From 711b307e6c56457647a98c6d76725aa90ac0d53e Mon Sep 17 00:00:00 2001 From: fragosti Date: Mon, 12 Nov 2018 15:28:54 -0800 Subject: feat: prevent eth balance blink --- packages/instant/src/redux/async_data.ts | 6 +++--- packages/instant/src/redux/reducer.ts | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'packages') diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index 8999ef097..2682677b9 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -72,9 +72,9 @@ export const asyncData = { fetchAccountBalanceAndDispatchToStore: async (providerState: ProviderState, dispatch: Dispatch) => { const web3Wrapper = providerState.web3Wrapper; const account = providerState.account; - if (account.state !== AccountState.Ready) { - return; - } + // if (account.state !== AccountState.Ready) { + // return; + // } try { const address = account.address; const ethBalanceInWei = await web3Wrapper.getBalanceInWeiAsync(address); diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index 4688250bc..28f094184 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -73,11 +73,16 @@ export const createReducer = (initialState: State) => { case ActionTypes.SET_ACCOUNT_STATE_LOCKED: return reduceStateWithAccount(state, LOCKED_ACCOUNT); case ActionTypes.SET_ACCOUNT_STATE_READY: { - const account: AccountReady = { + const address = action.data; + const newAccount: AccountReady = { state: AccountState.Ready, - address: action.data, + address, }; - return reduceStateWithAccount(state, account); + const currentAccount = state.providerState.account; + if (currentAccount.state === AccountState.Ready && currentAccount.address === address) { + newAccount.ethBalanceInWei = currentAccount.ethBalanceInWei; + } + return reduceStateWithAccount(state, newAccount); } case ActionTypes.UPDATE_ACCOUNT_ETH_BALANCE: { const { address, ethBalanceInWei } = action.data; -- cgit v1.2.3