diff --git a/ui/app/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js b/ui/app/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js index 4a21e9e99..bad68879b 100644 --- a/ui/app/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js +++ b/ui/app/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js @@ -40,10 +40,10 @@ import { getEstimatedGasTimes, getRenderableBasicEstimateData, getBasicGasEstimateBlockTime, - getTxParams, isCustomPriceSafe, getTokenBalance, getSendMaxModeState, + getFastPriceEstimateInHexWEI, } from '../../../../selectors' import { @@ -67,7 +67,7 @@ import { addHexPrefix } from 'ethereumjs-util' import { calcMaxAmount } from '../../../../pages/send/send-content/send-amount-row/amount-max-button/amount-max-button.utils' const mapStateToProps = (state, ownProps) => { - const { currentNetworkTxList } = state.metamask + const { currentNetworkTxList, send } = state.metamask const { modalState: { props: modalProps } = {} } = state.appState.modal || {} const { txData = {} } = modalProps || {} const { transaction = {} } = ownProps @@ -75,8 +75,18 @@ const mapStateToProps = (state, ownProps) => { const buttonDataLoading = getBasicGasEstimateLoadingStatus(state) const gasEstimatesLoading = getGasEstimatesLoadingStatus(state) + const selectedToken = getSelectedToken(state) - const { gasPrice: currentGasPrice, gas: currentGasLimit, value } = getTxParams(state, selectedTransaction) + // a "default" txParams is used during the send flow, since the transaction doesn't exist yet in that case + const txParams = selectedTransaction?.txParams + ? selectedTransaction.txParams + : { + gas: send.gasLimit || '0x5208', + gasPrice: send.gasPrice || getFastPriceEstimateInHexWEI(state, true), + value: selectedToken ? '0x0' : send.amount, + } + + const { gasPrice: currentGasPrice, gas: currentGasLimit, value } = txParams const customModalGasPriceInHex = getCustomGasPrice(state) || currentGasPrice const customModalGasLimitInHex = getCustomGasLimit(state) || currentGasLimit || '0x5208' const customGasTotal = calcGasTotal(customModalGasLimitInHex, customModalGasPriceInHex) @@ -102,7 +112,7 @@ const mapStateToProps = (state, ownProps) => { const isMainnet = getIsMainnet(state) const showFiat = Boolean(isMainnet || showFiatInTestnets) - const isTokenSelected = Boolean(getSelectedToken(state)) + const isTokenSelected = Boolean(selectedToken) const newTotalEth = maxModeOn && !isTokenSelected ? addHexWEIsToRenderableEth(balance, '0x0') : addHexWEIsToRenderableEth(value, customGasTotal) diff --git a/ui/app/components/app/transaction-time-remaining/transaction-time-remaining.container.js b/ui/app/components/app/transaction-time-remaining/transaction-time-remaining.container.js index 76bd7e82b..754d84991 100644 --- a/ui/app/components/app/transaction-time-remaining/transaction-time-remaining.container.js +++ b/ui/app/components/app/transaction-time-remaining/transaction-time-remaining.container.js @@ -3,14 +3,13 @@ import TransactionTimeRemaining from './transaction-time-remaining.component' import { getEstimatedGasPrices, getEstimatedGasTimes, - getTxParams, } from '../../../selectors' import { getRawTimeEstimateData } from '../../../helpers/utils/gas-time-estimates.util' import { hexWEIToDecGWEI } from '../../../helpers/utils/conversions.util' const mapStateToProps = (state, ownProps) => { const { transaction } = ownProps - const { gasPrice: currentGasPrice } = getTxParams(state, transaction) + const { gasPrice: currentGasPrice } = transaction.txParams const customGasPrice = calcCustomGasPrice(currentGasPrice) const gasPrices = getEstimatedGasPrices(state) const estimatedTimes = getEstimatedGasTimes(state) diff --git a/ui/app/hooks/useRetryTransaction.js b/ui/app/hooks/useRetryTransaction.js index 30362a0b8..2aa40875d 100644 --- a/ui/app/hooks/useRetryTransaction.js +++ b/ui/app/hooks/useRetryTransaction.js @@ -21,8 +21,8 @@ import { useMethodData } from './useMethodData' */ export function useRetryTransaction (transactionGroup) { const { primaryTransaction, initialTransaction } = transactionGroup - const gasPrice = primaryTransaction.txParams?.gasPrice - const methodData = useMethodData(primaryTransaction.txParams?.data) + const gasPrice = primaryTransaction.txParams.gasPrice + const methodData = useMethodData(primaryTransaction.txParams.data) const trackMetricsEvent = useMetricEvent(({ eventOpts: { category: 'Navigation', @@ -42,8 +42,8 @@ export function useRetryTransaction (transactionGroup) { await dispatch(fetchGasEstimates(basicEstimates.blockTime)) const transaction = initialTransaction const increasedGasPrice = increaseLastGasPrice(gasPrice) - dispatch(setCustomGasPriceForRetry(increasedGasPrice || transaction.txParams?.gasPrice)) - dispatch(setCustomGasLimit(transaction.txParams?.gas)) + dispatch(setCustomGasPriceForRetry(increasedGasPrice || transaction.txParams.gasPrice)) + dispatch(setCustomGasLimit(transaction.txParams.gas)) dispatch(showSidebar({ transitionName: 'sidebar-left', type: 'customize-gas', diff --git a/ui/app/selectors/transactions.js b/ui/app/selectors/transactions.js index 2906ff301..5950bbf0d 100644 --- a/ui/app/selectors/transactions.js +++ b/ui/app/selectors/transactions.js @@ -10,9 +10,7 @@ import { TRANSACTION_TYPE_RETRY, } from '../../../app/scripts/controllers/transactions/enums' import { hexToDecimal } from '../helpers/utils/conversions.util' -import { getFastPriceEstimateInHexWEI } from './custom-gas' import { - getSelectedToken, getSelectedAddress, } from '.' import txHelper from '../../lib/tx-helper' @@ -306,15 +304,3 @@ export const submittedPendingTransactionsSelector = createSelector( transactions.filter((transaction) => transaction.status === SUBMITTED_STATUS) ) ) - -export const getTxParams = (state, selectedTransaction = {}) => { - const { metamask: { send } } = state - const { txParams } = selectedTransaction - return txParams || { - from: send.from, - gas: send.gasLimit || '0x5208', - gasPrice: send.gasPrice || getFastPriceEstimateInHexWEI(state, true), - to: send.to, - value: getSelectedToken(state) ? '0x0' : send.amount, - } -}