2017-12-13 11:01:37 +00:00
|
|
|
/* @flow */
|
2018-10-01 09:59:31 +00:00
|
|
|
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';
|
2018-12-28 15:02:50 +00:00
|
|
|
import * as BLOCKCHAIN from 'actions/constants/blockchain';
|
2018-04-16 21:19:50 +00:00
|
|
|
|
2019-03-04 12:33:02 +00:00
|
|
|
import type { Dispatch, GetState, State as ReducersState, Action, ThunkAction } 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
|
|
|
|
2019-03-04 12:33:02 +00:00
|
|
|
export type SendFormAction =
|
|
|
|
| {
|
|
|
|
type: typeof SEND.INIT | typeof SEND.VALIDATION | typeof SEND.CHANGE | typeof SEND.CLEAR,
|
|
|
|
networkType: 'ethereum',
|
|
|
|
state: EthereumState,
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
type: typeof SEND.INIT | typeof SEND.VALIDATION | typeof SEND.CHANGE | typeof SEND.CLEAR,
|
|
|
|
networkType: 'ripple',
|
|
|
|
state: RippleState,
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
type: typeof SEND.TOGGLE_ADVANCED | typeof SEND.TX_SENDING | typeof SEND.TX_ERROR,
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
type: typeof SEND.TX_COMPLETE,
|
|
|
|
};
|
2018-11-29 20:02:56 +00:00
|
|
|
|
2018-10-01 09:59:31 +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,
|
2018-12-28 15:02:50 +00:00
|
|
|
BLOCKCHAIN.UPDATE_FEE,
|
2018-10-01 09:59:31 +00:00
|
|
|
...Object.values(SEND).filter(v => typeof v === 'string'),
|
|
|
|
];
|
|
|
|
|
2018-09-22 16:49:05 +00:00
|
|
|
/*
|
2019-03-04 12:33:02 +00:00
|
|
|
* Called from WalletService
|
|
|
|
*/
|
|
|
|
export const observe = (prevState: ReducersState, action: Action): ThunkAction => (
|
|
|
|
dispatch: Dispatch,
|
|
|
|
getState: GetState
|
|
|
|
): void => {
|
2018-10-01 09:59:31 +00:00
|
|
|
// 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;
|
2019-03-04 12:33:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
2017-12-13 11:01:37 +00:00
|
|
|
}
|
2018-07-30 10:52:13 +00:00
|
|
|
};
|