2020-01-09 04:34:58 +01:00
|
|
|
import abi from 'human-standard-token-abi'
|
2020-08-18 21:18:25 +02:00
|
|
|
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,
|
2020-05-04 20:27:14 +02:00
|
|
|
} from '.'
|
2018-04-07 00:29:51 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getBlockGasLimit(state) {
|
2018-05-22 17:16:53 +02:00
|
|
|
return state.metamask.currentBlockGasLimit
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getConversionRate(state) {
|
2018-04-07 00:29:51 +02:00
|
|
|
return state.metamask.conversionRate
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getNativeCurrency(state) {
|
2018-10-26 10:26:43 +02:00
|
|
|
return state.metamask.nativeCurrency
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getCurrentNetwork(state) {
|
2018-04-27 02:38:14 +02: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) {
|
2018-09-13 10:47:05 +02: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) {
|
2019-08-26 19:30:39 +02: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) {
|
2018-09-13 10:47:05 +02: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) {
|
2020-05-29 19:46:10 +02: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) {
|
2020-05-29 19:46:10 +02:00
|
|
|
return state.metamask.send.token
|
|
|
|
}
|
2018-04-27 02:38:14 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendTokenAddress(state) {
|
2020-05-29 19:46:10 +02: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) {
|
2020-05-29 19:46:10 +02:00
|
|
|
const sendTokenAddress = getSendTokenAddress(state)
|
2020-11-03 00:41:28 +01:00
|
|
|
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) {
|
2018-04-27 02:38:14 +02: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) {
|
2018-07-17 00:50:26 +02:00
|
|
|
return state.metamask.send.data
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendHexDataFeatureFlagState(state) {
|
2018-08-16 09:43:13 +02:00
|
|
|
return state.metamask.featureFlags.sendHexData
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendEditingTransactionId(state) {
|
2018-04-27 02:38:14 +02:00
|
|
|
return state.metamask.send.editingTransactionId
|
|
|
|
}
|
2018-04-07 00:29:51 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendErrors(state) {
|
2018-04-27 21:03:00 +02: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) {
|
2020-05-04 17:22:34 +02:00
|
|
|
return Boolean(state.send.errors.amount)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendFrom(state) {
|
2018-04-27 02:38:14 +02: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) {
|
2020-03-11 19:40:35 +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) {
|
2020-03-11 19:40:35 +01:00
|
|
|
const fromAddress = getSendFrom(state)
|
|
|
|
return fromAddress
|
|
|
|
? getTargetAccount(state, fromAddress)
|
|
|
|
: getSelectedAccount(state)
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendMaxModeState(state) {
|
2018-04-27 02:38:14 +02: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) {
|
2018-04-07 00:29:51 +02:00
|
|
|
return state.metamask.send.to
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendToNickname(state) {
|
2019-07-31 21:56:44 +02:00
|
|
|
return state.metamask.send.toNickname
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendToAccounts(state) {
|
2018-04-07 00:29:51 +02:00
|
|
|
const fromAccounts = accountsWithSendEtherInfoSelector(state)
|
|
|
|
const addressBookAccounts = getAddressBook(state)
|
2019-04-12 02:03:33 +02:00
|
|
|
return [...fromAccounts, ...addressBookAccounts]
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getTokenBalance(state) {
|
2018-04-27 02:38:14 +02:00
|
|
|
return state.metamask.send.tokenBalance
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendEnsResolution(state) {
|
2019-07-31 21:56:44 +02:00
|
|
|
return state.metamask.send.ensResolution
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSendEnsResolutionError(state) {
|
2019-07-31 21:56:44 +02:00
|
|
|
return state.metamask.send.ensResolutionError
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getUnapprovedTxs(state) {
|
2018-04-27 02:38:14 +02: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) {
|
2018-07-25 02:32:20 +02: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) {
|
2020-05-04 17:22:34 +02:00
|
|
|
return state.send.errors.gasLoading
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function gasFeeIsInError(state) {
|
2020-05-04 17:22:34 +02:00
|
|
|
return Boolean(state.send.errors.gasFee)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getGasButtonGroupShown(state) {
|
2020-05-04 17:22:34 +02:00
|
|
|
return state.send.gasButtonGroupShown
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getTitleKey(state) {
|
2020-05-04 17:22:34 +02:00
|
|
|
const isEditing = Boolean(getSendEditingTransactionId(state))
|
2020-05-29 19:46:10 +02:00
|
|
|
const isToken = Boolean(getSendToken(state))
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
if (!getSendTo(state)) {
|
|
|
|
return 'addRecipient'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isEditing) {
|
|
|
|
return 'edit'
|
|
|
|
} else if (isToken) {
|
|
|
|
return 'sendTokens'
|
|
|
|
}
|
2020-08-19 18:27:05 +02:00
|
|
|
return 'sendETH'
|
2020-05-04 17:22:34 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function isSendFormInError(state) {
|
2020-05-04 17:22:34 +02:00
|
|
|
return Object.values(getSendErrors(state)).some((n) => n)
|
|
|
|
}
|