mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 02:58:09 +01:00
97d268c8ee
* Remove use of ethgassthat; use metaswap /gasPrices api for gas price estimates * Remove references to ethgasstation * Pass base to BigNumber constructor in fetchExternalBasicGasEstimates * Update ui/app/hooks/useTokenTracker.js Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com> * Delete gas price chart * Remove price chart css import * Delete additional fee chart code * Lint fix * Delete more code no longer used after ethgasstation removal Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
import { useDispatch } from 'react-redux'
|
|
import { useCallback } from 'react'
|
|
import { showSidebar } from '../store/actions'
|
|
import {
|
|
fetchBasicGasEstimates,
|
|
setCustomGasPriceForRetry,
|
|
setCustomGasLimit,
|
|
} from '../ducks/gas/gas.duck'
|
|
import { increaseLastGasPrice } from '../helpers/utils/confirm-tx.util'
|
|
import { useMetricEvent } from './useMetricEvent'
|
|
|
|
/**
|
|
* 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
|
|
// Signature requests do not have a txParams, but this hook is called indiscriminately
|
|
const gasPrice = primaryTransaction.txParams?.gasPrice
|
|
const trackMetricsEvent = useMetricEvent({
|
|
eventOpts: {
|
|
category: 'Navigation',
|
|
action: 'Activity Log',
|
|
name: 'Clicked "Speed Up"',
|
|
},
|
|
})
|
|
const dispatch = useDispatch()
|
|
|
|
const retryTransaction = useCallback(
|
|
async (event) => {
|
|
event.stopPropagation()
|
|
|
|
trackMetricsEvent()
|
|
await dispatch(fetchBasicGasEstimates)
|
|
const transaction = initialTransaction
|
|
const increasedGasPrice = increaseLastGasPrice(gasPrice)
|
|
await dispatch(
|
|
setCustomGasPriceForRetry(
|
|
increasedGasPrice || transaction.txParams.gasPrice,
|
|
),
|
|
)
|
|
dispatch(setCustomGasLimit(transaction.txParams.gas))
|
|
dispatch(
|
|
showSidebar({
|
|
transitionName: 'sidebar-left',
|
|
type: 'customize-gas',
|
|
props: { transaction },
|
|
}),
|
|
)
|
|
},
|
|
[dispatch, trackMetricsEvent, initialTransaction, gasPrice],
|
|
)
|
|
|
|
return retryTransaction
|
|
}
|