diff options
author | brunobar79 <brunobar79@gmail.com> | 2018-07-27 09:11:58 +0800 |
---|---|---|
committer | brunobar79 <brunobar79@gmail.com> | 2018-07-27 09:11:58 +0800 |
commit | d65d018ad0f78a0319f11942ada9ca0d85214db9 (patch) | |
tree | a17ab54537f5f7ab9c892c38e46192ddd13c2688 /app/scripts/platforms | |
parent | 69f4c8c336a0f2fad2027c4a5f76e28a976b5e75 (diff) | |
download | tangerine-wallet-browser-d65d018ad0f78a0319f11942ada9ca0d85214db9.tar tangerine-wallet-browser-d65d018ad0f78a0319f11942ada9ca0d85214db9.tar.gz tangerine-wallet-browser-d65d018ad0f78a0319f11942ada9ca0d85214db9.tar.bz2 tangerine-wallet-browser-d65d018ad0f78a0319f11942ada9ca0d85214db9.tar.lz tangerine-wallet-browser-d65d018ad0f78a0319f11942ada9ca0d85214db9.tar.xz tangerine-wallet-browser-d65d018ad0f78a0319f11942ada9ca0d85214db9.tar.zst tangerine-wallet-browser-d65d018ad0f78a0319f11942ada9ca0d85214db9.zip |
restore platform/extension.js
Diffstat (limited to 'app/scripts/platforms')
-rw-r--r-- | app/scripts/platforms/extension.js | 62 |
1 files changed, 57 insertions, 5 deletions
diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js index 844670537..db0548efc 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 { @@ -23,8 +24,11 @@ class ExtensionPlatform { return extension.runtime.getManifest().version } - openExtensionInBrowser () { - const extensionURL = extension.runtime.getURL('home.html') + openExtensionInBrowser (route = null) { + let extensionURL = extension.runtime.getURL('home.html') + if (route) { + extensionURL += `#${route}` + } this.openWindow({ url: extensionURL }) } @@ -38,10 +42,58 @@ class ExtensionPlatform { } } - addMessageListener (cb) { - extension.runtime.onMessage.addListener(cb) + showTransactionNotification (txMeta) { + + const status = txMeta.status + if (status === 'confirmed') { + this._showConfirmedTransaction(txMeta) + } else if (status === 'failed') { + this._showFailedTransaction(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) + } + + _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 +module.exports = ExtensionPlatform
\ No newline at end of file |