Skip to content

Commit

Permalink
feat(neuron-ui): make description update fluently
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Aug 2, 2019
1 parent 315623a commit cb9a5f0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
5 changes: 0 additions & 5 deletions packages/neuron-ui/src/components/History/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useState, useEffect } from 'react'
import { AppActions } from 'states/stateProvider/reducer'
import { updateTransactionList } from 'states/stateProvider/actionCreators/transactions'
import { queryParsers } from 'utils/parser'

Expand Down Expand Up @@ -27,10 +26,6 @@ export const useSearch = (search: string = '', walletID: string = '', dispatch:
backToTop()
const params = queryParsers.history(search)
setKeywords(params.keywords)
dispatch({
type: AppActions.CleanTransactions,
payload: null,
})
updateTransactionList({ ...params, keywords: params.keywords, walletID })(dispatch)
}, [search, walletID, dispatch])
return { keywords, onKeywordsChange, setKeywords }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ export const updateTransactionDescription = (params: Controller.UpdateTransactio
updateRemoteTransactionDescription(params)
.then(res => {
if (res.status) {
dispatch({ type: AppActions.Ignore, payload: null })
dispatch({
type: NeuronWalletActions.UpdateTransactionDescription,
payload: {
hash: params.hash,
description: params.description,
},
})
} else {
addNotification({ type: 'alert', content: res.message.title })(dispatch)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ export const updateAddressDescription = (params: Controller.UpdateAddressDescrip
.then(res => {
if (res.status) {
dispatch({
type: AppActions.Ignore,
payload: null,
type: NeuronWalletActions.UpdateAddressDescription,
payload: {
address: params.address,
description: params.description,
},
})
} else {
addNotification({ type: 'alert', content: res.message.title })(dispatch)
Expand Down
39 changes: 39 additions & 0 deletions packages/neuron-ui/src/states/stateProvider/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ export enum NeuronWalletActions {
UpdateCurrentWallet = 'updateCurrentWallet',
UpdateWalletList = 'updateWalletList',
UpdateAddressListAndBalance = 'updateAddressListAndBalance',
UpdateAddressDescription = 'updateAddressDescription',
// transactions
UpdateTransactionList = 'updateTransactionList',
UpdateTransaction = 'updateTransaction',
UpdateTransactionDescription = 'updateTransactionDescription',
// networks
UpdateNetworkList = 'updateNetworkList',
UpdateCurrentNetworkID = 'updateCurrentNetworkID',
Expand Down Expand Up @@ -132,6 +134,23 @@ export const reducer = (
},
}
}
case NeuronWalletActions.UpdateAddressDescription: {
/**
* payload:{
* address: string
* description: string
* }
*/
return {
...state,
wallet: {
...wallet,
addresses: wallet.addresses.map(addr =>
addr.address === payload.address ? { ...addr, description: payload.description } : addr
),
},
}
}
case NeuronWalletActions.UpdateAddressListAndBalance: {
return {
...state,
Expand All @@ -150,6 +169,26 @@ export const reducer = (
},
}
}
case NeuronWalletActions.UpdateTransactionDescription: {
/**
* payload: {
* hash: string,
* description: string
* }
*/
return {
...state,
chain: {
...chain,
transactions: {
...chain.transactions,
items: chain.transactions.items.map(tx =>
tx.hash === payload.hash ? { ...tx, description: payload.description } : tx
),
},
},
}
}
case NeuronWalletActions.UpdateTransaction: {
return {
...state,
Expand Down

0 comments on commit cb9a5f0

Please sign in to comment.