mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
Differentiate locked and enabled
This commit is contained in:
parent
d7618bd5c6
commit
cc1bab6ebb
@ -157,10 +157,6 @@ function listenForProviderRequest () {
|
|||||||
case 'answer-is-unlocked':
|
case 'answer-is-unlocked':
|
||||||
injectScript(`window.dispatchEvent(new CustomEvent('metamaskisunlocked', { detail: { isUnlocked: ${isUnlocked}}}))`)
|
injectScript(`window.dispatchEvent(new CustomEvent('metamaskisunlocked', { detail: { isUnlocked: ${isUnlocked}}}))`)
|
||||||
break
|
break
|
||||||
case 'metamask-set-locked':
|
|
||||||
isEnabled = false
|
|
||||||
injectScript(`window.dispatchEvent(new CustomEvent('metamasksetlocked', { detail: {}}))`)
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,7 @@ class ProviderApprovalController {
|
|||||||
*/
|
*/
|
||||||
_handleProviderRequest (origin) {
|
_handleProviderRequest (origin) {
|
||||||
this.store.updateState({ providerRequests: [{ origin }] })
|
this.store.updateState({ providerRequests: [{ origin }] })
|
||||||
const isUnlocked = this.keyringController.memStore.getState().isUnlocked
|
if (this.isApproved(origin)) {
|
||||||
if (isUnlocked && this.isApproved(origin)) {
|
|
||||||
this.approveProviderRequest(origin)
|
this.approveProviderRequest(origin)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -126,14 +125,6 @@ class ProviderApprovalController {
|
|||||||
const privacyMode = this.preferencesController.getFeatureFlags().privacyMode
|
const privacyMode = this.preferencesController.getFeatureFlags().privacyMode
|
||||||
return !privacyMode || this.approvedOrigins[origin]
|
return !privacyMode || this.approvedOrigins[origin]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells all tabs that MetaMask is now locked. This is primarily used to set
|
|
||||||
* internal flags in the contentscript and inpage script.
|
|
||||||
*/
|
|
||||||
setLocked () {
|
|
||||||
this.platform.sendMessage({ action: 'metamask-set-locked' })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ProviderApprovalController
|
module.exports = ProviderApprovalController
|
||||||
|
@ -35,11 +35,6 @@ var inpageProvider = new MetamaskInpageProvider(metamaskStream)
|
|||||||
// set a high max listener count to avoid unnecesary warnings
|
// set a high max listener count to avoid unnecesary warnings
|
||||||
inpageProvider.setMaxListeners(100)
|
inpageProvider.setMaxListeners(100)
|
||||||
|
|
||||||
// set up a listener for when MetaMask is locked
|
|
||||||
window.addEventListener('metamasksetlocked', () => {
|
|
||||||
isEnabled = false
|
|
||||||
})
|
|
||||||
|
|
||||||
// augment the provider with its enable method
|
// augment the provider with its enable method
|
||||||
inpageProvider.enable = function () {
|
inpageProvider.enable = function () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -50,13 +45,15 @@ inpageProvider.enable = function () {
|
|||||||
// wait for the publicConfig store to populate with an account
|
// wait for the publicConfig store to populate with an account
|
||||||
const publicConfig = new Promise((resolve) => {
|
const publicConfig = new Promise((resolve) => {
|
||||||
const { selectedAddress } = inpageProvider.publicConfigStore.getState()
|
const { selectedAddress } = inpageProvider.publicConfigStore.getState()
|
||||||
if (selectedAddress) {
|
inpageProvider._metamask.isUnlocked().then(unlocked => {
|
||||||
resolve()
|
if (!unlocked || selectedAddress) {
|
||||||
} else {
|
resolve()
|
||||||
inpageProvider.publicConfigStore.on('update', ({ selectedAddress }) => {
|
} else {
|
||||||
selectedAddress && resolve()
|
inpageProvider.publicConfigStore.on('update', ({ selectedAddress }) => {
|
||||||
})
|
selectedAddress && resolve()
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// wait for the background to update with an accoount
|
// wait for the background to update with an accoount
|
||||||
|
@ -1581,7 +1581,6 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
* Locks MetaMask
|
* Locks MetaMask
|
||||||
*/
|
*/
|
||||||
setLocked() {
|
setLocked() {
|
||||||
this.providerApprovalController.setLocked()
|
|
||||||
return this.keyringController.setLocked()
|
return this.keyringController.setLocked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user