mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-25 02:20:24 +00:00
9ee30b957d
* Move address messages to config folder, add some other messages for common pitfalls. * Fix checksum vs lowercase issues. * Use gas limit if an address message specified one. Allow messages to have a custom severity. Add a function for getting message to reduce complexity. * Handle address message gas limit on all actions, make separate saga fn. * Apparently I used the wrong takeEvery?
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { getTo, getValue } from './fields';
|
|
import { getUnit, getTokenTo, getTokenValue } from './meta';
|
|
import { AppState } from 'reducers';
|
|
import { isEtherUnit, TokenValue, Wei, Address } from 'libs/units';
|
|
import { gasPriceValidator, gasLimitValidator } from 'libs/validators';
|
|
import { getDataExists, getGasPrice, getGasLimit } from 'selectors/transaction';
|
|
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 = isEtherUnit(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
|
|
};
|