aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2017-01-06 04:51:12 +0800
committerGitHub <noreply@github.com>2017-01-06 04:51:12 +0800
commit4e62ae98bd7c62ef0618c4c5e88569b86d1bffec (patch)
treee1cdd6bf33af4da4d3a21de0018d51b33976c43c /app/scripts/metamask-controller.js
parentaf61bb90653b873cba6678db43dc4997cb47b505 (diff)
parent906c3882bb426985b403e744727f3a2071eabce7 (diff)
downloadtangerine-wallet-browser-4e62ae98bd7c62ef0618c4c5e88569b86d1bffec.tar.gz
tangerine-wallet-browser-4e62ae98bd7c62ef0618c4c5e88569b86d1bffec.tar.zst
tangerine-wallet-browser-4e62ae98bd7c62ef0618c4c5e88569b86d1bffec.zip
Merge branch 'dev' into network-indicator-refactor
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js43
1 files changed, 24 insertions, 19 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index c0d2f3b4c..555460f3d 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -1,5 +1,6 @@
+const EventEmitter = require('events')
const extend = require('xtend')
-const EthStore = require('eth-store')
+const EthStore = require('./lib/eth-store')
const MetaMaskProvider = require('web3-provider-engine/zero.js')
const KeyringController = require('./keyring-controller')
const NoticeController = require('./notice-controller')
@@ -13,12 +14,12 @@ const autoFaucet = require('./lib/auto-faucet')
const nodeify = require('./lib/nodeify')
const IdStoreMigrator = require('./lib/idStore-migrator')
-module.exports = class MetamaskController {
+module.exports = class MetamaskController extends EventEmitter {
constructor (opts) {
+ super()
this.state = { network: 'loading' }
this.opts = opts
- this.listeners = []
this.configManager = new ConfigManager(opts)
this.keyringController = new KeyringController({
configManager: this.configManager,
@@ -62,6 +63,7 @@ module.exports = class MetamaskController {
})
this.ethStore.on('update', this.sendUpdate.bind(this))
+ this.keyringController.on('update', this.sendUpdate.bind(this))
}
getState () {
@@ -165,10 +167,7 @@ module.exports = class MetamaskController {
sendUpdate () {
this.getState()
.then((state) => {
-
- this.listeners.forEach((remote) => {
- remote.sendUpdate(state)
- })
+ this.emit('update', state)
})
}
@@ -185,10 +184,23 @@ module.exports = class MetamaskController {
},
// tx signing
approveTransaction: this.newUnsignedTransaction.bind(this),
- signTransaction: (...args) => {
- this.setupSigningListners(...args)
- this.txManager.formatTxForSigining(...args)
- this.sendUpdate()
+ signTransaction: (txParams, cb) => {
+ this.txManager.formatTxForSigining(txParams)
+ .then(({ethTx, address, txId}) => {
+ return this.keyringController.signTransaction(ethTx, address, txId)
+ })
+ .then(({tx, txId}) => {
+ return this.txManager.resolveSignedTransaction({tx, txId})
+ })
+ .then((rawTx) => {
+ cb(null, rawTx)
+ this.sendUpdate()
+ this.txManager.emit(`${txParams.metamaskId}:signingComplete`)
+ })
+ .catch((err) => {
+ console.error(err)
+ cb(err)
+ })
},
// msg signing
@@ -266,13 +278,6 @@ module.exports = class MetamaskController {
})
}
- 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.`
@@ -453,7 +458,7 @@ module.exports = class MetamaskController {
return this.state.network
}
- markAccountsFound(cb) {
+ markAccountsFound (cb) {
this.configManager.setLostAccounts([])
this.sendUpdate()
cb(null, this.getState())