HenryNguyen5 12d29e5b94 RC Bugfixes (#1644)
* Fix #1569

* Use common component for handling "to" address

* If to address becomes invalid, hide contract interact explorer

* Add IS_CONTRACT_INTERACTION mode - fix bugs related to contract interact

* Bump shepherd version to fix bugs related to metamask + network switches

* Update mycrypto link downloads

* Update facebook link

* Remove console log from checktx

* Fix dollar sign on contract address in conf modal

* Fix unchecksummed address for metamask signing

* Cleanup unused classname

* Update generate keystore file description to be correct

* Add space to create new wallet banner

* Remove extra variable

* Do checksumming in library function instead of component

* Clear state on address change
2018-04-23 18:35:24 -05:00

78 lines
2.3 KiB
TypeScript

import { State, RequestStatus } from './typings';
import {
TypeKeys as TK,
ResetTransactionSuccessfulAction,
NetworkAction,
InputGasPriceAction,
InputGasPriceIntentAction
} from 'actions/transaction';
import { Action } from 'redux';
const INITIAL_STATE: State = {
gasEstimationStatus: null,
getFromStatus: null,
getNonceStatus: null,
gasPriceStatus: null
};
const getPostFix = (str: string): keyof typeof RequestStatus => {
const arr = str.split('_');
return arr[arr.length - 1] as any;
};
const nextState = (field: keyof State) => (state: State, action: Action): State => ({
...state,
[field]: RequestStatus[getPostFix(action.type)]
});
const setGasPriceStatus = (state: State, gasPriceStatus: RequestStatus) => ({
...state,
gasPriceStatus
});
const reset = () => INITIAL_STATE;
export const network = (
state: State = INITIAL_STATE,
action:
| NetworkAction
| ResetTransactionSuccessfulAction
| InputGasPriceAction
| InputGasPriceIntentAction
) => {
switch (action.type) {
case TK.ESTIMATE_GAS_REQUESTED:
return nextState('gasEstimationStatus')(state, action);
case TK.ESTIMATE_GAS_FAILED:
return nextState('gasEstimationStatus')(state, action);
case TK.ESTIMATE_GAS_TIMEDOUT:
return nextState('gasEstimationStatus')(state, action);
case TK.ESTIMATE_GAS_SUCCEEDED:
return nextState('gasEstimationStatus')(state, action);
case TK.GET_FROM_REQUESTED:
return nextState('getFromStatus')(state, action);
case TK.GET_FROM_SUCCEEDED:
return nextState('getFromStatus')(state, action);
case TK.GET_FROM_FAILED:
return nextState('getFromStatus')(state, action);
case TK.GET_NONCE_REQUESTED:
return nextState('getNonceStatus')(state, action);
case TK.GET_NONCE_SUCCEEDED:
return nextState('getNonceStatus')(state, action);
case TK.GET_NONCE_FAILED:
return nextState('getNonceStatus')(state, action);
// Not exactly "network" requests, but we want to show pending while
// gas price is subject to change
case TK.GAS_PRICE_INPUT_INTENT:
return setGasPriceStatus(state, RequestStatus.REQUESTED);
case TK.GAS_PRICE_INPUT:
return setGasPriceStatus(state, RequestStatus.SUCCEEDED);
case TK.RESET_SUCCESSFUL:
return reset();
default:
return state;
}
};