You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-wallet/src/reducers/PendingTxReducer.js

74 lines
1.9 KiB

6 years ago
/* @flow */
import * as PENDING from 'actions/constants/pendingTx';
import * as SEND from 'actions/constants/send';
6 years ago
import type { Action } from 'flowtype';
import type { SendTxAction } from 'actions/SendFormActions';
6 years ago
6 years ago
export type PendingTx = {
6 years ago
+type: 'send' | 'recv';
6 years ago
+id: string;
+network: string;
+currency: string;
6 years ago
+amount: string;
+total: string;
+tx: any;
+nonce: number;
6 years ago
+address: string;
rejected: boolean;
6 years ago
}
6 years ago
export type State = Array<PendingTx>;
const initialState: State = [];
6 years ago
6 years ago
// const add01 = (state: State, action: SendTxAction): State => {
// const newState = [...state];
// newState.push({
// id: action.txid,
// network: action.account.network,
// currency: action.selectedCurrency,
// amount: action.amount,
// total: action.total,
// tx: action.tx,
// nonce: action.nonce,
// address: action.account.address,
// rejected: false,
// });
// return newState;
// };
const add = (state: State, payload: any): State => {
const newState = [...state];
6 years ago
newState.push(payload);
6 years ago
return newState;
};
6 years ago
const remove = (state: State, id: string): State => state.filter(tx => tx.id !== id);
6 years ago
const reject = (state: State, id: string): State => state.map((tx) => {
if (tx.id === id && !tx.rejected) {
return { ...tx, rejected: true };
}
return tx;
});
6 years ago
export default function pending(state: State = initialState, action: Action): State {
6 years ago
switch (action.type) {
6 years ago
// case SEND.TX_COMPLETE:
// return add(state, action);
6 years ago
6 years ago
case PENDING.ADD:
return add(state, action.payload);
case PENDING.TX_RESOLVED:
return remove(state, action.tx.id);
case PENDING.TX_NOT_FOUND:
return reject(state, action.tx.id);
6 years ago
case PENDING.FROM_STORAGE:
6 years ago
return action.payload;
default:
return state;
}
}