aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/platforms/extension.js
diff options
context:
space:
mode:
authorAkihiro <an0326ja@gmail.com>2018-07-21 09:47:14 +0800
committerAkihiro <an0326ja@gmail.com>2018-07-21 09:47:14 +0800
commit8c77e998e0491dfb48c91d2938644c9f855a2532 (patch)
treef3e54e635c92d54111ac2ddfc3e780ccdcdaf968 /app/scripts/platforms/extension.js
parent9dd637569d5c820d07ff15a8039f5ce5590f41dd (diff)
parente094d4ad1fb84a9bc663c328d0650bd9d8bf8716 (diff)
downloadtangerine-wallet-browser-8c77e998e0491dfb48c91d2938644c9f855a2532.tar.gz
tangerine-wallet-browser-8c77e998e0491dfb48c91d2938644c9f855a2532.tar.zst
tangerine-wallet-browser-8c77e998e0491dfb48c91d2938644c9f855a2532.zip
Merge remote-tracking branch 'upstream/develop' into develop
Diffstat (limited to 'app/scripts/platforms/extension.js')
-rw-r--r--app/scripts/platforms/extension.js61
1 files changed, 59 insertions, 2 deletions
diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js
index f5cc255d1..901c26cab 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 {
@@ -17,8 +18,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 })
}
@@ -31,6 +35,59 @@ class ExtensionPlatform {
cb(e)
}
}
+
+ 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