|
|
@ -1,5 +1,4 @@ |
|
|
|
const extension = require('extensionizer') |
|
|
|
const extension = require('extensionizer') |
|
|
|
const explorerLink = require('etherscan-link').createExplorerLink |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExtensionPlatform { |
|
|
|
class ExtensionPlatform { |
|
|
|
|
|
|
|
|
|
|
@ -18,11 +17,8 @@ class ExtensionPlatform { |
|
|
|
return extension.runtime.getManifest().version |
|
|
|
return extension.runtime.getManifest().version |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
openExtensionInBrowser (route = null) { |
|
|
|
openExtensionInBrowser () { |
|
|
|
let extensionURL = extension.runtime.getURL('home.html') |
|
|
|
const extensionURL = extension.runtime.getURL('home.html') |
|
|
|
if (route) { |
|
|
|
|
|
|
|
extensionURL += `#${route}` |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.openWindow({ url: extensionURL }) |
|
|
|
this.openWindow({ url: extensionURL }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -36,57 +32,16 @@ class ExtensionPlatform { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
showTransactionNotification (txMeta) { |
|
|
|
addMessageListener (cb) { |
|
|
|
|
|
|
|
extension.runtime.onMessage.addListener(cb) |
|
|
|
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 () { |
|
|
|
sendMessage (message, query = {}) { |
|
|
|
if (!extension.notifications.onClicked.hasListener(this._viewOnEtherScan)) { |
|
|
|
extension.tabs.query(query, tabs => { |
|
|
|
extension.notifications.onClicked.addListener(this._viewOnEtherScan) |
|
|
|
const activeTab = tabs.filter(tab => tab.active)[0] |
|
|
|
} |
|
|
|
extension.tabs.sendMessage(activeTab.id, message) |
|
|
|
} |
|
|
|
console.log('QR-SCANNER: message sent to tab', message, activeTab) |
|
|
|
|
|
|
|
}) |
|
|
|
_viewOnEtherScan (txId) { |
|
|
|
|
|
|
|
if (txId.startsWith('http://')) { |
|
|
|
|
|
|
|
global.metamaskController.platform.openWindow({ url: txId }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|