mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
Merge pull request #4840 from scsaba/transaction-notifications
Transaction notifications
This commit is contained in:
commit
e094d4ad1f
@ -6,6 +6,7 @@
|
|||||||
- Remove rejected transactions from transaction history
|
- Remove rejected transactions from transaction history
|
||||||
- Add Trezor Support
|
- Add Trezor Support
|
||||||
- Allow to remove accounts (Imported and Hardware Wallets)
|
- Allow to remove accounts (Imported and Hardware Wallets)
|
||||||
|
- [#4840](https://github.com/MetaMask/metamask-extension/pull/4840): Now shows notifications when transactions are completed.
|
||||||
|
|
||||||
## 4.8.0 Thur Jun 14 2018
|
## 4.8.0 Thur Jun 14 2018
|
||||||
|
|
||||||
|
@ -63,7 +63,8 @@
|
|||||||
"activeTab",
|
"activeTab",
|
||||||
"webRequest",
|
"webRequest",
|
||||||
"*://*.eth/",
|
"*://*.eth/",
|
||||||
"*://*.test/"
|
"*://*.test/",
|
||||||
|
"notifications"
|
||||||
],
|
],
|
||||||
"web_accessible_resources": [
|
"web_accessible_resources": [
|
||||||
"inpage.js"
|
"inpage.js"
|
||||||
|
@ -175,6 +175,13 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
this.txController.on('newUnapprovedTx', opts.showUnapprovedTx.bind(opts))
|
this.txController.on('newUnapprovedTx', opts.showUnapprovedTx.bind(opts))
|
||||||
|
|
||||||
|
this.txController.on(`tx:status-update`, (txId, status) => {
|
||||||
|
if (status === 'confirmed' || status === 'failed') {
|
||||||
|
const txMeta = this.txController.txStateManager.getTx(txId)
|
||||||
|
this.platform.showTransactionNotification(txMeta)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// computed balances (accounting for pending transactions)
|
// computed balances (accounting for pending transactions)
|
||||||
this.balancesController = new BalancesController({
|
this.balancesController = new BalancesController({
|
||||||
accountTracker: this.accountTracker,
|
accountTracker: this.accountTracker,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const extension = require('extensionizer')
|
const extension = require('extensionizer')
|
||||||
|
const explorerLink = require('etherscan-link').createExplorerLink
|
||||||
|
|
||||||
class ExtensionPlatform {
|
class ExtensionPlatform {
|
||||||
|
|
||||||
@ -34,6 +35,59 @@ class ExtensionPlatform {
|
|||||||
cb(e)
|
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
|
module.exports = ExtensionPlatform
|
||||||
|
Loading…
Reference in New Issue
Block a user