pendingTx rejected state

pull/2/merge
Szymon Lesisz 6 years ago
parent b41e6bacc0
commit 148a61645f

@ -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,

@ -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,
});
}
}
]
}
})
});
}
}
}
}

@ -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<Token> = props.tokens;

@ -17,6 +17,7 @@ export type PendingTx = {
+tx: any;
+nonce: number;
+address: string;
rejected: boolean;
}
export type State = Array<PendingTx>;
@ -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;

@ -93,13 +93,14 @@ export const getAccountPendingTx = (pending: Array<PendingTx>, account: ?Account
export const getPendingNonce = (pending: Array<PendingTx>): 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<PendingTx>, 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;

Loading…
Cancel
Save