Fix: global transaction event issue
MODIFY
src/common/Web3Client.ts
src/common/Web3Client.ts
@@ -50,12 +50,6 @@ export default class Web3Client {
!_options.chainId ? web3.eth.net.getId() : _options.chainId,
])
- this.events = {
- onTransactionHash: _options.onTransactionHash || null,
- onReceipt: _options.onReceipt || null,
- onError: _options.onError || null,
- }
-
return {
from,
gas: gasLimit,
@@ -67,15 +61,18 @@ export default class Web3Client {
to: _options.to || null,
data: _options.data,
encodeAbi: _options.encodeAbi || false,
+ onTransactionHash: _options.onTransactionHash || null,
+ onReceipt: _options.onReceipt || null,
+ onError: _options.onError || null,
}
}
- wrapWeb3Promise(promise) {
+ wrapWeb3Promise(promise, options) {
const _emptyFunc = () => {}
return promise
- .on('transactionHash', this.events.onTransactionHash || _emptyFunc)
- .on('receipt', this.events.onReceipt || _emptyFunc)
- .on('error', this.events.onError || _emptyFunc)
+ .on('transactionHash', options.onTransactionHash || _emptyFunc)
+ .on('receipt', options.onReceipt || _emptyFunc)
+ .on('error', options.onError || _emptyFunc)
}
async send(txObject, options?) {
@@ -93,7 +90,7 @@ export default class Web3Client {
_options.gasPrice = _options.gasPrice || this.maticDefaultOptions.gasPrice
}
logger.debug('sending tx with', { _options })
- return this.wrapWeb3Promise(txObject.send(_options))
+ return this.wrapWeb3Promise(txObject.send(_options), _options)
}
getParentWeb3() {

MODIFY
src/index.ts
src/index.ts
import BN from 'bn.js'
-
+import SDKClient from './common/SDKClient'
+import { Utils } from './common/Utils'
import DepositManager from './root/DepositManager'
-import RootChain from './root/RootChain'
+import POSRootChainManager from './root/POSRootChainManager'
import Registry from './root/Registry'
+import RootChain from './root/RootChain'
import WithdrawManager from './root/WithdrawManager'
-import POSRootChainManager from './root/POSRootChainManager'
-import { address, SendOptions, order, MaticClientInitializationOptions } from './types/Common'
-import SDKClient from './common/SDKClient'
-import { Utils } from './common/Utils'
+import { address, MaticClientInitializationOptions, order, SendOptions } from './types/Common'
export class MaticPOSClient extends SDKClient {
private rootChain: RootChain
@@ -284,7 +283,9 @@ export default class Matic extends SDKClient {
}
Object.assign(options, { value, to })
const _options = await this.web3Client.fillOptions(options /* txObject */, true /* onRootChain */, options)
- return _options.encodeAbi ? _options : this.web3Client.wrapWeb3Promise(web3Object.eth.sendTransaction(_options))
+ return _options.encodeAbi
+ ? _options
+ : this.web3Client.wrapWeb3Promise(web3Object.eth.sendTransaction(_options), options)
}
depositEther(amount: BN | string, options?: SendOptions) {

Fix: global transaction event issue