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 {
|
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 getGasLimit(state) {
|
2021-06-10 19:53:15 +02:00
|
|
|
return state.send.gasLimit || '0';
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getGasPrice(state) {
|
2021-06-10 19:53:15 +02:00
|
|
|
return state.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-06-10 19:53:15 +02:00
|
|
|
return state.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-06-10 19:53:15 +02:00
|
|
|
return state.send.amount;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendHexData(state) {
|
2021-06-10 19:53:15 +02:00
|
|
|
return state.send.data;
|
2018-07-17 00:50:26 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendEditingTransactionId(state) {
|
2021-06-10 19:53:15 +02:00
|
|
|
return state.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-06-10 19:53:15 +02:00
|
|
|
return state.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-06-10 19:53:15 +02:00
|
|
|
return state.send.maxModeOn;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendTo(state) {
|
2021-06-10 19:53:15 +02:00
|
|
|
return state.send.to;
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendToNickname(state) {
|
2021-06-10 19:53:15 +02:00
|
|
|
return state.send.toNickname;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getTokenBalance(state) {
|
2021-06-10 19:53:15 +02:00
|
|
|
return state.send.tokenBalance;
|
2018-04-27 02:38:14 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendEnsResolution(state) {
|
2021-06-10 19:53:15 +02:00
|
|
|
return state.send.ensResolution;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendEnsResolutionError(state) {
|
2021-06-10 19:53:15 +02:00
|
|
|
return state.send.ensResolutionError;
|
2019-07-31 21:56:44 +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-03-19 18:12:11 +01:00
|
|
|
return 'send';
|
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
|
|
|
}
|