diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/contentscript.js | 1 | ||||
-rw-r--r-- | app/scripts/controllers/provider-approval.js | 8 | ||||
-rw-r--r-- | app/scripts/inpage.js | 17 |
3 files changed, 20 insertions, 6 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 1cdc85945..2327dc4ac 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -125,6 +125,7 @@ function listenForProviderRequest () { case 'ETHEREUM_ENABLE_PROVIDER': extension.runtime.sendMessage({ action: 'init-provider-request', + force: data.force, origin: source.location.hostname, siteImage: getSiteIcon(source), siteTitle: getSiteName(source), diff --git a/app/scripts/controllers/provider-approval.js b/app/scripts/controllers/provider-approval.js index f2d40e67d..f17220cb9 100644 --- a/app/scripts/controllers/provider-approval.js +++ b/app/scripts/controllers/provider-approval.js @@ -25,10 +25,10 @@ class ProviderApprovalController { this.store = new ObservableStore() if (platform && platform.addMessageListener) { - platform.addMessageListener(({ action = '', origin, siteTitle, siteImage }) => { + platform.addMessageListener(({ action = '', force, origin, siteTitle, siteImage }) => { switch (action) { case 'init-provider-request': - this._handleProviderRequest(origin, siteTitle, siteImage) + this._handleProviderRequest(origin, siteTitle, siteImage, force) break case 'init-is-approved': this._handleIsApproved(origin) @@ -51,10 +51,10 @@ class ProviderApprovalController { * @param {string} siteTitle - The title of the document requesting full provider access * @param {string} siteImage - The icon of the window requesting full provider access */ - _handleProviderRequest (origin, siteTitle, siteImage) { + _handleProviderRequest (origin, siteTitle, siteImage, force) { this.store.updateState({ providerRequests: [{ origin, siteTitle, siteImage }] }) const isUnlocked = this.keyringController.memStore.getState().isUnlocked - if (this.isApproved(origin) && this.caching && isUnlocked) { + if (!force && this.isApproved(origin) && this.caching && isUnlocked) { this.approveProviderRequest(origin) return } diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 2ca3abde2..e1948a522 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -44,7 +44,7 @@ window.addEventListener('metamasksetlocked', () => { }) // augment the provider with its enable method -inpageProvider.enable = function () { +inpageProvider.enable = function ({ force } = {}) { return new Promise((resolve, reject) => { window.removeEventListener('ethereumprovider', providerHandle) providerHandle = ({ detail }) => { @@ -85,10 +85,23 @@ inpageProvider.enable = function () { } } window.addEventListener('ethereumprovider', providerHandle) - window.postMessage({ type: 'ETHEREUM_ENABLE_PROVIDER' }, '*') + window.postMessage({ type: 'ETHEREUM_ENABLE_PROVIDER', force }, '*') }) } +// detect eth_requestAccounts and pipe to enable for now +function detectAccountRequest(method) { + const originalMethod = inpageProvider[method] + inpageProvider[method] = function ({ method }) { + if (method === 'eth_requestAccounts') { + return ethereum.enable() + } + return originalMethod.apply(this, arguments) + } +} +detectAccountRequest('send') +detectAccountRequest('sendAsync') + // add metamask-specific convenience methods inpageProvider._metamask = new Proxy({ /** |