mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
Remove internal listeners
This commit is contained in:
parent
cc27a09a1a
commit
72730b3929
@ -8,6 +8,9 @@ const MetamaskInpageProvider = require('metamask-inpage-provider')
|
|||||||
|
|
||||||
let isEnabled = false
|
let isEnabled = false
|
||||||
let warned = false
|
let warned = false
|
||||||
|
let providerHandle
|
||||||
|
let isApprovedHandle
|
||||||
|
let isUnlockedHandle
|
||||||
|
|
||||||
restoreContextAfterImports()
|
restoreContextAfterImports()
|
||||||
|
|
||||||
@ -43,7 +46,8 @@ window.addEventListener('metamasksetlocked', () => {
|
|||||||
// 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) => {
|
||||||
window.addEventListener('ethereumprovider', ({ detail }) => {
|
window.removeEventListener('ethereumprovider', providerHandle)
|
||||||
|
providerHandle = ({ detail }) => {
|
||||||
if (typeof detail.error !== 'undefined') {
|
if (typeof detail.error !== 'undefined') {
|
||||||
reject(detail.error)
|
reject(detail.error)
|
||||||
} else {
|
} else {
|
||||||
@ -79,7 +83,8 @@ inpageProvider.enable = function () {
|
|||||||
})
|
})
|
||||||
.catch(reject)
|
.catch(reject)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
window.addEventListener('ethereumprovider', providerHandle)
|
||||||
window.postMessage({ type: 'ETHEREUM_ENABLE_PROVIDER' }, '*')
|
window.postMessage({ type: 'ETHEREUM_ENABLE_PROVIDER' }, '*')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -102,7 +107,8 @@ inpageProvider._metamask = new Proxy({
|
|||||||
*/
|
*/
|
||||||
isApproved: function() {
|
isApproved: function() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
window.addEventListener('ethereumisapproved', ({ detail }) => {
|
window.removeEventListener('ethereumisapproved', isApprovedHandle)
|
||||||
|
isApprovedHandle = ({ detail }) => {
|
||||||
if (typeof detail.error !== 'undefined') {
|
if (typeof detail.error !== 'undefined') {
|
||||||
reject(detail.error)
|
reject(detail.error)
|
||||||
} else {
|
} else {
|
||||||
@ -112,7 +118,8 @@ inpageProvider._metamask = new Proxy({
|
|||||||
resolve(isEnabled)
|
resolve(isEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
window.addEventListener('ethereumisapproved', isApprovedHandle)
|
||||||
window.postMessage({ type: 'ETHEREUM_IS_APPROVED' }, '*')
|
window.postMessage({ type: 'ETHEREUM_IS_APPROVED' }, '*')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -124,13 +131,15 @@ inpageProvider._metamask = new Proxy({
|
|||||||
*/
|
*/
|
||||||
isUnlocked: function () {
|
isUnlocked: function () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
window.addEventListener('metamaskisunlocked', ({ detail }) => {
|
window.removeEventListener('metamaskisunlocked', isUnlockedHandle)
|
||||||
|
isUnlockedHandle = ({ detail }) => {
|
||||||
if (typeof detail.error !== 'undefined') {
|
if (typeof detail.error !== 'undefined') {
|
||||||
reject(detail.error)
|
reject(detail.error)
|
||||||
} else {
|
} else {
|
||||||
resolve(!!detail.isUnlocked)
|
resolve(!!detail.isUnlocked)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
window.addEventListener('metamaskisunlocked', isUnlockedHandle)
|
||||||
window.postMessage({ type: 'METAMASK_IS_UNLOCKED' }, '*')
|
window.postMessage({ type: 'METAMASK_IS_UNLOCKED' }, '*')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user