Skip to content

Commit 6c4ea72

Browse files
committed
feat(neuron-ui): prevent updating tx and addr list when user is editing the description
1 parent 031fed0 commit 6c4ea72

13 files changed

Lines changed: 86 additions & 105 deletions

File tree

packages/neuron-ui/src/components/Addresses/index.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { onRenderRow } from 'utils/fabricUIRender'
2020

2121
const Addresses = ({
2222
app: {
23-
loadings: { addressList: isLoading, updateDescription: isUpdatingDescription },
23+
loadings: { addressList: isLoading },
2424
},
2525
wallet: { addresses = [], id: walletID },
2626
settings: { showAddressBook = false },
@@ -98,10 +98,6 @@ const Addresses = ({
9898
onBlur={isSelected ? onDescriptionFieldBlur(item.address, item.description) : undefined}
9999
onKeyPress={isSelected ? onDescriptionPress(item.address, item.description) : undefined}
100100
onChange={isSelected ? onDescriptionChange(item.address) : undefined}
101-
disabled={isSelected && isUpdatingDescription}
102-
iconProps={{
103-
iconName: isSelected && isUpdatingDescription ? 'Updating' : '',
104-
}}
105101
readOnly={!isSelected}
106102
styles={{
107103
root: {
@@ -110,7 +106,7 @@ const Addresses = ({
110106
fieldGroup: {
111107
backgroundColor: isSelected ? '#fff' : 'transparent',
112108
borderColor: 'transparent',
113-
border: isSelected ? '1px solid' : 'none',
109+
border: isSelected ? `1px solid ${semanticColors.inputBorder}!important` : 'none',
114110
},
115111
}}
116112
/>
@@ -161,8 +157,7 @@ const Addresses = ({
161157
localDescription,
162158
onDescriptionFieldBlur,
163159
onDescriptionPress,
164-
// onDescriptionFocus,
165-
isUpdatingDescription,
160+
onDescriptionSelected,
166161
t,
167162
semanticColors,
168163
]

packages/neuron-ui/src/components/History/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useSearch } from './hooks'
1414
const History = ({
1515
app: {
1616
tipBlockNumber: chainBlockNumber,
17-
loadings: { transactionList: isLoading, updateDescription: isUpdatingDescription },
17+
loadings: { transactionList: isLoading },
1818
},
1919
wallet: { id },
2020
chain: {
@@ -54,7 +54,6 @@ const History = ({
5454
</Stack>
5555
<TransactionList
5656
isLoading={isLoading}
57-
isUpdatingDescription={isUpdatingDescription}
5857
walletID={id}
5958
items={items}
6059
tipBlockNumber={tipBlockNumber}
@@ -87,7 +86,6 @@ const History = ({
8786
onKeywordsChange,
8887
onSearch,
8988
isLoading,
90-
isUpdatingDescription,
9189
id,
9290
items,
9391
tipBlockNumber,

packages/neuron-ui/src/components/TransactionList/index.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { onRenderRow } from 'utils/fabricUIRender'
2626
import { CONFIRMATION_THRESHOLD } from 'utils/const'
2727

2828
const theme = getTheme()
29+
const { semanticColors } = theme
2930

3031
const MIN_CELL_WIDTH = 50
3132

@@ -53,14 +54,12 @@ const onRenderHeader = ({ group }: any) => {
5354

5455
const TransactionList = ({
5556
isLoading = false,
56-
isUpdatingDescription = false,
5757
items = [],
5858
walletID,
5959
tipBlockNumber,
6060
dispatch,
6161
}: {
6262
isLoading?: boolean
63-
isUpdatingDescription?: boolean
6463
walletID: string
6564
items: State.Transaction[]
6665
tipBlockNumber: string
@@ -184,17 +183,13 @@ const TransactionList = ({
184183
onBlur={isSelected ? onDescriptionFieldBlur(item.hash, item.description) : undefined}
185184
onKeyPress={isSelected ? onDescriptionPress(item.hash, item.description) : undefined}
186185
onChange={isSelected ? onDescriptionChange(item.hash) : undefined}
187-
disabled={isSelected && isUpdatingDescription}
188-
iconProps={{
189-
iconName: isSelected && isUpdatingDescription ? 'Updating' : '',
190-
}}
191186
borderless
192187
readOnly={!isSelected}
193188
styles={{
194189
fieldGroup: {
195190
backgroundColor: isSelected ? '#fff' : 'transparent',
196191
borderColor: 'transparent',
197-
border: isSelected ? '1px solid' : 'none',
192+
border: isSelected ? `1px solid ${semanticColors.inputBorder}!important` : 'none',
198193
},
199194
}}
200195
/>
@@ -234,7 +229,6 @@ const TransactionList = ({
234229
onDescriptionFieldBlur,
235230
onDescriptionPress,
236231
onDescriptionSelected,
237-
isUpdatingDescription,
238232
t,
239233
]
240234
)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ export const useOnCurrentWalletChange = ({
116116
export const useSubscription = ({
117117
walletID,
118118
chain,
119+
isAllowedToFetchList,
119120
history,
120121
dispatch,
121122
}: {
122123
walletID: string
123124
chain: State.Chain
125+
isAllowedToFetchList: boolean
124126
history: any
125127
dispatch: StateDispatch
126128
}) => {
@@ -139,10 +141,16 @@ export const useSubscription = ({
139141
}
140142
switch (dataType) {
141143
case 'address': {
144+
if (!isAllowedToFetchList) {
145+
break
146+
}
142147
updateAddressListAndBalance(walletID)(dispatch)
143148
break
144149
}
145150
case 'transaction': {
151+
if (!isAllowedToFetchList) {
152+
break
153+
}
146154
updateTransactionList({
147155
walletID,
148156
keywords,
@@ -239,7 +247,7 @@ export const useSubscription = ({
239247
syncedBlockNumberSubscription.unsubscribe()
240248
commandSubscription.unsubscribe()
241249
}
242-
}, [walletID, pageNo, pageSize, keywords, history, dispatch])
250+
}, [walletID, pageNo, pageSize, keywords, isAllowedToFetchList, history, dispatch])
243251
}
244252

245253
export default {

packages/neuron-ui/src/containers/Main/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const MainContent = ({
115115
}: React.PropsWithoutRef<{ dispatch: StateDispatch } & RouteComponentProps>) => {
116116
const neuronWalletState = useState()
117117
const {
118+
app: { isAllowedToFetchList = true },
118119
wallet: { id: walletID = '' },
119120
chain,
120121
settings: { networks = [] },
@@ -125,6 +126,7 @@ const MainContent = ({
125126
useSubscription({
126127
walletID,
127128
chain,
129+
isAllowedToFetchList,
128130
history,
129131
dispatch,
130132
})

packages/neuron-ui/src/states/initStates/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ const appState: State.App = {
3737
sending: false,
3838
addressList: false,
3939
transactionList: false,
40-
updateDescription: false,
4140
},
4241
showTopAlert: false,
4342
showAllNotifications: false,
43+
isAllowedToFetchList: true,
4444
}
4545

4646
export default appState

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,19 @@ export const toggleAllNotificationVisibility = (show?: boolean) => (dispatch: St
100100
})
101101
}
102102

103+
export const toggleIsAllowedToFetchList = (allowed?: boolean) => (dispatch: StateDispatch) => {
104+
dispatch({
105+
type: AppActions.ToggleIsAllowedToFetchList,
106+
payload: allowed,
107+
})
108+
}
109+
103110
export default {
104111
initAppState,
105112
addNotification,
106113
addPopup,
107114
dismissNotification,
108115
toggleTopAlertVisibility,
109116
toggleAllNotificationVisibility,
117+
toggleIsAllowedToFetchList,
110118
}

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NeuronWalletActions, AppActions, StateDispatch } from 'states/stateProvider/reducer'
1+
import { NeuronWalletActions, StateDispatch } from 'states/stateProvider/reducer'
22
import {
33
GetTransactionListParams,
44
getTransactionList,
@@ -23,12 +23,6 @@ export const updateTransactionList = (params: GetTransactionListParams) => (disp
2323
export const updateTransactionDescription = (params: Controller.UpdateTransactionDescriptionParams) => (
2424
dispatch: StateDispatch
2525
) => {
26-
dispatch({
27-
type: AppActions.UpdateLoadings,
28-
payload: {
29-
updateDescription: true,
30-
},
31-
})
3226
const descriptionParams = {
3327
hash: params.hash,
3428
description: params.description,
@@ -37,25 +31,16 @@ export const updateTransactionDescription = (params: Controller.UpdateTransactio
3731
type: NeuronWalletActions.UpdateTransactionDescription,
3832
payload: descriptionParams,
3933
}) // update local description before remote description to avoid the flicker on the field
40-
updateRemoteTransactionDescription(params)
41-
.then(res => {
42-
if (res.status) {
43-
dispatch({
44-
type: NeuronWalletActions.UpdateTransactionDescription,
45-
payload: descriptionParams,
46-
})
47-
} else {
48-
addNotification(failureResToNotification(res))(dispatch)
49-
}
50-
})
51-
.finally(() => {
34+
updateRemoteTransactionDescription(params).then(res => {
35+
if (res.status) {
5236
dispatch({
53-
type: AppActions.UpdateLoadings,
54-
payload: {
55-
updateDescription: false,
56-
},
37+
type: NeuronWalletActions.UpdateTransactionDescription,
38+
payload: descriptionParams,
5739
})
58-
})
40+
} else {
41+
addNotification(failureResToNotification(res))(dispatch)
42+
}
43+
})
5944
}
6045

6146
export default {

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

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,6 @@ export const updateAddressListAndBalance = (params: Controller.GetAddressesByWal
203203
export const updateAddressDescription = (params: Controller.UpdateAddressDescriptionParams) => (
204204
dispatch: StateDispatch
205205
) => {
206-
dispatch({
207-
type: AppActions.UpdateLoadings,
208-
payload: {
209-
updateDescription: true,
210-
},
211-
})
212206
const descriptionParams = {
213207
address: params.address,
214208
description: params.description,
@@ -217,25 +211,16 @@ export const updateAddressDescription = (params: Controller.UpdateAddressDescrip
217211
type: NeuronWalletActions.UpdateAddressDescription,
218212
payload: descriptionParams,
219213
})
220-
updateRemoteAddressDescription(params)
221-
.then(res => {
222-
if (res.status) {
223-
dispatch({
224-
type: NeuronWalletActions.UpdateAddressDescription,
225-
payload: descriptionParams,
226-
})
227-
} else {
228-
addNotification(failureResToNotification(res))(dispatch)
229-
}
230-
})
231-
.finally(() => {
214+
updateRemoteAddressDescription(params).then(res => {
215+
if (res.status) {
232216
dispatch({
233-
type: AppActions.UpdateLoadings,
234-
payload: {
235-
updateDescription: false,
236-
},
217+
type: NeuronWalletActions.UpdateAddressDescription,
218+
payload: descriptionParams,
237219
})
238-
})
220+
} else {
221+
addNotification(failureResToNotification(res))(dispatch)
222+
}
223+
})
239224
}
240225

241226
export const deleteWallet = (params: Controller.DeleteWalletParams) => (dispatch: StateDispatch) => {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export enum AppActions {
4747
PopOut = 'popOut',
4848
ToggleTopAlertVisibility = 'toggleTopAlertVisibility',
4949
ToggleAllNotificationVisibility = 'toggleAllNotificationVisibility',
50+
ToggleIsAllowedToFetchList = 'toggleIsAllowedToFetchList',
5051
Ignore = 'ignore',
5152
}
5253

@@ -538,6 +539,15 @@ export const reducer = (
538539
},
539540
}
540541
}
542+
case AppActions.ToggleIsAllowedToFetchList: {
543+
return {
544+
...state,
545+
app: {
546+
...app,
547+
isAllowedToFetchList: payload === undefined ? !app.isAllowedToFetchList : payload,
548+
},
549+
}
550+
}
541551
default: {
542552
return state
543553
}

0 commit comments

Comments
 (0)