diff options
author | Csaba Solya <csaba.solya@gmail.com> | 2018-07-20 19:20:40 +0800 |
---|---|---|
committer | Csaba Solya <csaba.solya@gmail.com> | 2018-07-20 19:20:40 +0800 |
commit | a3822b4680a295848f900616e3e154a1e1003a54 (patch) | |
tree | 56f6b102b3247534c5c67ac6f35cb3c91b02b3ca /app/scripts/platforms | |
parent | 6921f94bfe11e618dbe586e608a5b6aeaa8feadf (diff) | |
download | tangerine-wallet-browser-a3822b4680a295848f900616e3e154a1e1003a54.tar tangerine-wallet-browser-a3822b4680a295848f900616e3e154a1e1003a54.tar.gz tangerine-wallet-browser-a3822b4680a295848f900616e3e154a1e1003a54.tar.bz2 tangerine-wallet-browser-a3822b4680a295848f900616e3e154a1e1003a54.tar.lz tangerine-wallet-browser-a3822b4680a295848f900616e3e154a1e1003a54.tar.xz tangerine-wallet-browser-a3822b4680a295848f900616e3e154a1e1003a54.tar.zst tangerine-wallet-browser-a3822b4680a295848f900616e3e154a1e1003a54.zip |
add notifications
Diffstat (limited to 'app/scripts/platforms')
-rw-r--r-- | app/scripts/platforms/extension.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js index f5cc255d1..afcc9bbca 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 |