1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-11 20:27:12 +01:00
metamask-extension/ui/hooks/useRetryTransaction.js

49 lines
1.5 KiB
JavaScript
Raw Normal View History

import { useCallback, useState } from 'react';
import { useMetricEvent } from './useMetricEvent';
import { useIncrementedGasFees } from './useIncrementedGasFees';
/**
* @typedef {Object} RetryTransactionReturnValue
* @property {(event: Event) => void} retryTransaction - open edit gas popover
* to begin setting retry gas fees
* @property {boolean} showRetryEditGasPopover - Whether to show the popover
* @property {() => void} closeRetryEditGasPopover - close the popover.
*/
/**
* Provides a reusable hook that, given a transactionGroup, will return
* a method for beginning the retry process
* @param {Object} transactionGroup - the transaction group
* @return {RetryTransactionReturnValue}
*/
export function useRetryTransaction(transactionGroup) {
const customRetryGasSettings = useIncrementedGasFees(transactionGroup);
2020-11-03 00:41:28 +01:00
const trackMetricsEvent = useMetricEvent({
eventOpts: {
category: 'Navigation',
action: 'Activity Log',
name: 'Clicked "Speed Up"',
},
});
const [showRetryEditGasPopover, setShowRetryEditGasPopover] = useState(false);
const closeRetryEditGasPopover = () => setShowRetryEditGasPopover(false);
2020-11-03 00:41:28 +01:00
const retryTransaction = useCallback(
async (event) => {
event.stopPropagation();
setShowRetryEditGasPopover(true);
trackMetricsEvent();
2020-11-03 00:41:28 +01:00
},
[trackMetricsEvent],
);
return {
retryTransaction,
showRetryEditGasPopover,
closeRetryEditGasPopover,
customRetryGasSettings,
};
}