aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorbitpshr <mail@bitpshr.net>2018-10-18 06:38:31 +0800
committerDan Finlay <542863+danfinlay@users.noreply.github.com>2018-11-06 07:07:09 +0800
commit84874a639d217da36926869fa3cb235c05725cf5 (patch)
tree63f44fd5e63bd5e483e18ab46fc312298e431915 /app
parent573139b9357ccd97eb6b866721fafc93ceb080b6 (diff)
downloadtangerine-wallet-browser-84874a639d217da36926869fa3cb235c05725cf5.tar
tangerine-wallet-browser-84874a639d217da36926869fa3cb235c05725cf5.tar.gz
tangerine-wallet-browser-84874a639d217da36926869fa3cb235c05725cf5.tar.bz2
tangerine-wallet-browser-84874a639d217da36926869fa3cb235c05725cf5.tar.lz
tangerine-wallet-browser-84874a639d217da36926869fa3cb235c05725cf5.tar.xz
tangerine-wallet-browser-84874a639d217da36926869fa3cb235c05725cf5.tar.zst
tangerine-wallet-browser-84874a639d217da36926869fa3cb235c05725cf5.zip
Add isUnlocked provider hook
Diffstat (limited to 'app')
-rw-r--r--app/scripts/contentscript.js10
-rw-r--r--app/scripts/controllers/provider-approval.js10
-rw-r--r--app/scripts/inpage.js11
-rw-r--r--app/scripts/metamask-controller.js1
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({