mirror of
https://github.com/status-im/ens-usernames.git
synced 2025-01-10 02:46:24 +00:00
cb41a904c5
add reselect - memoizes from the state tree
20 lines
775 B
JavaScript
20 lines
775 B
JavaScript
import ERC20Token from 'Embark/contracts/ERC20Token';
|
|
import { actions as accountActions } from '../reducers/accounts'
|
|
|
|
const { receiveAccounts } = accountActions
|
|
export const fetchAndDispatchAccountsWithBalances = (web3, dispatch) => {
|
|
web3.eth.getAccounts((err, addresses) => {
|
|
if (addresses) {
|
|
const defaultAccount = web3.eth.defaultAccount || addresses[0]
|
|
const accounts = addresses.map(async address => {
|
|
const balance = await web3.eth.getBalance(address, 'latest')
|
|
const ERC20TokenBalance = await ERC20Token.methods.balanceOf(address).call()
|
|
return { address, balance, ERC20TokenBalance }
|
|
})
|
|
Promise.all(accounts).then(accounts => {
|
|
dispatch(receiveAccounts(defaultAccount, accounts))
|
|
})
|
|
}
|
|
})
|
|
}
|