A Metamask fork with Infura removed and default networks editable
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.
ciphermask/ui/hooks/useTransactionEventFragment.js

41 lines
1.1 KiB

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 { TRANSACTION_EVENTS } 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,
TRANSACTION_EVENTS.APPROVED,
);
}
updateEventFragment(`transaction-added-${transaction.id}`, params);
},
[fragment, transaction],
);
return {
updateTransactionEventFragment,
};
};