diff options
author | Paul Bouchon <mail@bitpshr.net> | 2018-11-10 09:40:32 +0800 |
---|---|---|
committer | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-11-10 10:21:59 +0800 |
commit | c3176248544e3e0019389b1f177cac68087bfe8f (patch) | |
tree | c1100bb2ef2949138a48d950b206f85b06ab8948 /app/scripts/inpage.js | |
parent | 782c2c14d4278c5228465b39408f5eafb167b86a (diff) | |
download | tangerine-wallet-browser-c3176248544e3e0019389b1f177cac68087bfe8f.tar tangerine-wallet-browser-c3176248544e3e0019389b1f177cac68087bfe8f.tar.gz tangerine-wallet-browser-c3176248544e3e0019389b1f177cac68087bfe8f.tar.bz2 tangerine-wallet-browser-c3176248544e3e0019389b1f177cac68087bfe8f.tar.lz tangerine-wallet-browser-c3176248544e3e0019389b1f177cac68087bfe8f.tar.xz tangerine-wallet-browser-c3176248544e3e0019389b1f177cac68087bfe8f.tar.zst tangerine-wallet-browser-c3176248544e3e0019389b1f177cac68087bfe8f.zip |
EIP-1102: Update publicConfig store concurrently with approval
Diffstat (limited to 'app/scripts/inpage.js')
-rw-r--r-- | app/scripts/inpage.js | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index cfcf5e364..83392761e 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -56,45 +56,31 @@ inpageProvider.setMaxListeners(100) // set up a listener for when MetaMask is locked onMessage('metamasksetlocked', () => { isEnabled = false }) +// set up a listener for privacy mode responses +onMessage('ethereumproviderlegacy', ({ data: { selectedAddress } }) => { + isEnabled = true + inpageProvider.publicConfigStore.updateState({ selectedAddress }) +}, true) + // augment the provider with its enable method inpageProvider.enable = function ({ force } = {}) { return new Promise((resolve, reject) => { - providerHandle = ({ data: { error } }) => { + providerHandle = ({ data: { error, selectedAddress } }) => { if (typeof error !== 'undefined') { reject(error) } else { window.removeEventListener('message', providerHandle) - // wait for the publicConfig store to populate with an account - const publicConfig = new Promise((resolve) => { - const { selectedAddress } = inpageProvider.publicConfigStore.getState() - inpageProvider._metamask.isUnlocked().then(unlocked => { - if (!unlocked || selectedAddress) { - resolve() - } else { - inpageProvider.publicConfigStore.on('update', ({ selectedAddress }) => { - selectedAddress && resolve() - }) - } - }) - }) + inpageProvider.publicConfigStore.updateState({ selectedAddress }) // wait for the background to update with an account - 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]) => { + inpageProvider.sendAsync({ method: 'eth_accounts', params: [] }, (error, response) => { + if (error) { + reject(error) + } else { isEnabled = true - resolve(selectedAddress) - }) - .catch(reject) + resolve(response.result) + } + }) } } onMessage('ethereumprovider', providerHandle, true) |