Skip to content

Commit c0809bf

Browse files
committed
fix: update balance when address list is updated
1 parent bea9478 commit c0809bf

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

packages/neuron-ui/src/containers/Main/hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
updateTransaction,
88
updateCurrentWallet,
99
updateWalletList,
10-
updateAddressList,
10+
updateAddressListAndBalance,
1111
initAppState,
1212
} from 'states/stateProvider/actionCreators'
1313

@@ -137,7 +137,7 @@ export const useSubscription = ({
137137
}
138138
switch (dataType) {
139139
case 'address': {
140-
updateAddressList(walletID)(dispatch)
140+
updateAddressListAndBalance(walletID)(dispatch)
141141
break
142142
}
143143
case 'transaction': {

packages/neuron-ui/src/states/stateProvider/actionCreators/wallets.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import {
1111
deleteWallet as deleteRemoteWallet,
1212
backupWallet as backupRemoteWallet,
1313
} from 'services/remote'
14-
import { wallets as walletsCache, currentWallet as currentWalletCache } from 'utils/localCache'
1514
import initStates from 'states/initStates'
15+
import { wallets as walletsCache, currentWallet as currentWalletCache } from 'utils/localCache'
1616
import { Routes } from 'utils/const'
17+
import addressesToBalance from 'utils/addressesToBalance'
1718
import { NeuronWalletActions } from '../reducer'
1819
import { addNotification } from './app'
1920

@@ -140,12 +141,16 @@ export const sendTransaction = (params: Controller.SendTransaction) => (dispatch
140141
})
141142
}
142143

143-
export const updateAddressList = (params: Controller.GetAddressesByWalletIDParams) => (dispatch: StateDispatch) => {
144+
export const updateAddressListAndBalance = (params: Controller.GetAddressesByWalletIDParams) => (
145+
dispatch: StateDispatch
146+
) => {
144147
getAddressesByWalletID(params).then(res => {
145148
if (res.status) {
149+
const addresses = res.result || []
150+
const balance = addressesToBalance(addresses)
146151
dispatch({
147-
type: NeuronWalletActions.UpdateAddressList,
148-
payload: res.result,
152+
type: NeuronWalletActions.UpdateAddressListAndBalance,
153+
payload: { addresses, balance },
149154
})
150155
} else {
151156
addNotification({ type: 'alert', content: res.message.title })(dispatch)
@@ -224,7 +229,7 @@ export default {
224229
updateWallet,
225230
setCurrentWallet,
226231
sendTransaction,
227-
updateAddressList,
232+
updateAddressListAndBalance,
228233
updateAddressDescription,
229234
deleteWallet,
230235
backupWallet,

packages/neuron-ui/src/states/stateProvider/reducer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export enum NeuronWalletActions {
66
// wallets
77
UpdateCurrentWallet = 'updateCurrentWallet',
88
UpdateWalletList = 'updateWalletList',
9-
UpdateAddressList = 'updateAddressList',
9+
UpdateAddressListAndBalance = 'updateAddressListAndBalance',
1010
// transactions
1111
UpdateTransactionList = 'updateTransactionList',
1212
UpdateTransaction = 'updateTransaction',
@@ -111,12 +111,12 @@ export const reducer = (
111111
},
112112
}
113113
}
114-
case NeuronWalletActions.UpdateAddressList: {
114+
case NeuronWalletActions.UpdateAddressListAndBalance: {
115115
return {
116116
...state,
117117
wallet: {
118118
...wallet,
119-
addresses: payload,
119+
...payload,
120120
},
121121
}
122122
}

0 commit comments

Comments
 (0)