mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-25 20:02:58 +01:00
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import { useCallback } from 'react';
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { useGasFeeContext } from '../contexts/gasFee';
|
|
import {
|
|
createTransactionEventFragment,
|
|
updateEventFragment,
|
|
} from '../store/actions';
|
|
import { selectMatchingFragment } from '../selectors';
|
|
import { TransactionMetaMetricsEvent } from '../../shared/constants/transaction';
|
|
|
|
export const useTransactionEventFragment = () => {
|
|
const { transaction } = useGasFeeContext();
|
|
const fragment = useSelector((state) =>
|
|
selectMatchingFragment(state, {
|
|
fragmentOptions: {},
|
|
existingId: `transaction-added-${transaction?.id}`,
|
|
}),
|
|
);
|
|
|
|
const updateTransactionEventFragment = useCallback(
|
|
async (params) => {
|
|
if (!transaction || !transaction.id) {
|
|
return;
|
|
}
|
|
if (!fragment) {
|
|
await createTransactionEventFragment(
|
|
transaction.id,
|
|
TransactionMetaMetricsEvent.approved,
|
|
);
|
|
}
|
|
updateEventFragment(`transaction-added-${transaction.id}`, params);
|
|
},
|
|
[fragment, transaction],
|
|
);
|
|
|
|
return {
|
|
updateTransactionEventFragment,
|
|
};
|
|
};
|