aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorbitpshr <mail@bitpshr.net>2018-10-30 07:09:21 +0800
committerDan Finlay <542863+danfinlay@users.noreply.github.com>2018-11-06 07:07:09 +0800
commit72730b39296bf4531f69daa219b8cfccf06caac9 (patch)
tree920193794df0374b2a77d8335ea81fbad62ed379 /app
parentcc27a09a1aa676573c5b7354ba73b29ba38e08b8 (diff)
downloadtangerine-wallet-browser-72730b39296bf4531f69daa219b8cfccf06caac9.tar
tangerine-wallet-browser-72730b39296bf4531f69daa219b8cfccf06caac9.tar.gz
tangerine-wallet-browser-72730b39296bf4531f69daa219b8cfccf06caac9.tar.bz2
tangerine-wallet-browser-72730b39296bf4531f69daa219b8cfccf06caac9.tar.lz
tangerine-wallet-browser-72730b39296bf4531f69daa219b8cfccf06caac9.tar.xz
tangerine-wallet-browser-72730b39296bf4531f69daa219b8cfccf06caac9.tar.zst
tangerine-wallet-browser-72730b39296bf4531f69daa219b8cfccf06caac9.zip
Remove internal listeners
Diffstat (limited to 'app')
-rw-r--r--app/scripts/inpage.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index ddbb43326..d22072a3d 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -8,6 +8,9 @@ const MetamaskInpageProvider = require('metamask-inpage-provider')
let isEnabled = false
let warned = false
+let providerHandle
+let isApprovedHandle
+let isUnlockedHandle
restoreContextAfterImports()
@@ -43,7 +46,8 @@ window.addEventListener('metamasksetlocked', () => {
// augment the provider with its enable method
inpageProvider.enable = function () {
return new Promise((resolve, reject) => {
- window.addEventListener('ethereumprovider', ({ detail }) => {
+ window.removeEventListener('ethereumprovider', providerHandle)
+ providerHandle = ({ detail }) => {
if (typeof detail.error !== 'undefined') {
reject(detail.error)
} else {
@@ -79,7 +83,8 @@ inpageProvider.enable = function () {
})
.catch(reject)
}
- })
+ }
+ window.addEventListener('ethereumprovider', providerHandle)
window.postMessage({ type: 'ETHEREUM_ENABLE_PROVIDER' }, '*')
})
}
@@ -102,7 +107,8 @@ inpageProvider._metamask = new Proxy({
*/
isApproved: function() {
return new Promise((resolve, reject) => {
- window.addEventListener('ethereumisapproved', ({ detail }) => {
+ window.removeEventListener('ethereumisapproved', isApprovedHandle)
+ isApprovedHandle = ({ detail }) => {
if (typeof detail.error !== 'undefined') {
reject(detail.error)
} else {
@@ -112,7 +118,8 @@ inpageProvider._metamask = new Proxy({
resolve(isEnabled)
}
}
- })
+ }
+ window.addEventListener('ethereumisapproved', isApprovedHandle)
window.postMessage({ type: 'ETHEREUM_IS_APPROVED' }, '*')
})
},
@@ -124,13 +131,15 @@ inpageProvider._metamask = new Proxy({
*/
isUnlocked: function () {
return new Promise((resolve, reject) => {
- window.addEventListener('metamaskisunlocked', ({ detail }) => {
+ window.removeEventListener('metamaskisunlocked', isUnlockedHandle)
+ isUnlockedHandle = ({ detail }) => {
if (typeof detail.error !== 'undefined') {
reject(detail.error)
} else {
resolve(!!detail.isUnlocked)
}
- })
+ }
+ window.addEventListener('metamaskisunlocked', isUnlockedHandle)
window.postMessage({ type: 'METAMASK_IS_UNLOCKED' }, '*')
})
},