mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix race condition with publicConfigStore
This commit is contained in:
parent
32630b68df
commit
f35466a247
@ -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' }, '*')
|
||||
|
Loading…
Reference in New Issue
Block a user