You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
4.6 KiB
194 lines
4.6 KiB
5 years ago
|
import abi from 'human-standard-token-abi'
|
||
5 years ago
|
import {
|
||
|
accountsWithSendEtherInfoSelector,
|
||
|
getAddressBook,
|
||
5 years ago
|
getSelectedAccount,
|
||
|
getTargetAccount,
|
||
5 years ago
|
getSelectedAddress,
|
||
5 years ago
|
getAveragePriceEstimateInHexWEI,
|
||
5 years ago
|
} from '.'
|
||
|
import { estimateGasPriceFromRecentBlocks, calcGasTotal } from '../pages/send/send.utils'
|
||
7 years ago
|
|
||
5 years ago
|
export function getBlockGasLimit (state) {
|
||
7 years ago
|
return state.metamask.currentBlockGasLimit
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getConversionRate (state) {
|
||
7 years ago
|
return state.metamask.conversionRate
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getCurrentCurrency (state) {
|
||
7 years ago
|
return state.metamask.currentCurrency
|
||
|
}
|
||
7 years ago
|
|
||
5 years ago
|
export function getNativeCurrency (state) {
|
||
6 years ago
|
return state.metamask.nativeCurrency
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getCurrentNetwork (state) {
|
||
7 years ago
|
return state.metamask.network
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getGasLimit (state) {
|
||
6 years ago
|
return state.metamask.send.gasLimit || '0'
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getGasPrice (state) {
|
||
5 years ago
|
return state.metamask.send.gasPrice || getAveragePriceEstimateInHexWEI(state)
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getGasPriceFromRecentBlocks (state) {
|
||
7 years ago
|
return estimateGasPriceFromRecentBlocks(state.metamask.recentBlocks)
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getGasTotal (state) {
|
||
6 years ago
|
return calcGasTotal(getGasLimit(state), getGasPrice(state))
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getPrimaryCurrency (state) {
|
||
7 years ago
|
const selectedToken = getSelectedToken(state)
|
||
|
return selectedToken && selectedToken.symbol
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getRecentBlocks (state) {
|
||
7 years ago
|
return state.metamask.recentBlocks
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getSelectedIdentity (state) {
|
||
7 years ago
|
const selectedAddress = getSelectedAddress(state)
|
||
|
const identities = state.metamask.identities
|
||
|
|
||
|
return identities[selectedAddress]
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getSelectedToken (state) {
|
||
7 years ago
|
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
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getSelectedTokenContract (state) {
|
||
7 years ago
|
const selectedToken = getSelectedToken(state)
|
||
7 years ago
|
|
||
7 years ago
|
return selectedToken
|
||
|
? global.eth.contract(abi).at(selectedToken.address)
|
||
|
: null
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getSendAmount (state) {
|
||
7 years ago
|
return state.metamask.send.amount
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getSendHexData (state) {
|
||
6 years ago
|
return state.metamask.send.data
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getSendHexDataFeatureFlagState (state) {
|
||
6 years ago
|
return state.metamask.featureFlags.sendHexData
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getSendEditingTransactionId (state) {
|
||
7 years ago
|
return state.metamask.send.editingTransactionId
|
||
|
}
|
||
7 years ago
|
|
||
5 years ago
|
export function getSendErrors (state) {
|
||
7 years ago
|
return state.send.errors
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
5 years ago
|
export function sendAmountIsInError (state) {
|
||
|
return Boolean(state.send.errors.amount)
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getSendFrom (state) {
|
||
7 years ago
|
return state.metamask.send.from
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getSendFromBalance (state) {
|
||
5 years ago
|
const fromAccount = getSendFromObject(state)
|
||
|
return fromAccount.balance
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getSendFromObject (state) {
|
||
|
const fromAddress = getSendFrom(state)
|
||
|
return fromAddress
|
||
|
? getTargetAccount(state, fromAddress)
|
||
|
: getSelectedAccount(state)
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getSendMaxModeState (state) {
|
||
7 years ago
|
return state.metamask.send.maxModeOn
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getSendTo (state) {
|
||
7 years ago
|
return state.metamask.send.to
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getSendToNickname (state) {
|
||
5 years ago
|
return state.metamask.send.toNickname
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getSendToAccounts (state) {
|
||
7 years ago
|
const fromAccounts = accountsWithSendEtherInfoSelector(state)
|
||
|
const addressBookAccounts = getAddressBook(state)
|
||
6 years ago
|
return [...fromAccounts, ...addressBookAccounts]
|
||
7 years ago
|
}
|
||
5 years ago
|
export function getTokenBalance (state) {
|
||
7 years ago
|
return state.metamask.send.tokenBalance
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getSendEnsResolution (state) {
|
||
5 years ago
|
return state.metamask.send.ensResolution
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getSendEnsResolutionError (state) {
|
||
5 years ago
|
return state.metamask.send.ensResolutionError
|
||
|
}
|
||
|
|
||
5 years ago
|
export function getUnapprovedTxs (state) {
|
||
7 years ago
|
return state.metamask.unapprovedTxs
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getQrCodeData (state) {
|
||
6 years ago
|
return state.appState.qrCodeData
|
||
6 years ago
|
}
|
||
5 years ago
|
|
||
|
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)
|
||
|
}
|