|
|
@ -10,31 +10,22 @@ const MetamaskController = require('./metamask-controller') |
|
|
|
const extension = require('./lib/extension') |
|
|
|
const extension = require('./lib/extension') |
|
|
|
|
|
|
|
|
|
|
|
const STORAGE_KEY = 'metamask-config' |
|
|
|
const STORAGE_KEY = 'metamask-config' |
|
|
|
|
|
|
|
var popupIsOpen = false |
|
|
|
|
|
|
|
|
|
|
|
const controller = new MetamaskController({ |
|
|
|
const controller = new MetamaskController({ |
|
|
|
// User confirmation callbacks:
|
|
|
|
// User confirmation callbacks:
|
|
|
|
showUnconfirmedMessage, |
|
|
|
showUnconfirmedMessage: triggerUi, |
|
|
|
unlockAccountMessage, |
|
|
|
unlockAccountMessage: triggerUi, |
|
|
|
showUnconfirmedTx, |
|
|
|
showUnconfirmedTx: triggerUi, |
|
|
|
// Persistence Methods:
|
|
|
|
// Persistence Methods:
|
|
|
|
setData, |
|
|
|
setData, |
|
|
|
loadData, |
|
|
|
loadData, |
|
|
|
}) |
|
|
|
}) |
|
|
|
const idStore = controller.idStore |
|
|
|
const idStore = controller.idStore |
|
|
|
|
|
|
|
|
|
|
|
function unlockAccountMessage () { |
|
|
|
function triggerUi () { |
|
|
|
notification.show() |
|
|
|
if (!popupIsOpen) notification.show() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function showUnconfirmedMessage (msgParams, msgId) { |
|
|
|
|
|
|
|
notification.show() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function showUnconfirmedTx (txParams, txData, onTxDoneCb) { |
|
|
|
|
|
|
|
notification.show() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// On first install, open a window to MetaMask website to how-it-works.
|
|
|
|
// On first install, open a window to MetaMask website to how-it-works.
|
|
|
|
|
|
|
|
|
|
|
|
extension.runtime.onInstalled.addListener(function (details) { |
|
|
|
extension.runtime.onInstalled.addListener(function (details) { |
|
|
@ -53,7 +44,8 @@ function connectRemote (remotePort) { |
|
|
|
var portStream = new PortStream(remotePort) |
|
|
|
var portStream = new PortStream(remotePort) |
|
|
|
if (isMetaMaskInternalProcess) { |
|
|
|
if (isMetaMaskInternalProcess) { |
|
|
|
// communication with popup
|
|
|
|
// communication with popup
|
|
|
|
setupTrustedCommunication(portStream, 'MetaMask') |
|
|
|
popupIsOpen = remotePort.name === 'popup' |
|
|
|
|
|
|
|
setupTrustedCommunication(portStream, 'MetaMask', remotePort.name) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// communication with page
|
|
|
|
// communication with page
|
|
|
|
var originDomain = urlUtil.parse(remotePort.sender.url).hostname |
|
|
|
var originDomain = urlUtil.parse(remotePort.sender.url).hostname |
|
|
@ -95,6 +87,7 @@ function setupControllerConnection (stream) { |
|
|
|
// teardown on disconnect
|
|
|
|
// teardown on disconnect
|
|
|
|
eos(stream, () => { |
|
|
|
eos(stream, () => { |
|
|
|
controller.ethStore.removeListener('update', controller.sendUpdate.bind(controller)) |
|
|
|
controller.ethStore.removeListener('update', controller.sendUpdate.bind(controller)) |
|
|
|
|
|
|
|
popupIsOpen = false |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|