Skip to content

Commit cb9a5f0

Browse files
committed
feat(neuron-ui): make description update fluently
1 parent 315623a commit cb9a5f0

4 files changed

Lines changed: 51 additions & 8 deletions

File tree

packages/neuron-ui/src/components/History/hooks.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useState, useEffect } from 'react'
2-
import { AppActions } from 'states/stateProvider/reducer'
32
import { updateTransactionList } from 'states/stateProvider/actionCreators/transactions'
43
import { queryParsers } from 'utils/parser'
54

@@ -27,10 +26,6 @@ export const useSearch = (search: string = '', walletID: string = '', dispatch:
2726
backToTop()
2827
const params = queryParsers.history(search)
2928
setKeywords(params.keywords)
30-
dispatch({
31-
type: AppActions.CleanTransactions,
32-
payload: null,
33-
})
3429
updateTransactionList({ ...params, keywords: params.keywords, walletID })(dispatch)
3530
}, [search, walletID, dispatch])
3631
return { keywords, onKeywordsChange, setKeywords }

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ export const updateTransactionDescription = (params: Controller.UpdateTransactio
4444
updateRemoteTransactionDescription(params)
4545
.then(res => {
4646
if (res.status) {
47-
dispatch({ type: AppActions.Ignore, payload: null })
47+
dispatch({
48+
type: NeuronWalletActions.UpdateTransactionDescription,
49+
payload: {
50+
hash: params.hash,
51+
description: params.description,
52+
},
53+
})
4854
} else {
4955
addNotification({ type: 'alert', content: res.message.title })(dispatch)
5056
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ export const updateAddressDescription = (params: Controller.UpdateAddressDescrip
163163
.then(res => {
164164
if (res.status) {
165165
dispatch({
166-
type: AppActions.Ignore,
167-
payload: null,
166+
type: NeuronWalletActions.UpdateAddressDescription,
167+
payload: {
168+
address: params.address,
169+
description: params.description,
170+
},
168171
})
169172
} else {
170173
addNotification({ type: 'alert', content: res.message.title })(dispatch)

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ export enum NeuronWalletActions {
88
UpdateCurrentWallet = 'updateCurrentWallet',
99
UpdateWalletList = 'updateWalletList',
1010
UpdateAddressListAndBalance = 'updateAddressListAndBalance',
11+
UpdateAddressDescription = 'updateAddressDescription',
1112
// transactions
1213
UpdateTransactionList = 'updateTransactionList',
1314
UpdateTransaction = 'updateTransaction',
15+
UpdateTransactionDescription = 'updateTransactionDescription',
1416
// networks
1517
UpdateNetworkList = 'updateNetworkList',
1618
UpdateCurrentNetworkID = 'updateCurrentNetworkID',
@@ -132,6 +134,23 @@ export const reducer = (
132134
},
133135
}
134136
}
137+
case NeuronWalletActions.UpdateAddressDescription: {
138+
/**
139+
* payload:{
140+
* address: string
141+
* description: string
142+
* }
143+
*/
144+
return {
145+
...state,
146+
wallet: {
147+
...wallet,
148+
addresses: wallet.addresses.map(addr =>
149+
addr.address === payload.address ? { ...addr, description: payload.description } : addr
150+
),
151+
},
152+
}
153+
}
135154
case NeuronWalletActions.UpdateAddressListAndBalance: {
136155
return {
137156
...state,
@@ -150,6 +169,26 @@ export const reducer = (
150169
},
151170
}
152171
}
172+
case NeuronWalletActions.UpdateTransactionDescription: {
173+
/**
174+
* payload: {
175+
* hash: string,
176+
* description: string
177+
* }
178+
*/
179+
return {
180+
...state,
181+
chain: {
182+
...chain,
183+
transactions: {
184+
...chain.transactions,
185+
items: chain.transactions.items.map(tx =>
186+
tx.hash === payload.hash ? { ...tx, description: payload.description } : tx
187+
),
188+
},
189+
},
190+
}
191+
}
153192
case NeuronWalletActions.UpdateTransaction: {
154193
return {
155194
...state,

0 commit comments

Comments
 (0)