mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-27 12:56:01 +01:00
795676d3ec
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.
63 lines
2.1 KiB
JavaScript
63 lines
2.1 KiB
JavaScript
import { useDispatch } from 'react-redux'
|
|
import { useCallback } from 'react'
|
|
import { setSelectedToken, showSidebar } from '../store/actions'
|
|
import {
|
|
fetchBasicGasAndTimeEstimates,
|
|
fetchGasEstimates,
|
|
setCustomGasPriceForRetry,
|
|
setCustomGasLimit,
|
|
} from '../ducks/gas/gas.duck'
|
|
import { TOKEN_METHOD_TRANSFER } from '../helpers/constants/transactions'
|
|
import { increaseLastGasPrice } from '../helpers/utils/confirm-tx.util'
|
|
import { useMetricEvent } from './useMetricEvent'
|
|
import { useMethodData } from './useMethodData'
|
|
|
|
|
|
/**
|
|
* Provides a reusable hook that, given a transactionGroup, will return
|
|
* a method for beginning the retry process
|
|
* @param {Object} transactionGroup - the transaction group
|
|
* @return {Function}
|
|
*/
|
|
export function useRetryTransaction (transactionGroup) {
|
|
const { primaryTransaction, initialTransaction } = transactionGroup
|
|
const gasPrice = primaryTransaction.txParams.gasPrice
|
|
const methodData = useMethodData(primaryTransaction.txParams.data)
|
|
const trackMetricsEvent = useMetricEvent(({
|
|
eventOpts: {
|
|
category: 'Navigation',
|
|
action: 'Activity Log',
|
|
name: 'Clicked "Speed Up"',
|
|
},
|
|
}))
|
|
const dispatch = useDispatch()
|
|
|
|
const { name: methodName } = methodData || {}
|
|
|
|
const retryTransaction = useCallback(async (event) => {
|
|
event.stopPropagation()
|
|
|
|
trackMetricsEvent()
|
|
const basicEstimates = await dispatch(fetchBasicGasAndTimeEstimates)
|
|
await dispatch(fetchGasEstimates(basicEstimates.blockTime))
|
|
const transaction = initialTransaction
|
|
const increasedGasPrice = increaseLastGasPrice(gasPrice)
|
|
dispatch(setCustomGasPriceForRetry(increasedGasPrice || transaction.txParams.gasPrice))
|
|
dispatch(setCustomGasLimit(transaction.txParams.gas))
|
|
dispatch(showSidebar({
|
|
transitionName: 'sidebar-left',
|
|
type: 'customize-gas',
|
|
props: { transaction },
|
|
}))
|
|
|
|
if (
|
|
methodName === TOKEN_METHOD_TRANSFER &&
|
|
initialTransaction.txParams.to
|
|
) {
|
|
dispatch(setSelectedToken(initialTransaction.txParams.to))
|
|
}
|
|
}, [dispatch, methodName, trackMetricsEvent, initialTransaction, gasPrice])
|
|
|
|
return retryTransaction
|
|
}
|