fix promise fail
MODIFY
src/index.js
src/index.js
@@ -118,7 +118,9 @@ export default class Matic {
if (options.parent) {
web3Object = this._parentWeb3
}
- const balance = await this._getERC721TokenContract(token,web3Object).methods.balanceOf(address).call()
+ const balance = await this._getERC721TokenContract(token, web3Object)
+ .methods.balanceOf(address)
+ .call()
return balance
}
@@ -250,12 +252,7 @@ export default class Matic {
// if matic chain, transfer normal WETH tokens
if (!options.parent) {
- return this.transferTokens(
- this._maticWethAddress,
- to,
- amount,
- options
- )
+ return this.transferTokens(this._maticWethAddress, to, amount, options)
}
const gasLimit = await this._parentWeb3.eth.estimateGas({
@@ -425,14 +422,15 @@ export default class Matic {
}
async processExits(rootTokenAddress, options = {}) {
- const processExits = this._withdrawManagerContract.methods.processExits(rootTokenAddress)
+ const processExits = this._withdrawManagerContract.methods.processExits(
+ rootTokenAddress
+ )
const _options = await this._fillOptions(
options,
processExits,
this._parentWeb3
)
return this._wrapWeb3Promise(processExits.send(_options), options)
-
}
async withdrawLocally(txId, options = {}) {
@@ -544,14 +542,18 @@ export default class Matic {
const [gasLimit, gasPrice, nonce, chainId] = await Promise.all([
!(options.gasLimit || options.gas)
- ? await txObject.estimateGas({ from, value: options.value })
+ ? txObject.estimateGas({ from, value: options.value })
: options.gasLimit || options.gas,
// NOTE: Gas Price is set to '0', take care of type of gasPrice on web3^1.0.0-beta.36
- !options.gasPrice ? !web3.matic ? await web3.eth.getGasPrice() : '0' : options.gasPrice,
+ !options.gasPrice
+ ? !web3.matic
+ ? web3.eth.getGasPrice()
+ : '0'
+ : options.gasPrice,
!options.nonce
- ? await web3.eth.getTransactionCount(from, 'pending')
+ ? web3.eth.getTransactionCount(from, 'pending')
: options.nonce,
- !options.chainId ? await web3.eth.net.getId() : options.chainId,
+ !options.chainId ? web3.eth.net.getId() : options.chainId,
])
return {
@@ -567,10 +569,11 @@ export default class Matic {
}
_wrapWeb3Promise(promise, options) {
+ const _emptyFunc = () => {}
return promise
- .on('transactionHash', options.onTransactionHash)
- .on('receipt', options.onReceipt)
- .on('error', options.onError)
+ .on('transactionHash', options.onTransactionHash || _emptyFunc)
+ .on('receipt', options.onReceipt || _emptyFunc)
+ .on('error', options.onError || _emptyFunc)
}
_apiCall(data = {}) {

fix promise fail