1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-15 21:08:57 +00:00
trezor-wallet/src/actions/SendFormActions.js

68 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-12-13 11:01:37 +00:00
/* @flow */
import * as ACCOUNT from 'actions/constants/account';
2018-08-14 13:18:16 +00:00
import * as SEND from 'actions/constants/send';
2018-09-22 16:49:05 +00:00
import * as WEB3 from 'actions/constants/web3';
import * as BLOCKCHAIN from 'actions/constants/blockchain';
2018-04-16 21:19:50 +00:00
2018-07-30 10:52:13 +00:00
import type {
2018-04-16 21:19:50 +00:00
Dispatch,
GetState,
2018-09-22 16:49:05 +00:00
State as ReducersState,
2018-04-16 21:19:50 +00:00
Action,
2018-05-02 09:01:08 +00:00
ThunkAction,
2018-08-14 12:56:47 +00:00
} from 'flowtype';
2018-11-29 20:02:56 +00:00
import type { State as EthereumState } from 'reducers/SendFormEthereumReducer';
import type { State as RippleState } from 'reducers/SendFormRippleReducer';
import * as EthereumSendFormActions from './ethereum/SendFormActions';
import * as RippleSendFormActions from './ripple/SendFormActions';
2018-04-16 21:19:50 +00:00
2018-09-22 16:49:05 +00:00
export type SendFormAction = {
2019-01-15 14:24:41 +00:00
type: typeof SEND.INIT | typeof SEND.VALIDATION | typeof SEND.CHANGE | typeof SEND.CLEAR,
2018-11-29 20:02:56 +00:00
networkType: 'ethereum',
state: EthereumState,
} | {
2019-01-15 14:24:41 +00:00
type: typeof SEND.INIT | typeof SEND.VALIDATION | typeof SEND.CHANGE | typeof SEND.CLEAR,
2018-11-29 20:02:56 +00:00
networkType: 'ripple',
state: RippleState,
2018-04-16 21:19:50 +00:00
} | {
2018-09-22 16:49:05 +00:00
type: typeof SEND.TOGGLE_ADVANCED | typeof SEND.TX_SENDING | typeof SEND.TX_ERROR,
} | {
type: typeof SEND.TX_COMPLETE,
};
2018-09-22 16:49:05 +00:00
2018-11-29 20:02:56 +00:00
// list of all actions which has influence on "sendForm" reducer
// other actions will be ignored
const actions = [
ACCOUNT.UPDATE_SELECTED_ACCOUNT,
WEB3.GAS_PRICE_UPDATED,
BLOCKCHAIN.UPDATE_FEE,
...Object.values(SEND).filter(v => typeof v === 'string'),
];
2018-09-22 16:49:05 +00:00
/*
* Called from WalletService
2018-09-22 16:49:05 +00:00
*/
export const observe = (prevState: ReducersState, action: Action): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
// ignore not listed actions
if (actions.indexOf(action.type) < 0) return;
2018-09-22 16:49:05 +00:00
const currentState = getState();
// do not proceed if it's not "send" url
if (!currentState.router.location.state.send) return;
2018-11-29 20:02:56 +00:00
const { network } = currentState.selectedAccount;
2018-11-17 16:29:28 +00:00
if (!network) return;
2018-11-29 20:02:56 +00:00
switch (network.type) {
case 'ethereum':
dispatch(EthereumSendFormActions.observe(prevState, action));
break;
case 'ripple':
dispatch(RippleSendFormActions.observe(prevState, action));
break;
default: break;
2017-12-13 11:01:37 +00:00
}
2018-07-30 10:52:13 +00:00
};