diff options
author | bitpshr <mail@bitpshr.net> | 2018-10-04 23:05:32 +0800 |
---|---|---|
committer | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-11-06 07:07:09 +0800 |
commit | bfcb73ad533b7c2acea012a586c2a391811faf03 (patch) | |
tree | ff3f8290e01d56396aa93424eadcd535ea0ec954 /app/scripts/inpage.js | |
parent | 89b4aa5d62237f36fac9dcce9c546005ec18968b (diff) | |
download | tangerine-wallet-browser-bfcb73ad533b7c2acea012a586c2a391811faf03.tar tangerine-wallet-browser-bfcb73ad533b7c2acea012a586c2a391811faf03.tar.gz tangerine-wallet-browser-bfcb73ad533b7c2acea012a586c2a391811faf03.tar.bz2 tangerine-wallet-browser-bfcb73ad533b7c2acea012a586c2a391811faf03.tar.lz tangerine-wallet-browser-bfcb73ad533b7c2acea012a586c2a391811faf03.tar.xz tangerine-wallet-browser-bfcb73ad533b7c2acea012a586c2a391811faf03.tar.zst tangerine-wallet-browser-bfcb73ad533b7c2acea012a586c2a391811faf03.zip |
EIP-1102: add isEnabled convenience method to provider
Diffstat (limited to 'app/scripts/inpage.js')
-rw-r--r-- | app/scripts/inpage.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 5b5c02c26..c5f4ee4c9 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -50,6 +50,19 @@ inpageProvider.enable = function () { }) } +inpageProvider.isEnabled = function () { + return new Promise((resolve, reject) => { + window.addEventListener('ethereumproviderstatus', ({ detail }) => { + if (typeof detail.error !== 'undefined') { + reject(detail.error) + } else { + resolve(detail.isEnabled) + } + }) + window.postMessage({ type: 'ETHEREUM_PROVIDER_STATUS' }, '*') + }) +} + // 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, { @@ -60,6 +73,7 @@ const proxiedInpageProvider = new Proxy(inpageProvider, { window.ethereum = proxiedInpageProvider + // // setup web3 // |