separate clear from init function

pull/336/head
slowbackspace 5 years ago
parent c77cd10f03
commit a8d39d95c2

@ -18,19 +18,17 @@ import * as EthereumSendFormActions from './ethereum/SendFormActions';
import * as RippleSendFormActions from './ripple/SendFormActions';
export type SendFormAction = {
type: typeof SEND.INIT | typeof SEND.VALIDATION | typeof SEND.CHANGE,
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,
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,
} | {
type: typeof SEND.CLEAR,
};

@ -53,13 +53,6 @@ export const observe = (prevState: ReducersState, action: Action): ThunkAction =
return;
}
// clear transaction draft from session storage and reinitialize send form
if (action.type === SEND.CLEAR) {
dispatch(SessionStorageActions.clear());
dispatch(init());
return;
}
// if send form was not initialized
if (currentState.sendFormEthereum.currency === '') {
dispatch(init());
@ -116,8 +109,6 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
network,
} = getState().selectedAccount;
const { advanced } = getState().sendFormEthereum;
if (!account || !network) return;
const stateFromStorage = dispatch(SessionStorageActions.loadEthereumDraftTransaction());
@ -149,7 +140,6 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
recommendedGasPrice: gasPrice.toString(),
gasLimit,
gasPrice: gasPrice.toString(),
advanced,
},
});
};
@ -165,10 +155,37 @@ export const toggleAdvanced = (): Action => ({
/*
* Called from UI from "clear" button
*/
export const onClear = (): Action => ({
type: SEND.CLEAR,
networkType: 'ethereum',
});
export const onClear = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const { network } = getState().selectedAccount;
const { advanced } = getState().sendFormEthereum;
if (!network) return;
// clear transaction draft from session storage
dispatch(SessionStorageActions.clear());
const gasPrice: BigNumber = await dispatch(BlockchainActions.getGasPrice(network.shortcut, network.defaultGasPrice));
const gasLimit = network.defaultGasLimit.toString();
const feeLevels = ValidationActions.getFeeLevels(network.symbol, gasPrice, gasLimit);
const selectedFeeLevel = ValidationActions.getSelectedFeeLevel(feeLevels, initialState.selectedFeeLevel);
dispatch({
type: SEND.CLEAR,
networkType: 'ethereum',
state: {
...initialState,
networkName: network.shortcut,
networkSymbol: network.symbol,
currency: network.symbol,
feeLevels,
selectedFeeLevel,
recommendedGasPrice: gasPrice.toString(),
gasLimit,
gasPrice: gasPrice.toString(),
advanced,
},
});
};
/*
* Called from UI on "address" field change

@ -35,13 +35,6 @@ export const observe = (prevState: ReducersState, action: Action): ThunkAction =
return;
}
// clear transaction draft from session storage and reinitialize send form
if (action.type === SEND.CLEAR) {
dispatch(SessionStorageActions.clear());
dispatch(init());
return;
}
// if send form was not initialized
if (currentState.sendFormRipple.networkSymbol === '') {
dispatch(init());
@ -87,8 +80,6 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
network,
} = getState().selectedAccount;
const { advanced } = getState().sendFormEthereum;
if (!account || account.networkType !== 'ripple' || !network) return;
const stateFromStorage = dispatch(SessionStorageActions.loadRippleDraftTransaction());
@ -116,7 +107,6 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
selectedFeeLevel,
fee: network.fee.defaultFee,
sequence: '1',
advanced,
},
});
};
@ -132,11 +122,34 @@ export const toggleAdvanced = (): Action => ({
/*
* Called from UI from "clear" button
*/
export const onClear = (): Action => ({
type: SEND.CLEAR,
networkType: 'ripple',
});
export const onClear = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const { network } = getState().selectedAccount;
const { advanced } = getState().sendFormRipple;
if (!network) return;
// clear transaction draft from session storage
dispatch(SessionStorageActions.clear());
const blockchainFeeLevels = dispatch(BlockchainActions.getFeeLevels(network));
const feeLevels = dispatch(ValidationActions.getFeeLevels(blockchainFeeLevels));
const selectedFeeLevel = ValidationActions.getSelectedFeeLevel(feeLevels, initialState.selectedFeeLevel);
dispatch({
type: SEND.CLEAR,
networkType: 'ripple',
state: {
...initialState,
networkName: network.shortcut,
networkSymbol: network.symbol,
feeLevels,
selectedFeeLevel,
fee: network.fee.defaultFee,
sequence: '1',
advanced,
},
});
};
/*
* Called from UI on "address" field change

@ -82,6 +82,7 @@ export default (state: State = initialState, action: Action): State => {
case SEND.INIT:
case SEND.CHANGE:
case SEND.VALIDATION:
case SEND.CLEAR:
return action.state;
case SEND.TOGGLE_ADVANCED:

@ -75,6 +75,7 @@ export default (state: State = initialState, action: Action): State => {
case SEND.INIT:
case SEND.CHANGE:
case SEND.VALIDATION:
case SEND.CLEAR:
return action.state;
case SEND.TOGGLE_ADVANCED:

Loading…
Cancel
Save