1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Remove getTxParams (#8676)

This function primarily ensured that there was a reasonable fallback
for `txParams` if the given transaction was missing it. This fallback
was only used in one place: the customize gas modal, during the send
flow specifically.

The helper function has been removed, and the default `txParams` is set
in the one place it was needed. In the future we should attempt to
simplify this modal so it doesn't need to know details about the
context in which it's being used.
This commit is contained in:
Mark Stacey 2020-05-28 16:39:33 -03:00 committed by GitHub
parent 00834f5de6
commit 795676d3ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 24 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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',

View File

@ -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,
}
}