diff --git a/packages/neuron-ui/src/containers/Main/hooks.ts b/packages/neuron-ui/src/containers/Main/hooks.ts index f5669db5e1..f0b6473887 100644 --- a/packages/neuron-ui/src/containers/Main/hooks.ts +++ b/packages/neuron-ui/src/containers/Main/hooks.ts @@ -7,7 +7,7 @@ import { updateTransaction, updateCurrentWallet, updateWalletList, - updateAddressList, + updateAddressListAndBalance, initAppState, } from 'states/stateProvider/actionCreators' @@ -137,7 +137,7 @@ export const useSubscription = ({ } switch (dataType) { case 'address': { - updateAddressList(walletID)(dispatch) + updateAddressListAndBalance(walletID)(dispatch) break } case 'transaction': { diff --git a/packages/neuron-ui/src/states/stateProvider/actionCreators/wallets.ts b/packages/neuron-ui/src/states/stateProvider/actionCreators/wallets.ts index 0b01761376..bb7e7dda7c 100644 --- a/packages/neuron-ui/src/states/stateProvider/actionCreators/wallets.ts +++ b/packages/neuron-ui/src/states/stateProvider/actionCreators/wallets.ts @@ -11,9 +11,10 @@ import { deleteWallet as deleteRemoteWallet, backupWallet as backupRemoteWallet, } from 'services/remote' -import { wallets as walletsCache, currentWallet as currentWalletCache } from 'utils/localCache' import initStates from 'states/initStates' +import { wallets as walletsCache, currentWallet as currentWalletCache } from 'utils/localCache' import { Routes } from 'utils/const' +import addressesToBalance from 'utils/addressesToBalance' import { NeuronWalletActions } from '../reducer' import { addNotification } from './app' @@ -140,12 +141,16 @@ export const sendTransaction = (params: Controller.SendTransaction) => (dispatch }) } -export const updateAddressList = (params: Controller.GetAddressesByWalletIDParams) => (dispatch: StateDispatch) => { +export const updateAddressListAndBalance = (params: Controller.GetAddressesByWalletIDParams) => ( + dispatch: StateDispatch +) => { getAddressesByWalletID(params).then(res => { if (res.status) { + const addresses = res.result || [] + const balance = addressesToBalance(addresses) dispatch({ - type: NeuronWalletActions.UpdateAddressList, - payload: res.result, + type: NeuronWalletActions.UpdateAddressListAndBalance, + payload: { addresses, balance }, }) } else { addNotification({ type: 'alert', content: res.message.title })(dispatch) @@ -224,7 +229,7 @@ export default { updateWallet, setCurrentWallet, sendTransaction, - updateAddressList, + updateAddressListAndBalance, updateAddressDescription, deleteWallet, backupWallet, diff --git a/packages/neuron-ui/src/states/stateProvider/reducer.ts b/packages/neuron-ui/src/states/stateProvider/reducer.ts index 48f135c47c..4559ee40d3 100644 --- a/packages/neuron-ui/src/states/stateProvider/reducer.ts +++ b/packages/neuron-ui/src/states/stateProvider/reducer.ts @@ -6,7 +6,7 @@ export enum NeuronWalletActions { // wallets UpdateCurrentWallet = 'updateCurrentWallet', UpdateWalletList = 'updateWalletList', - UpdateAddressList = 'updateAddressList', + UpdateAddressListAndBalance = 'updateAddressListAndBalance', // transactions UpdateTransactionList = 'updateTransactionList', UpdateTransaction = 'updateTransaction', @@ -111,12 +111,12 @@ export const reducer = ( }, } } - case NeuronWalletActions.UpdateAddressList: { + case NeuronWalletActions.UpdateAddressListAndBalance: { return { ...state, wallet: { ...wallet, - addresses: payload, + ...payload, }, } }