2020-01-09 04:34:58 +01:00
|
|
|
import abi from 'human-standard-token-abi'
|
2020-03-06 22:34:56 +01:00
|
|
|
import {
|
|
|
|
accountsWithSendEtherInfoSelector,
|
|
|
|
getAddressBook,
|
2020-03-11 19:40:35 +01:00
|
|
|
getSelectedAccount,
|
|
|
|
getTargetAccount,
|
2020-03-06 22:34:56 +01:00
|
|
|
getSelectedAddress,
|
2019-08-26 19:30:39 +02:00
|
|
|
getAveragePriceEstimateInHexWEI,
|
2020-05-04 20:27:14 +02:00
|
|
|
} from '.'
|
|
|
|
import { estimateGasPriceFromRecentBlocks, calcGasTotal } from '../pages/send/send.utils'
|
2018-04-07 00:29:51 +02:00
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getBlockGasLimit (state) {
|
2018-05-22 17:16:53 +02:00
|
|
|
return state.metamask.currentBlockGasLimit
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getConversionRate (state) {
|
2018-04-07 00:29:51 +02:00
|
|
|
return state.metamask.conversionRate
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getCurrentCurrency (state) {
|
2018-04-27 02:38:14 +02:00
|
|
|
return state.metamask.currentCurrency
|
|
|
|
}
|
2018-04-07 00:29:51 +02:00
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getNativeCurrency (state) {
|
2018-10-26 10:26:43 +02:00
|
|
|
return state.metamask.nativeCurrency
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +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-01-09 04:34:58 +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-01-09 04:34:58 +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-01-09 04:34:58 +01:00
|
|
|
export function getGasPriceFromRecentBlocks (state) {
|
2018-05-22 10:10:06 +02:00
|
|
|
return estimateGasPriceFromRecentBlocks(state.metamask.recentBlocks)
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +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-01-09 04:34:58 +01:00
|
|
|
export function getPrimaryCurrency (state) {
|
2018-04-27 21:03:00 +02:00
|
|
|
const selectedToken = getSelectedToken(state)
|
|
|
|
return selectedToken && selectedToken.symbol
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getRecentBlocks (state) {
|
2018-05-22 10:10:06 +02:00
|
|
|
return state.metamask.recentBlocks
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getSelectedIdentity (state) {
|
2018-04-27 02:38:14 +02:00
|
|
|
const selectedAddress = getSelectedAddress(state)
|
|
|
|
const identities = state.metamask.identities
|
|
|
|
|
|
|
|
return identities[selectedAddress]
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getSelectedToken (state) {
|
2018-04-27 02:38:14 +02:00
|
|
|
const tokens = state.metamask.tokens || []
|
|
|
|
const selectedTokenAddress = state.metamask.selectedTokenAddress
|
|
|
|
const selectedToken = tokens.filter(({ address }) => address === selectedTokenAddress)[0]
|
|
|
|
const sendToken = state.metamask.send.token
|
|
|
|
|
|
|
|
return selectedToken || sendToken || null
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getSelectedTokenContract (state) {
|
2018-04-27 02:38:14 +02:00
|
|
|
const selectedToken = getSelectedToken(state)
|
2018-05-14 14:13:55 +02:00
|
|
|
|
2018-04-27 02:38:14 +02:00
|
|
|
return selectedToken
|
|
|
|
? global.eth.contract(abi).at(selectedToken.address)
|
|
|
|
: null
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +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-01-09 04:34:58 +01:00
|
|
|
export function getSendHexData (state) {
|
2018-07-17 00:50:26 +02:00
|
|
|
return state.metamask.send.data
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getSendHexDataFeatureFlagState (state) {
|
2018-08-16 09:43:13 +02:00
|
|
|
return state.metamask.featureFlags.sendHexData
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +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-01-09 04:34:58 +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-05-04 17:22:34 +02:00
|
|
|
export function sendAmountIsInError (state) {
|
|
|
|
return Boolean(state.send.errors.amount)
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +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-01-09 04:34:58 +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-03-11 19:40:35 +01:00
|
|
|
export function getSendFromObject (state) {
|
|
|
|
const fromAddress = getSendFrom(state)
|
|
|
|
return fromAddress
|
|
|
|
? getTargetAccount(state, fromAddress)
|
|
|
|
: getSelectedAccount(state)
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +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-01-09 04:34:58 +01:00
|
|
|
export function getSendTo (state) {
|
2018-04-07 00:29:51 +02:00
|
|
|
return state.metamask.send.to
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getSendToNickname (state) {
|
2019-07-31 21:56:44 +02:00
|
|
|
return state.metamask.send.toNickname
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +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-01-09 04:34:58 +01:00
|
|
|
export function getTokenBalance (state) {
|
2018-04-27 02:38:14 +02:00
|
|
|
return state.metamask.send.tokenBalance
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getSendEnsResolution (state) {
|
2019-07-31 21:56:44 +02:00
|
|
|
return state.metamask.send.ensResolution
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getSendEnsResolutionError (state) {
|
2019-07-31 21:56:44 +02:00
|
|
|
return state.metamask.send.ensResolutionError
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +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-01-09 04:34:58 +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
|
|
|
|
|
|
|
export function getGasLoadingError (state) {
|
|
|
|
return state.send.errors.gasLoading
|
|
|
|
}
|
|
|
|
|
|
|
|
export function gasFeeIsInError (state) {
|
|
|
|
return Boolean(state.send.errors.gasFee)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getGasButtonGroupShown (state) {
|
|
|
|
return state.send.gasButtonGroupShown
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getTokens (state) {
|
|
|
|
return state.metamask.tokens
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getTitleKey (state) {
|
|
|
|
const isEditing = Boolean(getSendEditingTransactionId(state))
|
|
|
|
const isToken = Boolean(getSelectedToken(state))
|
|
|
|
|
|
|
|
if (!getSendTo(state)) {
|
|
|
|
return 'addRecipient'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isEditing) {
|
|
|
|
return 'edit'
|
|
|
|
} else if (isToken) {
|
|
|
|
return 'sendTokens'
|
|
|
|
} else {
|
|
|
|
return 'sendETH'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isSendFormInError (state) {
|
|
|
|
return Object.values(getSendErrors(state)).some((n) => n)
|
|
|
|
}
|