validation on required parameters
MODIFY
src/index.js
src/index.js
@@ -96,6 +96,9 @@ export default class Matic {
}
async approveTokensForDeposit(token, amount, options = {}) {
+ if (!options.from || !amount || !token) {
+ throw new Error('Missing Parameters')
+ }
const _tokenContract = new this._parentWeb3.eth.Contract(
StandardTokenArtifacts.abi,
token
@@ -114,6 +117,9 @@ export default class Matic {
}
async depositEthers(user, options = {}) {
+ if (!options.from || !user || !options.value) {
+ throw new Error('Missing Parameters')
+ }
const depositTx = this._rootChainContract.methods.depositEthers(user)
const _options = await this._fillOptions(
options,
@@ -125,6 +131,9 @@ export default class Matic {
}
async depositTokens(token, user, amount, options = {}) {
+ if (!options.from || !user || !amount || token) {
+ throw new Error('Missing Parameters')
+ }
const depositTx = this._rootChainContract.methods.deposit(
token,
user,
@@ -140,6 +149,9 @@ export default class Matic {
}
async transferMaticEthers(to, amount, options) {
+ if (!options.from || !amount || !to) {
+ throw new Error('Missing Parameters')
+ }
const from = options.from
const gasLimit = await this._web3.eth.estimateGas({
@@ -158,6 +170,9 @@ export default class Matic {
}
async transferTokens(token, user, amount, options = {}) {
+ if (!options.from || !amount || !user || !token) {
+ throw new Error('Missing Parameters')
+ }
let web3Object = this._web3
if (options.parent) {
web3Object = this._parentWeb3
@@ -169,6 +184,9 @@ export default class Matic {
}
async transferEthers(to, amount, options = {}) {
+ if (!options.from || !amount || !to) {
+ throw new Error('Missing Parameters')
+ }
const from = options.from
// if matic chain, transfer normal WETH tokens
@@ -192,6 +210,9 @@ export default class Matic {
}
async startWithdraw(token, amount, options = {}) {
+ if (!options.from || !amount || !token) {
+ throw new Error('Missing Parameters')
+ }
const _tokenContract = this._getERC20TokenContract(token, this._web3)
const withdrawTx = _tokenContract.methods.withdraw(amount)
const _options = await this._fillOptions(options, withdrawTx, this._web3)

validation on required parameters