diff options
author | bitpshr <mail@bitpshr.net> | 2018-10-24 01:19:01 +0800 |
---|---|---|
committer | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-11-06 07:07:09 +0800 |
commit | f35466a247e503659228f0b8e098275a875026a4 (patch) | |
tree | 4604b76fa57d9f961410fee139a27fae30d1366d /app/scripts | |
parent | 32630b68dfae257a59bf1ce985e9a04ca1ca58b4 (diff) | |
download | tangerine-wallet-browser-f35466a247e503659228f0b8e098275a875026a4.tar tangerine-wallet-browser-f35466a247e503659228f0b8e098275a875026a4.tar.gz tangerine-wallet-browser-f35466a247e503659228f0b8e098275a875026a4.tar.bz2 tangerine-wallet-browser-f35466a247e503659228f0b8e098275a875026a4.tar.lz tangerine-wallet-browser-f35466a247e503659228f0b8e098275a875026a4.tar.xz tangerine-wallet-browser-f35466a247e503659228f0b8e098275a875026a4.tar.zst tangerine-wallet-browser-f35466a247e503659228f0b8e098275a875026a4.zip |
Fix race condition with publicConfigStore
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/inpage.js | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 9d50a695f..cadc61727 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -40,14 +40,33 @@ inpageProvider.enable = function () { if (typeof detail.error !== 'undefined') { reject(detail.error) } else { - inpageProvider.sendAsync({ method: 'eth_accounts', params: [] }, (error, response) => { - if (error) { - reject(error) + const publicConfig = new Promise((resolve) => { + const { selectedAddress } = inpageProvider.publicConfigStore.getState() + if (selectedAddress) { + resolve() } else { - isEnabled = true - resolve(response.result) + inpageProvider.publicConfigStore.on('update', ({ selectedAddress }) => { + selectedAddress && resolve() + }) } }) + + const ethAccounts = new Promise((resolveAccounts, rejectAccounts) => { + inpageProvider.sendAsync({ method: 'eth_accounts', params: [] }, (error, response) => { + if (error) { + rejectAccounts(error) + } else { + resolveAccounts(response.result) + } + }) + }) + + Promise.all([ethAccounts, publicConfig]) + .then(([selectedAddress]) => { + isEnabled = true + resolve(selectedAddress) + }) + .catch(reject) } }) window.postMessage({ type: 'ETHEREUM_ENABLE_PROVIDER' }, '*') |