diff options
author | bitpshr <mail@bitpshr.net> | 2018-10-18 06:29:40 +0800 |
---|---|---|
committer | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-11-06 07:07:09 +0800 |
commit | 573139b9357ccd97eb6b866721fafc93ceb080b6 (patch) | |
tree | f34a8dd34fb3914a3e80b055dbe2b31e1e09c259 /app/scripts | |
parent | 3a2ade4e8490fa754b66e8f342a8308879e2f9ed (diff) | |
download | tangerine-wallet-browser-573139b9357ccd97eb6b866721fafc93ceb080b6.tar tangerine-wallet-browser-573139b9357ccd97eb6b866721fafc93ceb080b6.tar.gz tangerine-wallet-browser-573139b9357ccd97eb6b866721fafc93ceb080b6.tar.bz2 tangerine-wallet-browser-573139b9357ccd97eb6b866721fafc93ceb080b6.tar.lz tangerine-wallet-browser-573139b9357ccd97eb6b866721fafc93ceb080b6.tar.xz tangerine-wallet-browser-573139b9357ccd97eb6b866721fafc93ceb080b6.tar.zst tangerine-wallet-browser-573139b9357ccd97eb6b866721fafc93ceb080b6.zip |
Differentiate isEnabled and isApproved hook
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/inpage.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index bfafc255d..88831c0cc 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -27,9 +27,10 @@ var metamaskStream = new LocalMessageDuplexStream({ // compose the inpage provider var inpageProvider = new MetamaskInpageProvider(metamaskStream) + // set a high max listener count to avoid unnecesary warnings inpageProvider.setMaxListeners(100) -var originApproved = false +var isEnabled = false // Augment the provider with its enable method inpageProvider.enable = function () { @@ -38,11 +39,11 @@ inpageProvider.enable = function () { if (typeof detail.error !== 'undefined') { reject(detail.error) } else { - originApproved = true inpageProvider.sendAsync({ method: 'eth_accounts', params: [] }, (error, response) => { if (error) { reject(error) } else { + isEnabled = true resolve(response.result) } }) @@ -53,18 +54,26 @@ inpageProvider.enable = function () { } inpageProvider.isEnabled = function () { + return isEnabled +} + +inpageProvider.isApproved = function () { return new Promise((resolve, reject) => { window.addEventListener('ethereumproviderstatus', ({ detail }) => { if (typeof detail.error !== 'undefined') { reject(detail.error) } else { - resolve(originApproved && !!detail.isEnabled) + resolve(!!detail.isEnabled) } }) window.postMessage({ type: 'ETHEREUM_QUERY_STATUS' }, '*') }) } +inpageProvider.isUnlocked = function () { + +} + // Work around for web3@1.0 deleting the bound `sendAsync` but not the unbound // `sendAsync` method on the prototype, causing `this` reference issues with drizzle const proxiedInpageProvider = new Proxy(inpageProvider, { |