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/js/reducers/PendingTxReducer.js

56 lines
1.3 KiB

6 years ago
/* @flow */
'use strict';
6 years ago
import * as PENDING from '../actions/constants/pendingTx';
import * as SEND from '../actions/constants/send';
import * as WEB3 from '../actions/constants/web3';
6 years ago
import type { Action } from '~/flowtype';
import type { SendTxAction } from '../actions/SendFormActions';
6 years ago
6 years ago
export type PendingTx = {
+id: string;
+network: string;
+currency: string;
6 years ago
+amount: string;
+address: string;
}
6 years ago
export type State = Array<PendingTx>;
const initialState: State = [];
6 years ago
const add = (state: State, action: SendTxAction): State => {
6 years ago
const newState = [ ...state ];
newState.push({
id: action.txid,
network: action.account.network,
currency: action.selectedCurrency,
6 years ago
amount: action.amount,
address: action.account.address,
6 years ago
});
return newState;
}
const remove = (state: State, id: string): State => {
return state.filter(tx => tx.id !== id);
6 years ago
}
6 years ago
export default function pending(state: State = initialState, action: Action): State {
6 years ago
switch (action.type) {
case SEND.TX_COMPLETE :
return add(state, action);
6 years ago
case PENDING.TX_RESOLVED :
return remove(state, action.tx.id);
6 years ago
6 years ago
case PENDING.FROM_STORAGE :
6 years ago
return action.payload;
default:
return state;
}
}