From cde192df0d48bb45f57c319179dbd9f64abd13e9 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 7 Nov 2018 23:36:00 -0800 Subject: feat(instant): fetch balance at startup --- packages/instant/src/redux/async_data.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'packages/instant/src/redux/async_data.ts') diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index e27ec1dc3..862f60e78 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -50,8 +50,24 @@ export const asyncData = { if (!_.isEmpty(availableAddresses)) { const activeAddress = availableAddresses[0]; store.dispatch(actions.setAccountStateReady(activeAddress)); + await asyncData.fetchAccountBalanceAndDispatchToStore(store); } else { store.dispatch(actions.setAccountStateLocked()); } }, + fetchAccountBalanceAndDispatchToStore: async (store: Store) => { + const { providerState } = store.getState(); + const web3Wrapper = providerState.web3Wrapper; + const account = providerState.account; + if (account.state !== AccountState.Ready) { + return; + } + try { + const ethBalanceInWei = await web3Wrapper.getBalanceInWeiAsync(account.address); + store.dispatch(actions.updateAccountEthBalance(ethBalanceInWei)); + } catch (e) { + // leave balance as is + return; + } + }, }; -- cgit v1.2.3