You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Tag:
Branch:
Tree:
c30e41b9ce
develop
feature/default_network_editable
v10.22.3
${ noResults }
58 lines
1.7 KiB
58 lines
1.7 KiB
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 } = 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 = primaryTransaction;
|
|||
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, gasPrice, primaryTransaction],
|
|||
);
|
|||
|
|||
return retryTransaction;
|
|||
}
|