2021-02-04 19:15:23 +01:00
|
|
|
import abi from 'human-standard-token-abi';
|
|
|
|
import { calcGasTotal } from '../pages/send/send.utils';
|
2020-03-06 22:34:56 +01:00
|
|
|
import {
|
|
|
|
accountsWithSendEtherInfoSelector,
|
|
|
|
getAddressBook,
|
2020-03-11 19:40:35 +01:00
|
|
|
getSelectedAccount,
|
|
|
|
getTargetAccount,
|
2019-08-26 19:30:39 +02:00
|
|
|
getAveragePriceEstimateInHexWEI,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '.';
|
2018-04-07 00:29:51 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getBlockGasLimit(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.currentBlockGasLimit;
|
2018-05-22 17:16:53 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getConversionRate(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.conversionRate;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getNativeCurrency(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.nativeCurrency;
|
2018-10-26 10:26:43 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getCurrentNetwork(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.network;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getGasLimit(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.gasLimit || '0';
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getGasPrice(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.gasPrice || getAveragePriceEstimateInHexWEI(state);
|
2018-05-05 17:11:53 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getGasTotal(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return calcGasTotal(getGasLimit(state), getGasPrice(state));
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getPrimaryCurrency(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const sendToken = getSendToken(state);
|
|
|
|
return sendToken?.symbol;
|
2018-04-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendToken(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.token;
|
2020-05-29 19:46:10 +02:00
|
|
|
}
|
2018-04-27 02:38:14 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendTokenAddress(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return getSendToken(state)?.address;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendTokenContract(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const sendTokenAddress = getSendTokenAddress(state);
|
|
|
|
return sendTokenAddress
|
|
|
|
? global.eth.contract(abi).at(sendTokenAddress)
|
|
|
|
: null;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendAmount(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.amount;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendHexData(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.data;
|
2018-07-17 00:50:26 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendHexDataFeatureFlagState(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.featureFlags.sendHexData;
|
2018-08-16 09:43:13 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendEditingTransactionId(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.editingTransactionId;
|
2018-04-27 02:38:14 +02:00
|
|
|
}
|
2018-04-07 00:29:51 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendErrors(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.send.errors;
|
2018-04-27 02:38:14 +02:00
|
|
|
}
|
2018-04-07 00:29:51 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function sendAmountIsInError(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return Boolean(state.send.errors.amount);
|
2020-05-04 17:22:34 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendFrom(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.from;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendFromBalance(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const fromAccount = getSendFromObject(state);
|
|
|
|
return fromAccount.balance;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendFromObject(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const fromAddress = getSendFrom(state);
|
2020-03-11 19:40:35 +01:00
|
|
|
return fromAddress
|
|
|
|
? getTargetAccount(state, fromAddress)
|
2021-02-04 19:15:23 +01:00
|
|
|
: getSelectedAccount(state);
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendMaxModeState(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.maxModeOn;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendTo(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.to;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendToNickname(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.toNickname;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendToAccounts(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const fromAccounts = accountsWithSendEtherInfoSelector(state);
|
|
|
|
const addressBookAccounts = getAddressBook(state);
|
|
|
|
return [...fromAccounts, ...addressBookAccounts];
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getTokenBalance(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.tokenBalance;
|
2018-04-27 02:38:14 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendEnsResolution(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.ensResolution;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendEnsResolutionError(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.send.ensResolutionError;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getUnapprovedTxs(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.metamask.unapprovedTxs;
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getQrCodeData(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.appState.qrCodeData;
|
2018-07-27 02:56:58 +02:00
|
|
|
}
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getGasLoadingError(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.send.errors.gasLoading;
|
2020-05-04 17:22:34 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function gasFeeIsInError(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return Boolean(state.send.errors.gasFee);
|
2020-05-04 17:22:34 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getGasButtonGroupShown(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.send.gasButtonGroupShown;
|
2020-05-04 17:22:34 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getTitleKey(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const isEditing = Boolean(getSendEditingTransactionId(state));
|
|
|
|
const isToken = Boolean(getSendToken(state));
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
if (!getSendTo(state)) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'addRecipient';
|
2020-05-04 17:22:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isEditing) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'edit';
|
2020-05-04 17:22:34 +02:00
|
|
|
} else if (isToken) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'sendTokens';
|
2020-05-04 17:22:34 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'sendETH';
|
2020-05-04 17:22:34 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function isSendFormInError(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return Object.values(getSendErrors(state)).some((n) => n);
|
2020-05-04 17:22:34 +02:00
|
|
|
}
|