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.
58 lines
1.7 KiB
58 lines
1.7 KiB
4 years ago
|
import { useDispatch } from 'react-redux';
|
||
|
import { useCallback } from 'react';
|
||
|
import { showSidebar } from '../store/actions';
|
||
5 years ago
|
import {
|
||
4 years ago
|
fetchBasicGasEstimates,
|
||
5 years ago
|
setCustomGasPriceForRetry,
|
||
|
setCustomGasLimit,
|
||
4 years ago
|
} from '../ducks/gas/gas.duck';
|
||
|
import { increaseLastGasPrice } from '../helpers/utils/confirm-tx.util';
|
||
|
import { useMetricEvent } from './useMetricEvent';
|
||
5 years ago
|
|
||
|
/**
|
||
|
* 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}
|
||
|
*/
|
||
4 years ago
|
export function useRetryTransaction(transactionGroup) {
|
||
4 years ago
|
const { primaryTransaction } = transactionGroup;
|
||
5 years ago
|
// Signature requests do not have a txParams, but this hook is called indiscriminately
|
||
4 years ago
|
const gasPrice = primaryTransaction.txParams?.gasPrice;
|
||
4 years ago
|
const trackMetricsEvent = useMetricEvent({
|
||
5 years ago
|
eventOpts: {
|
||
|
category: 'Navigation',
|
||
|
action: 'Activity Log',
|
||
|
name: 'Clicked "Speed Up"',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
const dispatch = useDispatch();
|
||
5 years ago
|
|
||
4 years ago
|
const retryTransaction = useCallback(
|
||
|
async (event) => {
|
||
4 years ago
|
event.stopPropagation();
|
||
5 years ago
|
|
||
4 years ago
|
trackMetricsEvent();
|
||
|
await dispatch(fetchBasicGasEstimates);
|
||
4 years ago
|
const transaction = primaryTransaction;
|
||
4 years ago
|
const increasedGasPrice = increaseLastGasPrice(gasPrice);
|
||
4 years ago
|
await dispatch(
|
||
4 years ago
|
setCustomGasPriceForRetry(
|
||
|
increasedGasPrice || transaction.txParams.gasPrice,
|
||
|
),
|
||
4 years ago
|
);
|
||
|
dispatch(setCustomGasLimit(transaction.txParams.gas));
|
||
4 years ago
|
dispatch(
|
||
|
showSidebar({
|
||
|
transitionName: 'sidebar-left',
|
||
|
type: 'customize-gas',
|
||
|
props: { transaction },
|
||
|
}),
|
||
4 years ago
|
);
|
||
4 years ago
|
},
|
||
4 years ago
|
[dispatch, trackMetricsEvent, gasPrice, primaryTransaction],
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
4 years ago
|
return retryTransaction;
|
||
5 years ago
|
}
|