From 6921f94bfe11e618dbe586e608a5b6aeaa8feadf Mon Sep 17 00:00:00 2001 From: Csaba Solya Date: Thu, 19 Jul 2018 22:34:06 +0200 Subject: [PATCH 1/4] initial test --- app/manifest.json | 3 ++- .../lib/transaction-notification-manager.js | 27 +++++++++++++++++++ .../transactions/tx-state-manager.js | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 app/scripts/controllers/transactions/lib/transaction-notification-manager.js diff --git a/app/manifest.json b/app/manifest.json index b67cef025a4b..52256c5b72fa 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -63,7 +63,8 @@ "activeTab", "webRequest", "*://*.eth/", - "*://*.test/" + "*://*.test/", + "notifications" ], "web_accessible_resources": [ "inpage.js" diff --git a/app/scripts/controllers/transactions/lib/transaction-notification-manager.js b/app/scripts/controllers/transactions/lib/transaction-notification-manager.js new file mode 100644 index 000000000000..6bdf40b6201e --- /dev/null +++ b/app/scripts/controllers/transactions/lib/transaction-notification-manager.js @@ -0,0 +1,27 @@ +const extension = require('extensionizer') + +// Confirmed tx +// Transaction ${tx.nonce} confirmed! View on Etherscan + +// Failed tx +// Transaction ${tx.nonce} failed. (Maybe append tx.error.message) + +// Dropped tx +// A Transaction ${tx.nonce} was dropped, because another transaction with that number was successfully processed. + +function showConfirmedNotification (txMeta) { + extension.notifications.create({ + "type": "basic", + "title": "Confirmed transaction", + "iconUrl": extension.extension.getURL('../../../../images/icon-64.png'), + "message": JSON.stringify(txMeta) + }); +} + + +/** +@module +*/ +module.exports = { + showConfirmedNotification +} \ No newline at end of file diff --git a/app/scripts/controllers/transactions/tx-state-manager.js b/app/scripts/controllers/transactions/tx-state-manager.js index 28a18ca2e53a..72da45913344 100644 --- a/app/scripts/controllers/transactions/tx-state-manager.js +++ b/app/scripts/controllers/transactions/tx-state-manager.js @@ -5,6 +5,7 @@ const ethUtil = require('ethereumjs-util') const log = require('loglevel') const txStateHistoryHelper = require('./lib/tx-state-history-helper') const createId = require('../../lib/random-id') +const transactionNotificationManager = require('./lib/transaction-notification-manager') const { getFinalStates } = require('./lib/util') /** TransactionStateManager is responsible for the state of a transaction and @@ -332,6 +333,8 @@ class TransactionStateManager extends EventEmitter { */ setTxStatusConfirmed (txId) { this._setTxStatus(txId, 'confirmed') + const txMeta = this.getTx(txId) + transactionNotificationManager.showConfirmedNotification(txMeta) } /** From a3822b4680a295848f900616e3e154a1e1003a54 Mon Sep 17 00:00:00 2001 From: Csaba Solya Date: Fri, 20 Jul 2018 13:20:40 +0200 Subject: [PATCH 2/4] add notifications --- .../lib/transaction-notification-manager.js | 27 -------- .../transactions/tx-state-manager.js | 3 - app/scripts/metamask-controller.js | 7 ++ app/scripts/platforms/extension.js | 64 +++++++++++++++++++ 4 files changed, 71 insertions(+), 30 deletions(-) delete mode 100644 app/scripts/controllers/transactions/lib/transaction-notification-manager.js diff --git a/app/scripts/controllers/transactions/lib/transaction-notification-manager.js b/app/scripts/controllers/transactions/lib/transaction-notification-manager.js deleted file mode 100644 index 6bdf40b6201e..000000000000 --- a/app/scripts/controllers/transactions/lib/transaction-notification-manager.js +++ /dev/null @@ -1,27 +0,0 @@ -const extension = require('extensionizer') - -// Confirmed tx -// Transaction ${tx.nonce} confirmed! View on Etherscan - -// Failed tx -// Transaction ${tx.nonce} failed. (Maybe append tx.error.message) - -// Dropped tx -// A Transaction ${tx.nonce} was dropped, because another transaction with that number was successfully processed. - -function showConfirmedNotification (txMeta) { - extension.notifications.create({ - "type": "basic", - "title": "Confirmed transaction", - "iconUrl": extension.extension.getURL('../../../../images/icon-64.png'), - "message": JSON.stringify(txMeta) - }); -} - - -/** -@module -*/ -module.exports = { - showConfirmedNotification -} \ No newline at end of file diff --git a/app/scripts/controllers/transactions/tx-state-manager.js b/app/scripts/controllers/transactions/tx-state-manager.js index 72da45913344..28a18ca2e53a 100644 --- a/app/scripts/controllers/transactions/tx-state-manager.js +++ b/app/scripts/controllers/transactions/tx-state-manager.js @@ -5,7 +5,6 @@ const ethUtil = require('ethereumjs-util') const log = require('loglevel') const txStateHistoryHelper = require('./lib/tx-state-history-helper') const createId = require('../../lib/random-id') -const transactionNotificationManager = require('./lib/transaction-notification-manager') const { getFinalStates } = require('./lib/util') /** TransactionStateManager is responsible for the state of a transaction and @@ -333,8 +332,6 @@ class TransactionStateManager extends EventEmitter { */ setTxStatusConfirmed (txId) { this._setTxStatus(txId, 'confirmed') - const txMeta = this.getTx(txId) - transactionNotificationManager.showConfirmedNotification(txMeta) } /** diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 450113acfee7..31156b5b6277 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -164,6 +164,13 @@ module.exports = class MetamaskController extends EventEmitter { }) this.txController.on('newUnapprovedTx', opts.showUnapprovedTx.bind(opts)) + this.txController.on(`tx:status-update`, (txId, status) => { + if (status === 'confirmed' || status === 'failed' || status === 'dropped') { + const txMeta = this.txController.txStateManager.getTx(txId) + this.platform.showTransactionNotification(txMeta) + } + }) + // computed balances (accounting for pending transactions) this.balancesController = new BalancesController({ accountTracker: this.accountTracker, diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js index f5cc255d1cda..afcc9bbca32a 100644 --- a/app/scripts/platforms/extension.js +++ b/app/scripts/platforms/extension.js @@ -1,4 +1,5 @@ const extension = require('extensionizer') +const explorerLink = require('etherscan-link').createExplorerLink class ExtensionPlatform { @@ -31,6 +32,69 @@ class ExtensionPlatform { cb(e) } } + + showTransactionNotification (txMeta) { + + const status = txMeta.status + if (status === 'confirmed') { + this._showConfirmedTransaction(txMeta) + } else if (status === 'failed') { + this._showFailedTransaction(txMeta) + } else if (status === 'dropped') { + this._showDroppedTransaction(txMeta) + } + } + + _showConfirmedTransaction (txMeta) { + + this._subscribeToNotificationClicked() + + const url = explorerLink(txMeta.hash, parseInt(txMeta.metamaskNetworkId)) + const nonce = parseInt(txMeta.txParams.nonce, 16) + + const title = 'Confirmed transaction' + const message = `Transaction ${nonce} confirmed! View on EtherScan` + this._showNotification(title, message, url) + } + + _showFailedTransaction (txMeta) { + + const nonce = parseInt(txMeta.txParams.nonce, 16) + const title = 'Failed transaction' + const message = `Transaction ${nonce} failed! ${txMeta.err.message}` + this._showNotification(title, message) + } + + _showDroppedTransaction (txMeta) { + + const nonce = parseInt(txMeta.txParams.nonce, 16) + const title = 'Dropped transaction' + const message = `Transaction ${nonce} was dropped, because another transaction with that number was successfully processed.` + this._showNotification(title, message) + } + + _showNotification (title, message, url) { + extension.notifications.create( + url, + { + 'type': 'basic', + 'title': title, + 'iconUrl': extension.extension.getURL('../../images/icon-64.png'), + 'message': message, + }) + } + + _subscribeToNotificationClicked () { + if (!extension.notifications.onClicked.hasListener(this._viewOnEtherScan)) { + extension.notifications.onClicked.addListener(this._viewOnEtherScan) + } + } + + _viewOnEtherScan (txId) { + if (txId.startsWith('http://')) { + global.metamaskController.platform.openWindow({ url: txId }) + } + } } module.exports = ExtensionPlatform From 72591d4f41aafa7556cbc37d613fcbe016444156 Mon Sep 17 00:00:00 2001 From: Csaba Solya Date: Fri, 20 Jul 2018 19:58:26 +0200 Subject: [PATCH 3/4] remove dropped handler --- app/scripts/metamask-controller.js | 2 +- app/scripts/platforms/extension.js | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 31156b5b6277..939a30d748ed 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -165,7 +165,7 @@ module.exports = class MetamaskController extends EventEmitter { this.txController.on('newUnapprovedTx', opts.showUnapprovedTx.bind(opts)) this.txController.on(`tx:status-update`, (txId, status) => { - if (status === 'confirmed' || status === 'failed' || status === 'dropped') { + if (status === 'confirmed' || status === 'failed') { const txMeta = this.txController.txStateManager.getTx(txId) this.platform.showTransactionNotification(txMeta) } diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js index afcc9bbca32a..60ecfeff4acc 100644 --- a/app/scripts/platforms/extension.js +++ b/app/scripts/platforms/extension.js @@ -40,8 +40,6 @@ class ExtensionPlatform { this._showConfirmedTransaction(txMeta) } else if (status === 'failed') { this._showFailedTransaction(txMeta) - } else if (status === 'dropped') { - this._showDroppedTransaction(txMeta) } } @@ -65,14 +63,6 @@ class ExtensionPlatform { this._showNotification(title, message) } - _showDroppedTransaction (txMeta) { - - const nonce = parseInt(txMeta.txParams.nonce, 16) - const title = 'Dropped transaction' - const message = `Transaction ${nonce} was dropped, because another transaction with that number was successfully processed.` - this._showNotification(title, message) - } - _showNotification (title, message, url) { extension.notifications.create( url, From 682d59cfe0114dc987fe5e953e9db4dca5e2b5d7 Mon Sep 17 00:00:00 2001 From: Csaba Solya Date: Fri, 20 Jul 2018 19:58:51 +0200 Subject: [PATCH 4/4] adding changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ad52b79547d..862a0167505b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Current Master - Remove rejected transactions from transaction history + - [#4840](https://github.com/MetaMask/metamask-extension/pull/4840): Now shows notifications when transactions are completed. ## 4.8.0 Thur Jun 14 2018