43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { AppState } from 'reducers';
|
|
import { getTransactionState, getGasCost } from 'selectors/transaction';
|
|
import { getEtherBalance } from 'selectors/wallet';
|
|
import { getOffline } from 'selectors/config';
|
|
|
|
const getFields = (state: AppState) => getTransactionState(state).fields;
|
|
const getTo = (state: AppState) => getFields(state).to;
|
|
const getData = (state: AppState) => getFields(state).data;
|
|
const getGasLimit = (state: AppState) => getFields(state).gasLimit;
|
|
const getGasPrice = (state: AppState) => getFields(state).gasPrice;
|
|
const getValue = (state: AppState) => getFields(state).value;
|
|
const getNonce = (state: AppState) => getFields(state).nonce;
|
|
|
|
const getDataExists = (state: AppState) => {
|
|
const { value } = getData(state);
|
|
return !!value && value.length > 0;
|
|
};
|
|
|
|
const getValidGasCost = (state: AppState) => {
|
|
const gasCost = getGasCost(state);
|
|
const etherBalance = getEtherBalance(state);
|
|
const isOffline = getOffline(state);
|
|
if (isOffline || !etherBalance) {
|
|
return true;
|
|
}
|
|
return gasCost.lte(etherBalance);
|
|
};
|
|
|
|
const getToRaw = (state: AppState) => getTo(state).raw;
|
|
|
|
export {
|
|
getData,
|
|
getFields,
|
|
getGasLimit,
|
|
getValue,
|
|
getTo,
|
|
getToRaw,
|
|
getNonce,
|
|
getGasPrice,
|
|
getDataExists,
|
|
getValidGasCost
|
|
};
|