1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-28 03:08:30 +00:00

pendingTx rejected state

This commit is contained in:
Szymon Lesisz 2018-05-29 10:48:28 +02:00
parent b41e6bacc0
commit 148a61645f
5 changed files with 45 additions and 5 deletions

View File

@ -10,7 +10,7 @@ export type PendingTxAction = {
} | { } | {
type: typeof PENDING.TX_RESOLVED, type: typeof PENDING.TX_RESOLVED,
tx: PendingTx, tx: PendingTx,
receipt: Object, receipt?: Object,
} | { } | {
type: typeof PENDING.TX_NOT_FOUND, type: typeof PENDING.TX_NOT_FOUND,
tx: PendingTx, tx: PendingTx,

View File

@ -4,6 +4,8 @@
import { LOCATION_CHANGE } from 'react-router-redux'; import { LOCATION_CHANGE } from 'react-router-redux';
import * as ACCOUNT from './constants/account'; import * as ACCOUNT from './constants/account';
import * as SEND from './constants/send'; 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 SendFormActions from './SendFormActions';
import * as SessionStorageActions from './SessionStorageActions'; import * as SessionStorageActions from './SessionStorageActions';
@ -95,6 +97,32 @@ export const updateSelectedValues = (prevState: State, action: Action): AsyncAct
if (location.state.send && getState().sendForm.currency === "") { if (location.state.send && getState().sendForm.currency === "") {
dispatch( SendFormActions.init() ); 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,
});
}
}
]
}
})
});
}
} }
} }
} }

View File

@ -25,8 +25,7 @@ type Style = {
const PendingTransactions = (props: Props) => { const PendingTransactions = (props: Props) => {
const pending = props.pending; const pending = props.pending.filter(tx => !tx.rejected);
if (pending.length < 1) return null; if (pending.length < 1) return null;
const tokens: Array<Token> = props.tokens; const tokens: Array<Token> = props.tokens;

View File

@ -17,6 +17,7 @@ export type PendingTx = {
+tx: any; +tx: any;
+nonce: number; +nonce: number;
+address: string; +address: string;
rejected: boolean;
} }
export type State = Array<PendingTx>; export type State = Array<PendingTx>;
@ -34,6 +35,7 @@ const add = (state: State, action: SendTxAction): State => {
tx: action.tx, tx: action.tx,
nonce: action.nonce, nonce: action.nonce,
address: action.account.address, address: action.account.address,
rejected: false,
}); });
return newState; return newState;
} }
@ -42,6 +44,15 @@ const remove = (state: State, id: string): State => {
return state.filter(tx => tx.id !== id); 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 { export default function pending(state: State = initialState, action: Action): State {
switch (action.type) { switch (action.type) {
@ -50,8 +61,9 @@ export default function pending(state: State = initialState, action: Action): St
return add(state, action); return add(state, action);
case PENDING.TX_RESOLVED : case PENDING.TX_RESOLVED :
case PENDING.TX_NOT_FOUND :
return remove(state, action.tx.id); return remove(state, action.tx.id);
case PENDING.TX_NOT_FOUND :
return reject(state, action.tx.id);
case PENDING.FROM_STORAGE : case PENDING.FROM_STORAGE :
return action.payload; return action.payload;

View File

@ -93,13 +93,14 @@ export const getAccountPendingTx = (pending: Array<PendingTx>, account: ?Account
export const getPendingNonce = (pending: Array<PendingTx>): number => { export const getPendingNonce = (pending: Array<PendingTx>): number => {
return pending.reduce((value: number, tx: PendingTx) => { return pending.reduce((value: number, tx: PendingTx) => {
if (tx.rejected) return value;
return Math.max(value, tx.nonce); return Math.max(value, tx.nonce);
}, 0); }, 0);
} }
export const getPendingAmount = (pending: Array<PendingTx>, currency: string): BigNumber => { export const getPendingAmount = (pending: Array<PendingTx>, currency: string): BigNumber => {
return pending.reduce((value: BigNumber, tx: PendingTx) => { 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 new BigNumber(value).plus(tx.total);
} }
return value; return value;