|
|
@ -3,17 +3,14 @@ import { RunTab } from "../types/run-tab" |
|
|
|
import { clearInstances, setAccount, setExecEnv } from "./actions" |
|
|
|
import { clearInstances, setAccount, setExecEnv } from "./actions" |
|
|
|
import { displayNotification, displayPopUp, fetchAccountsListFailed, fetchAccountsListRequest, fetchAccountsListSuccess, setExternalEndpoint, setMatchPassphrase, setPassphrase } from "./payload" |
|
|
|
import { displayNotification, displayPopUp, fetchAccountsListFailed, fetchAccountsListRequest, fetchAccountsListSuccess, setExternalEndpoint, setMatchPassphrase, setPassphrase } from "./payload" |
|
|
|
|
|
|
|
|
|
|
|
export const updateAccountBalances = (plugin: RunTab, dispatch: React.Dispatch<any>) => { |
|
|
|
export const updateAccountBalances = async (plugin: RunTab, dispatch: React.Dispatch<any>) => { |
|
|
|
const accounts = plugin.REACT_API.accounts.loadedAccounts |
|
|
|
const accounts = plugin.REACT_API.accounts.loadedAccounts |
|
|
|
|
|
|
|
|
|
|
|
Object.keys(accounts).map((value) => { |
|
|
|
for (const account of Object.keys(accounts)) { |
|
|
|
plugin.blockchain.getBalanceInEther(value, (err, balance) => { |
|
|
|
const balance = await plugin.blockchain.getBalanceInEther(account) |
|
|
|
if (err) return |
|
|
|
const updated = shortenAddress(account, balance) |
|
|
|
const updated = shortenAddress(value, balance) |
|
|
|
accounts[account] = updated |
|
|
|
|
|
|
|
} |
|
|
|
accounts[value] = updated |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
dispatch(fetchAccountsListSuccess(accounts)) |
|
|
|
dispatch(fetchAccountsListSuccess(accounts)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -31,17 +28,10 @@ export const fillAccountsList = async (plugin: RunTab, dispatch: React.Dispatch< |
|
|
|
// - all the promises resolve
|
|
|
|
// - all the promises resolve
|
|
|
|
// - at least one reject
|
|
|
|
// - at least one reject
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
|
|
|
|
await (Promise as any).all(accounts.map((account) => { |
|
|
|
for (const account of accounts) { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
const balance = await plugin.blockchain.getBalanceInEther(account) |
|
|
|
plugin.blockchain.getBalanceInEther(account, (err, balance) => { |
|
|
|
loadedAccounts[account] = shortenAddress(account, balance) |
|
|
|
if (err) return reject(err) |
|
|
|
}
|
|
|
|
const updated = shortenAddress(account, balance) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadedAccounts[account] = updated |
|
|
|
|
|
|
|
resolve(account) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
const provider = plugin.blockchain.getProvider() |
|
|
|
const provider = plugin.blockchain.getProvider() |
|
|
|
|
|
|
|
|
|
|
|
if (provider === 'injected') { |
|
|
|
if (provider === 'injected') { |
|
|
|