diff options
author | Dan Finlay <flyswatter@users.noreply.github.com> | 2017-01-03 06:04:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-03 06:04:27 +0800 |
commit | 25d0ac147668e45da43a4dd74876e3e22bd6a246 (patch) | |
tree | 6a81531e5398afc26685e7b0523c7526dabd0f7f /app/scripts/metamask-controller.js | |
parent | edc5f9e821bf18fa6ec984e645790fba3457d0bb (diff) | |
parent | fb002dc44eae82e0471b8b52acecc61ba5f39332 (diff) | |
download | tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar.gz tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar.bz2 tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar.lz tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar.xz tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar.zst tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.zip |
Merge branch 'dev' into ShowDifferentAccounts
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r-- | app/scripts/metamask-controller.js | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 8d4d574ff..3e27272b9 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -4,6 +4,7 @@ const MetaMaskProvider = require('web3-provider-engine/zero.js') const KeyringController = require('./keyring-controller') const NoticeController = require('./notice-controller') const messageManager = require('./lib/message-manager') +const TxManager = require('./transaction-manager') const HostStore = require('./lib/remote-store.js').HostStore const Web3 = require('web3') const ConfigManager = require('./lib/config-manager') @@ -12,7 +13,6 @@ const autoFaucet = require('./lib/auto-faucet') const nodeify = require('./lib/nodeify') const IdStoreMigrator = require('./lib/idStore-migrator') - module.exports = class MetamaskController { constructor (opts) { @@ -36,6 +36,16 @@ module.exports = class MetamaskController { this.keyringController.setStore(this.ethStore) this.getNetwork() this.messageManager = messageManager + this.txManager = new TxManager({ + txList: this.configManager.getTxList(), + txHistoryLimit: 40, + setTxList: this.configManager.setTxList.bind(this.configManager), + getSelectedAccount: this.configManager.getSelectedAccount.bind(this.configManager), + getGasMultiplier: this.configManager.getGasMultiplier.bind(this.configManager), + getNetwork: this.getStateNetwork.bind(this), + provider: this.provider, + blockTracker: this.provider, + }) this.publicConfigStore = this.initPublicConfigStore() var currentFiat = this.configManager.getCurrentFiat() || 'USD' @@ -59,6 +69,7 @@ module.exports = class MetamaskController { this.state, this.ethStore.getState(), this.configManager.getConfig(), + this.txManager.getState(), keyringControllerState, this.noticeController.getState(), { lostAccounts: this.configManager.getLostAccounts(), @@ -69,6 +80,7 @@ module.exports = class MetamaskController { getApi () { const keyringController = this.keyringController + const txManager = this.txManager const noticeController = this.noticeController return { @@ -103,8 +115,8 @@ module.exports = class MetamaskController { exportAccount: nodeify(keyringController.exportAccount).bind(keyringController), // signing methods - approveTransaction: keyringController.approveTransaction.bind(keyringController), - cancelTransaction: keyringController.cancelTransaction.bind(keyringController), + approveTransaction: txManager.approveTransaction.bind(txManager), + cancelTransaction: txManager.cancelTransaction.bind(txManager), signMessage: keyringController.signMessage.bind(keyringController), cancelMessage: keyringController.cancelMessage.bind(keyringController), @@ -168,7 +180,8 @@ module.exports = class MetamaskController { // tx signing approveTransaction: this.newUnsignedTransaction.bind(this), signTransaction: (...args) => { - keyringController.signTransaction(...args) + this.setupSigningListners(...args) + this.txManager.formatTxForSigining(...args) this.sendUpdate() }, @@ -184,7 +197,6 @@ module.exports = class MetamaskController { var web3 = new Web3(provider) this.web3 = web3 keyringController.web3 = web3 - provider.on('block', this.processBlock.bind(this)) provider.on('error', this.getNetwork.bind(this)) @@ -238,16 +250,23 @@ module.exports = class MetamaskController { } newUnsignedTransaction (txParams, onTxDoneCb) { - const keyringController = this.keyringController + const txManager = this.txManager const err = this.enforceTxValidations(txParams) if (err) return onTxDoneCb(err) - keyringController.addUnconfirmedTransaction(txParams, onTxDoneCb, (err, txData) => { + txManager.addUnapprovedTransaction(txParams, onTxDoneCb, (err, txData) => { if (err) return onTxDoneCb(err) this.sendUpdate() - this.opts.showUnconfirmedTx(txParams, txData, onTxDoneCb) + this.opts.showUnapprovedTx(txParams, txData, onTxDoneCb) }) } + setupSigningListners (txParams) { + var txId = txParams.metamaskId + // apply event listeners for signing and formating events + this.txManager.once(`${txId}:formatted`, this.keyringController.signTransaction.bind(this.keyringController)) + this.keyringController.once(`${txId}:signed`, this.txManager.resolveSignedTransaction.bind(this.txManager)) + } + enforceTxValidations (txParams) { if (('value' in txParams) && txParams.value.indexOf('-') === 0) { const msg = `Invalid transaction value of ${txParams.value} not a positive number.` |