aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js32
1 files changed, 27 insertions, 5 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index d53094e43..5373cf0d9 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -12,6 +12,7 @@ module.exports = class MetamaskController {
constructor (opts) {
this.opts = opts
+ this.listeners = []
this.configManager = new ConfigManager(opts)
this.idStore = new IdentityStore({
configManager: this.configManager,
@@ -112,9 +113,9 @@ module.exports = class MetamaskController {
}
sendUpdate () {
- if (this.remote) {
- this.remote.sendUpdate(this.getState())
- }
+ this.listeners.forEach((remote) => {
+ remote.sendUpdate(this.getState())
+ })
}
initializeProvider (opts) {
@@ -130,10 +131,17 @@ module.exports = class MetamaskController {
},
// tx signing
approveTransaction: this.newUnsignedTransaction.bind(this),
- signTransaction: idStore.signTransaction.bind(idStore),
+ signTransaction: (...args) => {
+ idStore.signTransaction(...args)
+ this.sendUpdate()
+ },
+
// msg signing
approveMessage: this.newUnsignedMessage.bind(this),
- signMessage: idStore.signMessage.bind(idStore),
+ signMessage: (...args) => {
+ idStore.signMessage(...args)
+ this.sendUpdate()
+ },
}
var provider = MetaMaskProvider(providerOpts)
@@ -191,8 +199,13 @@ module.exports = class MetamaskController {
const idStore = this.idStore
var state = idStore.getState()
+ let err = this.enforceTxValidations(txParams)
+ if (err) return onTxDoneCb(err)
+
// It's locked
if (!state.isUnlocked) {
+
+ // Allow the environment to define an unlock message.
this.opts.unlockAccountMessage()
idStore.addUnconfirmedTransaction(txParams, onTxDoneCb, noop)
@@ -200,11 +213,19 @@ module.exports = class MetamaskController {
} else {
idStore.addUnconfirmedTransaction(txParams, onTxDoneCb, (err, txData) => {
if (err) return onTxDoneCb(err)
+ this.sendUpdate()
this.opts.showUnconfirmedTx(txParams, txData, onTxDoneCb)
})
}
}
+ enforceTxValidations (txParams) {
+ if (('value' in txParams) && txParams.value.indexOf('-') === 0) {
+ const msg = `Invalid transaction value of ${txParams.value} not a positive number.`
+ return new Error(msg)
+ }
+ }
+
newUnsignedMessage (msgParams, cb) {
var state = this.idStore.getState()
if (!state.isUnlocked) {
@@ -212,6 +233,7 @@ module.exports = class MetamaskController {
this.opts.unlockAccountMessage()
} else {
this.addUnconfirmedMessage(msgParams, cb)
+ this.sendUpdate()
}
}