From 148a61645f39fda5d74bdd4ee6517af628985801 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Tue, 29 May 2018 10:48:28 +0200 Subject: [PATCH] pendingTx rejected state --- src/js/actions/PendingTxActions.js | 2 +- src/js/actions/SelectedAccountActions.js | 28 +++++++++++++++++++ .../account/send/PendingTransactions.js | 3 +- src/js/reducers/PendingTxReducer.js | 14 +++++++++- src/js/reducers/utils/index.js | 3 +- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/js/actions/PendingTxActions.js b/src/js/actions/PendingTxActions.js index 3b263dc8..c0f38520 100644 --- a/src/js/actions/PendingTxActions.js +++ b/src/js/actions/PendingTxActions.js @@ -10,7 +10,7 @@ export type PendingTxAction = { } | { type: typeof PENDING.TX_RESOLVED, tx: PendingTx, - receipt: Object, + receipt?: Object, } | { type: typeof PENDING.TX_NOT_FOUND, tx: PendingTx, diff --git a/src/js/actions/SelectedAccountActions.js b/src/js/actions/SelectedAccountActions.js index 27955db1..faa7da89 100644 --- a/src/js/actions/SelectedAccountActions.js +++ b/src/js/actions/SelectedAccountActions.js @@ -4,6 +4,8 @@ import { LOCATION_CHANGE } from 'react-router-redux'; import * as ACCOUNT from './constants/account'; import * as SEND from './constants/send'; +import * as NOTIFICATION from './constants/notification'; +import * as PENDING from './constants/pendingTx'; import * as SendFormActions from './SendFormActions'; import * as SessionStorageActions from './SessionStorageActions'; @@ -95,6 +97,32 @@ export const updateSelectedValues = (prevState: State, action: Action): AsyncAct if (location.state.send && getState().sendForm.currency === "") { dispatch( SendFormActions.init() ); } + + if (location.state.send) { + const rejectedTxs = pending.filter(tx => tx.rejected); + rejectedTxs.forEach(tx => { + dispatch({ + type: NOTIFICATION.ADD, + payload: { + type: "warning", + title: "Pending transaction rejected", + message: `Transaction with id: ${ tx.id } not found.`, + cancelable: true, + actions: [ + { + label: 'OK', + callback: () => { + dispatch({ + type: PENDING.TX_RESOLVED, + tx, + }); + } + } + ] + } + }) + }); + } } } } diff --git a/src/js/components/wallet/account/send/PendingTransactions.js b/src/js/components/wallet/account/send/PendingTransactions.js index d8dee0ca..e3729313 100644 --- a/src/js/components/wallet/account/send/PendingTransactions.js +++ b/src/js/components/wallet/account/send/PendingTransactions.js @@ -25,8 +25,7 @@ type Style = { const PendingTransactions = (props: Props) => { - const pending = props.pending; - + const pending = props.pending.filter(tx => !tx.rejected); if (pending.length < 1) return null; const tokens: Array = props.tokens; diff --git a/src/js/reducers/PendingTxReducer.js b/src/js/reducers/PendingTxReducer.js index bb8cebde..bb7f9e6a 100644 --- a/src/js/reducers/PendingTxReducer.js +++ b/src/js/reducers/PendingTxReducer.js @@ -17,6 +17,7 @@ export type PendingTx = { +tx: any; +nonce: number; +address: string; + rejected: boolean; } export type State = Array; @@ -34,6 +35,7 @@ const add = (state: State, action: SendTxAction): State => { tx: action.tx, nonce: action.nonce, address: action.account.address, + rejected: false, }); return newState; } @@ -42,6 +44,15 @@ const remove = (state: State, id: string): State => { return state.filter(tx => tx.id !== id); } +const reject = (state: State, id: string): State => { + return state.map(tx => { + if (tx.id === id && !tx.rejected) { + return { ...tx, rejected: true }; + } + return tx; + }); +} + export default function pending(state: State = initialState, action: Action): State { switch (action.type) { @@ -50,8 +61,9 @@ export default function pending(state: State = initialState, action: Action): St return add(state, action); case PENDING.TX_RESOLVED : - case PENDING.TX_NOT_FOUND : return remove(state, action.tx.id); + case PENDING.TX_NOT_FOUND : + return reject(state, action.tx.id); case PENDING.FROM_STORAGE : return action.payload; diff --git a/src/js/reducers/utils/index.js b/src/js/reducers/utils/index.js index cc708b9a..2fcb5602 100644 --- a/src/js/reducers/utils/index.js +++ b/src/js/reducers/utils/index.js @@ -93,13 +93,14 @@ export const getAccountPendingTx = (pending: Array, account: ?Account export const getPendingNonce = (pending: Array): number => { return pending.reduce((value: number, tx: PendingTx) => { + if (tx.rejected) return value; return Math.max(value, tx.nonce); }, 0); } export const getPendingAmount = (pending: Array, currency: string): BigNumber => { return pending.reduce((value: BigNumber, tx: PendingTx) => { - if (tx.currency === currency) { + if (tx.currency === currency && !tx.rejected) { return new BigNumber(value).plus(tx.total); } return value;