mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 18:41:38 +01:00
ddaa492751
The chosen token in the `send` flow was set from one of two places: `metamask.selectedTokenAddress` or `metamask.send.token`. The former is used most of the time, but the latter is used for the 'Edit' button shown in the upper-left of the confirmation UI. The send flow will now exclusively use `metamask.send.token` for the token state during the send flow. `metamask.selectedTokenAddress` is now only used for the selected token state on the Home screen. This simplifies the Redux state, as the send token is now in one place instead of two, and `metamask.selectedTokenAddress` has only one purpose.
168 lines
3.8 KiB
JavaScript
168 lines
3.8 KiB
JavaScript
import abi from 'human-standard-token-abi'
|
|
import {
|
|
accountsWithSendEtherInfoSelector,
|
|
getAddressBook,
|
|
getSelectedAccount,
|
|
getTargetAccount,
|
|
getAveragePriceEstimateInHexWEI,
|
|
} from '.'
|
|
import { calcGasTotal } from '../pages/send/send.utils'
|
|
|
|
export function getBlockGasLimit (state) {
|
|
return state.metamask.currentBlockGasLimit
|
|
}
|
|
|
|
export function getConversionRate (state) {
|
|
return state.metamask.conversionRate
|
|
}
|
|
|
|
export function getNativeCurrency (state) {
|
|
return state.metamask.nativeCurrency
|
|
}
|
|
|
|
export function getCurrentNetwork (state) {
|
|
return state.metamask.network
|
|
}
|
|
|
|
export function getGasLimit (state) {
|
|
return state.metamask.send.gasLimit || '0'
|
|
}
|
|
|
|
export function getGasPrice (state) {
|
|
return state.metamask.send.gasPrice || getAveragePriceEstimateInHexWEI(state)
|
|
}
|
|
|
|
export function getGasTotal (state) {
|
|
return calcGasTotal(getGasLimit(state), getGasPrice(state))
|
|
}
|
|
|
|
export function getPrimaryCurrency (state) {
|
|
const sendToken = getSendToken(state)
|
|
return sendToken?.symbol
|
|
}
|
|
|
|
export function getSendToken (state) {
|
|
return state.metamask.send.token
|
|
}
|
|
|
|
export function getSendTokenAddress (state) {
|
|
return getSendToken(state)?.address
|
|
}
|
|
|
|
export function getSendTokenContract (state) {
|
|
const sendTokenAddress = getSendTokenAddress(state)
|
|
return sendTokenAddress
|
|
? global.eth.contract(abi).at(sendTokenAddress)
|
|
: null
|
|
}
|
|
|
|
export function getSendAmount (state) {
|
|
return state.metamask.send.amount
|
|
}
|
|
|
|
export function getSendHexData (state) {
|
|
return state.metamask.send.data
|
|
}
|
|
|
|
export function getSendHexDataFeatureFlagState (state) {
|
|
return state.metamask.featureFlags.sendHexData
|
|
}
|
|
|
|
export function getSendEditingTransactionId (state) {
|
|
return state.metamask.send.editingTransactionId
|
|
}
|
|
|
|
export function getSendErrors (state) {
|
|
return state.send.errors
|
|
}
|
|
|
|
export function sendAmountIsInError (state) {
|
|
return Boolean(state.send.errors.amount)
|
|
}
|
|
|
|
export function getSendFrom (state) {
|
|
return state.metamask.send.from
|
|
}
|
|
|
|
export function getSendFromBalance (state) {
|
|
const fromAccount = getSendFromObject(state)
|
|
return fromAccount.balance
|
|
}
|
|
|
|
export function getSendFromObject (state) {
|
|
const fromAddress = getSendFrom(state)
|
|
return fromAddress
|
|
? getTargetAccount(state, fromAddress)
|
|
: getSelectedAccount(state)
|
|
}
|
|
|
|
export function getSendMaxModeState (state) {
|
|
return state.metamask.send.maxModeOn
|
|
}
|
|
|
|
export function getSendTo (state) {
|
|
return state.metamask.send.to
|
|
}
|
|
|
|
export function getSendToNickname (state) {
|
|
return state.metamask.send.toNickname
|
|
}
|
|
|
|
export function getSendToAccounts (state) {
|
|
const fromAccounts = accountsWithSendEtherInfoSelector(state)
|
|
const addressBookAccounts = getAddressBook(state)
|
|
return [...fromAccounts, ...addressBookAccounts]
|
|
}
|
|
export function getTokenBalance (state) {
|
|
return state.metamask.send.tokenBalance
|
|
}
|
|
|
|
export function getSendEnsResolution (state) {
|
|
return state.metamask.send.ensResolution
|
|
}
|
|
|
|
export function getSendEnsResolutionError (state) {
|
|
return state.metamask.send.ensResolutionError
|
|
}
|
|
|
|
export function getUnapprovedTxs (state) {
|
|
return state.metamask.unapprovedTxs
|
|
}
|
|
|
|
export function getQrCodeData (state) {
|
|
return state.appState.qrCodeData
|
|
}
|
|
|
|
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 getTitleKey (state) {
|
|
const isEditing = Boolean(getSendEditingTransactionId(state))
|
|
const isToken = Boolean(getSendToken(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)
|
|
}
|