diff options
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/contentscript.js | 10 | ||||
-rw-r--r-- | app/scripts/controllers/provider-approval.js | 10 | ||||
-rw-r--r-- | app/scripts/inpage.js | 11 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 1 |
4 files changed, 29 insertions, 3 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 29fa3f5c7..bb79e1d4a 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -131,10 +131,15 @@ function listenForProviderRequest () { origin: source.location.hostname, }) break + case 'METAMASK_UNLOCK_STATUS': + extension.runtime.sendMessage({ + action: 'init-unlock-request', + }) + break } }) - extension.runtime.onMessage.addListener(({ action, isEnabled }) => { + extension.runtime.onMessage.addListener(({ action, isEnabled, isUnlocked }) => { if (!action) { return } switch (action) { case 'approve-provider-request': @@ -147,6 +152,9 @@ function listenForProviderRequest () { case 'answer-status-request': injectScript(`window.dispatchEvent(new CustomEvent('ethereumproviderstatus', { detail: { isEnabled: ${isEnabled}}}))`) break + case 'answer-unlock-request': + injectScript(`window.dispatchEvent(new CustomEvent('metamaskunlockstatus', { detail: { isUnlocked: ${isUnlocked}}}))`) + break } }) } diff --git a/app/scripts/controllers/provider-approval.js b/app/scripts/controllers/provider-approval.js index a44d2b3ab..c9680cb46 100644 --- a/app/scripts/controllers/provider-approval.js +++ b/app/scripts/controllers/provider-approval.js @@ -9,7 +9,7 @@ class ProviderApprovalController { * * @param {Object} [config] - Options to configure controller */ - constructor ({ closePopup, openPopup, platform, preferencesController, publicConfigStore } = {}) { + constructor ({ closePopup, openPopup, keyringController, platform, preferencesController, publicConfigStore } = {}) { this.store = new ObservableStore() this.closePopup = closePopup this.openPopup = openPopup @@ -17,6 +17,7 @@ class ProviderApprovalController { this.publicConfigStore = publicConfigStore this.approvedOrigins = {} this.preferencesController = preferencesController + this.keyringController = keyringController platform && platform.addMessageListener && platform.addMessageListener(({ action, origin }) => { if (!action) { return } switch (action) { @@ -26,6 +27,8 @@ class ProviderApprovalController { case 'init-status-request': this.handleProviderStatusRequest(origin) break + case 'init-unlock-request': + this.handleUnlockRequest() case 'init-privacy-request': this.handlePrivacyStatusRequest() } @@ -56,6 +59,11 @@ class ProviderApprovalController { this.platform && this.platform.sendMessage({ action: 'answer-status-request', isEnabled }, { active: true }) } + handleUnlockRequest() { + const isUnlocked = this.keyringController.memStore.getState().isUnlocked + this.platform && this.platform.sendMessage({ action: 'answer-unlock-request', isUnlocked }, { active: true }) + } + handlePrivacyStatusRequest () { const privacyMode = this.preferencesController.getFeatureFlags().privacyMode if (!privacyMode) { diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 88831c0cc..72f7033f9 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -71,7 +71,16 @@ inpageProvider.isApproved = function () { } inpageProvider.isUnlocked = function () { - + return new Promise((resolve, reject) => { + window.addEventListener('metamaskunlockstatus', ({ detail }) => { + if (typeof detail.error !== 'undefined') { + reject(detail.error) + } else { + resolve(!!detail.isUnlocked) + } + }) + window.postMessage({ type: 'METAMASK_UNLOCK_STATUS' }, '*') + }) } // Work around for web3@1.0 deleting the bound `sendAsync` but not the unbound diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 2265838fb..8930a3f2d 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -226,6 +226,7 @@ module.exports = class MetamaskController extends EventEmitter { platform: opts.platform, preferencesController: this.preferencesController, publicConfigStore: this.publicConfigStore, + keyringController: this.keyringController, }) this.store.updateStructure({ |