Skip to content

Commit

Permalink
fix: update balance when address list is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Jul 29, 2019
1 parent bea9478 commit c0809bf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/neuron-ui/src/containers/Main/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
updateTransaction,
updateCurrentWallet,
updateWalletList,
updateAddressList,
updateAddressListAndBalance,
initAppState,
} from 'states/stateProvider/actionCreators'

Expand Down Expand Up @@ -137,7 +137,7 @@ export const useSubscription = ({
}
switch (dataType) {
case 'address': {
updateAddressList(walletID)(dispatch)
updateAddressListAndBalance(walletID)(dispatch)
break
}
case 'transaction': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -224,7 +229,7 @@ export default {
updateWallet,
setCurrentWallet,
sendTransaction,
updateAddressList,
updateAddressListAndBalance,
updateAddressDescription,
deleteWallet,
backupWallet,
Expand Down
6 changes: 3 additions & 3 deletions packages/neuron-ui/src/states/stateProvider/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export enum NeuronWalletActions {
// wallets
UpdateCurrentWallet = 'updateCurrentWallet',
UpdateWalletList = 'updateWalletList',
UpdateAddressList = 'updateAddressList',
UpdateAddressListAndBalance = 'updateAddressListAndBalance',
// transactions
UpdateTransactionList = 'updateTransactionList',
UpdateTransaction = 'updateTransaction',
Expand Down Expand Up @@ -111,12 +111,12 @@ export const reducer = (
},
}
}
case NeuronWalletActions.UpdateAddressList: {
case NeuronWalletActions.UpdateAddressListAndBalance: {
return {
...state,
wallet: {
...wallet,
addresses: payload,
...payload,
},
}
}
Expand Down

0 comments on commit c0809bf

Please sign in to comment.