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/SendFormReducer.js

109 lines
2.3 KiB

7 years ago
/* @flow */
import * as SEND from 'actions/constants/send';
import * as ACCOUNT from 'actions/constants/account';
import type { Action } from 'flowtype';
export type FeeLevel = {
label: string;
gasPrice: string;
value: string;
}
6 years ago
export type State = {
+networkName: string;
+networkSymbol: string;
currency: string;
6 years ago
// form fields
advanced: boolean;
untouched: boolean; // set to true when user made any changes in form
touched: {[k: string]: boolean};
7 years ago
address: string;
6 years ago
amount: string;
setMax: boolean;
feeLevels: Array<FeeLevel>;
selectedFeeLevel: FeeLevel;
6 years ago
recommendedGasPrice: string;
gasPriceNeedsUpdate: boolean;
gasLimit: string;
calculatingGasLimit: boolean;
6 years ago
gasPrice: string;
7 years ago
data: string;
6 years ago
nonce: string;
total: string;
6 years ago
errors: {[k: string]: string};
warnings: {[k: string]: string};
infos: {[k: string]: string};
sending: boolean;
6 years ago
}
export const initialState: State = {
networkName: '',
networkSymbol: '',
currency: '',
6 years ago
advanced: false,
untouched: true,
touched: {},
6 years ago
address: '',
//address: '0x574BbB36871bA6b78E27f4B4dCFb76eA0091880B',
6 years ago
amount: '',
setMax: false,
feeLevels: [],
selectedFeeLevel: {
label: 'Normal',
gasPrice: '0',
value: 'Normal',
},
6 years ago
recommendedGasPrice: '0',
gasPriceNeedsUpdate: false,
gasLimit: '0',
calculatingGasLimit: false,
6 years ago
gasPrice: '0',
data: '',
nonce: '0',
total: '0',
sending: false,
errors: {},
warnings: {},
infos: {},
};
6 years ago
6 years ago
export default (state: State = initialState, action: Action): State => {
7 years ago
switch (action.type) {
case SEND.INIT:
case SEND.CHANGE:
case SEND.VALIDATION:
6 years ago
return action.state;
case ACCOUNT.DISPOSE:
6 years ago
return initialState;
case SEND.TOGGLE_ADVANCED:
7 years ago
return {
...state,
advanced: !state.advanced,
};
7 years ago
case SEND.TX_SENDING:
7 years ago
return {
...state,
6 years ago
sending: true,
};
7 years ago
case SEND.TX_ERROR:
7 years ago
return {
...state,
6 years ago
sending: false,
};
7 years ago
default:
return state;
}
};