Skip to content

Commit

Permalink
Merge pull request #928 from Keith-CY/disable-submit-button-before-re…
Browse files Browse the repository at this point in the history
…quest-sending

fix(neuron-ui): disable the submit button once a sending request is sent
  • Loading branch information
ashchan authored Sep 11, 2019
2 parents 474ef33 + 0c72b01 commit 4803492
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 47 deletions.
3 changes: 2 additions & 1 deletion packages/neuron-ui/src/components/PasswordRequest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { priceToFee, CKBToShannonFormatter } from 'utils/formatters'

const PasswordRequest = ({
app: {
send: { txID, outputs, description, price, cycles, loading: isSending },
send: { txID, outputs, description, price, cycles },
loadings: { sending: isSending = false },
passwordRequest: { walletID = '', actionType = null, password = '' },
},
settings: { wallets = [] },
Expand Down
1 change: 0 additions & 1 deletion packages/neuron-ui/src/states/initStates/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const appState: State.App = {
price: '0',
cycles: '0',
description: '',
loading: false,
},
passwordRequest: {
actionType: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,39 +148,40 @@ export const sendTransaction = (params: Controller.SendTransaction) => (dispatch
sending: true,
},
})
sendCapacity(params)
.then(res => {
if (res.status === 1) {
history.push(Routes.History)
} else {
// TODO: the pretreatment is unnecessary once the error code is implemented
addNotification({
type: 'alert',
timestamp: +new Date(),
code: res.status,
content: (typeof res.message === 'string' ? res.message : res.message.content || '').replace(
/(\b"|"\b)/g,
''
),
meta: typeof res.message === 'string' ? undefined : res.message.meta,
})(dispatch)
}
dispatch({
type: AppActions.DismissPasswordRequest,
payload: null,
setTimeout(() => {
sendCapacity(params)
.then(res => {
if (res.status === 1) {
history.push(Routes.History)
} else {
addNotification({
type: 'alert',
timestamp: +new Date(),
code: res.status,
content: (typeof res.message === 'string' ? res.message : res.message.content || '').replace(
/(\b"|"\b)/g,
''
),
meta: typeof res.message === 'string' ? undefined : res.message.meta,
})(dispatch)
}
dispatch({
type: AppActions.DismissPasswordRequest,
payload: null,
})
})
})
.catch(err => {
console.warn(err)
})
.finally(() => {
dispatch({
type: AppActions.UpdateLoadings,
payload: {
sending: false,
},
.catch(err => {
console.warn(err)
})
.finally(() => {
dispatch({
type: AppActions.UpdateLoadings,
payload: {
sending: false,
},
})
})
})
}, 0)
}

export const updateAddressListAndBalance = (params: Controller.GetAddressesByWalletIDParams) => (
Expand Down
13 changes: 0 additions & 13 deletions packages/neuron-ui/src/states/stateProvider/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export enum AppActions {
UpdateSendCycles = 'updateSendCycles',
UpdateSendDescription = 'updateSendDescription',
ClearSendState = 'clearSendState',
UpdateSendLoading = 'updateSendLoading',
UpdateMessage = 'updateMessage',
AddNotification = 'addNotification',
DismissNotification = 'dismissNotification',
Expand Down Expand Up @@ -366,18 +365,6 @@ export const reducer = (
},
}
}
case AppActions.UpdateSendLoading: {
return {
...state,
app: {
...app,
send: {
...app.send,
loading: payload,
},
},
}
}
case AppActions.ClearSendState: {
return {
...state,
Expand Down
1 change: 0 additions & 1 deletion packages/neuron-ui/src/types/App/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ declare namespace State {
price: string
cycles: string
description: string
loading: boolean
}

interface Popup {
Expand Down

0 comments on commit 4803492

Please sign in to comment.