Skip to content

Commit 0c72b01

Browse files
committed
fix(neuron-ui): disable the submit button once a sending request is sent
Add a timeout to avoid the block in ui process due to the transaction generation
1 parent ae680bf commit 0c72b01

5 files changed

Lines changed: 34 additions & 47 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { priceToFee, CKBToShannonFormatter } from 'utils/formatters'
88

99
const PasswordRequest = ({
1010
app: {
11-
send: { txID, outputs, description, price, cycles, loading: isSending },
11+
send: { txID, outputs, description, price, cycles },
12+
loadings: { sending: isSending = false },
1213
passwordRequest: { walletID = '', actionType = null, password = '' },
1314
},
1415
settings: { wallets = [] },

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const appState: State.App = {
1717
price: '0',
1818
cycles: '0',
1919
description: '',
20-
loading: false,
2120
},
2221
passwordRequest: {
2322
actionType: null,

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

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -148,39 +148,40 @@ export const sendTransaction = (params: Controller.SendTransaction) => (dispatch
148148
sending: true,
149149
},
150150
})
151-
sendCapacity(params)
152-
.then(res => {
153-
if (res.status === 1) {
154-
history.push(Routes.History)
155-
} else {
156-
// TODO: the pretreatment is unnecessary once the error code is implemented
157-
addNotification({
158-
type: 'alert',
159-
timestamp: +new Date(),
160-
code: res.status,
161-
content: (typeof res.message === 'string' ? res.message : res.message.content || '').replace(
162-
/(\b"|"\b)/g,
163-
''
164-
),
165-
meta: typeof res.message === 'string' ? undefined : res.message.meta,
166-
})(dispatch)
167-
}
168-
dispatch({
169-
type: AppActions.DismissPasswordRequest,
170-
payload: null,
151+
setTimeout(() => {
152+
sendCapacity(params)
153+
.then(res => {
154+
if (res.status === 1) {
155+
history.push(Routes.History)
156+
} else {
157+
addNotification({
158+
type: 'alert',
159+
timestamp: +new Date(),
160+
code: res.status,
161+
content: (typeof res.message === 'string' ? res.message : res.message.content || '').replace(
162+
/(\b"|"\b)/g,
163+
''
164+
),
165+
meta: typeof res.message === 'string' ? undefined : res.message.meta,
166+
})(dispatch)
167+
}
168+
dispatch({
169+
type: AppActions.DismissPasswordRequest,
170+
payload: null,
171+
})
171172
})
172-
})
173-
.catch(err => {
174-
console.warn(err)
175-
})
176-
.finally(() => {
177-
dispatch({
178-
type: AppActions.UpdateLoadings,
179-
payload: {
180-
sending: false,
181-
},
173+
.catch(err => {
174+
console.warn(err)
175+
})
176+
.finally(() => {
177+
dispatch({
178+
type: AppActions.UpdateLoadings,
179+
payload: {
180+
sending: false,
181+
},
182+
})
182183
})
183-
})
184+
}, 0)
184185
}
185186

186187
export const updateAddressListAndBalance = (params: Controller.GetAddressesByWalletIDParams) => (

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export enum AppActions {
2929
UpdateSendCycles = 'updateSendCycles',
3030
UpdateSendDescription = 'updateSendDescription',
3131
ClearSendState = 'clearSendState',
32-
UpdateSendLoading = 'updateSendLoading',
3332
UpdateMessage = 'updateMessage',
3433
AddNotification = 'addNotification',
3534
DismissNotification = 'dismissNotification',
@@ -366,18 +365,6 @@ export const reducer = (
366365
},
367366
}
368367
}
369-
case AppActions.UpdateSendLoading: {
370-
return {
371-
...state,
372-
app: {
373-
...app,
374-
send: {
375-
...app.send,
376-
loading: payload,
377-
},
378-
},
379-
}
380-
}
381368
case AppActions.ClearSendState: {
382369
return {
383370
...state,

packages/neuron-ui/src/types/App/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ declare namespace State {
6161
price: string
6262
cycles: string
6363
description: string
64-
loading: boolean
6564
}
6665

6766
interface Popup {

0 commit comments

Comments
 (0)