From 891e17c44c9a8ff8b2c794f534018f727dd25d5d Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 2 Sep 2016 13:29:47 -0700 Subject: notif - use standard err-first callback style --- app/scripts/lib/notifications.js | 42 +++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/lib/notifications.js b/app/scripts/lib/notifications.js index df4fe73dd..4e3f7558c 100644 --- a/app/scripts/lib/notifications.js +++ b/app/scripts/lib/notifications.js @@ -9,20 +9,26 @@ module.exports = notifications window.METAMASK_NOTIFIER = notifications function show () { - getWindows((windows) => { + getPopup((err, popup) => { + if (err) throw err - if (windows.length > 0) { - const win = windows[0] - return extension.windows.update(win.id, { focused: true }) - } + if (popup) { + + // bring focus to existing popup + extension.windows.update(popup.id, { focused: true }) + + } else { - extension.windows.create({ - url: 'notification.html', - type: 'popup', - focused: true, - width: 360, - height: 500, - }) + // create new popup + extension.windows.create({ + url: 'notification.html', + type: 'popup', + focused: true, + width: 360, + height: 500, + }) + + } }) } @@ -38,19 +44,19 @@ function getWindows(cb) { } function getPopup(cb) { - getWindows((windows) => { - cb(getPopupIn(windows)) + getWindows((err, windows) => { + if (err) throw err + cb(null, getPopupIn(windows)) }) } function getPopupIn(windows) { - return windows ? windows.find((win) => { - return win.type === 'popup' - }) : null + return windows ? windows.find((win) => win.type === 'popup') : null } function closePopup() { - getPopup((popup) => { + getPopup((err, popup) => { + if (err) throw err if (!popup) return extension.windows.remove(popup.id, console.error) }) -- cgit From 76d63ec4e0f02b7bb91aefb9eb6959198322f42b Mon Sep 17 00:00:00 2001 From: Vincent Serpoul Date: Tue, 6 Sep 2016 11:20:22 +0800 Subject: Error message more helpful --- app/scripts/lib/inpage-provider.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index 3b7d76c7d..e22e5e411 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -80,7 +80,8 @@ MetamaskInpageProvider.prototype.send = function (payload) { // throw not-supported Error default: - var message = 'The MetaMask Web3 object does not support synchronous methods. See https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#all-async---think-of-metamask-as-a-light-client for details.' + var message = 'The MetaMask Web3 object does not support synchronous methods like '+ payload.method + + '. See https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#all-async---think-of-metamask-as-a-light-client for details.' throw new Error(message) } @@ -131,4 +132,4 @@ function eachJsonMessage(payload, transformFn){ } else { return transformFn(payload) } -} \ No newline at end of file +} -- cgit From 4cf12337f2d3ad97a670ddbdc131435415f9626b Mon Sep 17 00:00:00 2001 From: Vincent Serpoul Date: Tue, 6 Sep 2016 11:24:09 +0800 Subject: linting --- app/scripts/lib/inpage-provider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts') diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index e22e5e411..4f9fa1a7d 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -80,7 +80,7 @@ MetamaskInpageProvider.prototype.send = function (payload) { // throw not-supported Error default: - var message = 'The MetaMask Web3 object does not support synchronous methods like '+ payload.method + + var message = 'The MetaMask Web3 object does not support synchronous methods like ' + payload.method + '. See https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#all-async---think-of-metamask-as-a-light-client for details.' throw new Error(message) -- cgit From dcc24804a1048e9379ce30233f4ecf540db5a54a Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 6 Sep 2016 15:23:48 -0700 Subject: Add negative value validation to tx approval --- app/scripts/metamask-controller.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app/scripts') diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index e94db2dfd..83827ec76 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -199,6 +199,9 @@ 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) { @@ -216,6 +219,13 @@ module.exports = class MetamaskController { } } + enforceTxValidations (txParams) { + if (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) { -- cgit