2018-06-05 17:19:21 +00:00
|
|
|
import ERC20Token from 'Embark/contracts/ERC20Token';
|
2018-06-01 16:45:11 +00:00
|
|
|
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')
|
2018-06-13 16:58:19 +00:00
|
|
|
const SNTBalance = await ERC20Token.methods.balanceOf(address).call()
|
|
|
|
return { address, balance, SNTBalance }
|
2018-06-01 16:45:11 +00:00
|
|
|
})
|
|
|
|
Promise.all(accounts).then(accounts => {
|
|
|
|
dispatch(receiveAccounts(defaultAccount, accounts))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|