James Prado aabcd3f7a3 Use Network Symbol in Confirmation Modal (#1039)
* Set default unit to 'ETH' instead of 'ether'

* Use 'isEtherUnit()' everywhere

* Set default unit to empty string

* Update isEthUnit to isNetworkUnit

* Fix unit conversion for non-ethereum networks

* Set default network unit properly

* Fix tests

* fix typos

* Update isNetworkUnit selector

* Update isNetworkUnit

* Fix validationhelpers tests

* Add mock state to tests & Move isNetworkUnit to selectors

* Fix validation helper spec

* fix unit swap spec
2018-03-01 19:24:14 -06:00

63 lines
1.8 KiB
TypeScript

import { getTo, getValue } from './fields';
import { getUnit, getTokenTo, getTokenValue } from './meta';
import { AppState } from 'reducers';
import { TokenValue, Wei, Address } from 'libs/units';
import { gasPriceValidator, gasLimitValidator } from 'libs/validators';
import { getDataExists, getGasPrice, getGasLimit } from 'selectors/transaction';
import { isNetworkUnit } from 'selectors/config';
import { getAddressMessage, AddressMessage } from 'config';
interface ICurrentValue {
raw: string;
value: TokenValue | Wei | null;
}
interface ICurrentTo {
raw: string;
value: Address | null;
}
const isEtherTransaction = (state: AppState) => {
const unit = getUnit(state);
const etherUnit = isNetworkUnit(state, unit);
return etherUnit;
};
const getCurrentTo = (state: AppState): ICurrentTo =>
isEtherTransaction(state) ? getTo(state) : getTokenTo(state);
const getCurrentValue = (state: AppState): ICurrentValue =>
isEtherTransaction(state) ? getValue(state) : getTokenValue(state);
const isValidCurrentTo = (state: AppState) => {
const currentTo = getCurrentTo(state);
const dataExists = getDataExists(state);
if (isEtherTransaction(state)) {
// if data exists the address can be 0x
return !!currentTo.value || dataExists;
} else {
return !!currentTo.value;
}
};
const isValidGasPrice = (state: AppState): boolean => gasPriceValidator(getGasPrice(state).raw);
const isValidGasLimit = (state: AppState): boolean => gasLimitValidator(getGasLimit(state).raw);
function getCurrentToAddressMessage(state: AppState): AddressMessage | undefined {
const to = getCurrentTo(state);
return getAddressMessage(to.raw);
}
export {
getCurrentValue,
getCurrentTo,
ICurrentValue,
ICurrentTo,
isEtherTransaction,
isValidCurrentTo,
isValidGasPrice,
isValidGasLimit,
getCurrentToAddressMessage
};