Files
js/hooks/useTxNotifications.ts
T
Nacho Iacovino fe53dfa054 Update dependencies and clean unused (#2328)
* Remove kyb/kyc, update stripe

* Knip cleanup, improve stripe init

* Update dependencies

* Remove unused campaign

* eslint

* unused

* Update dependencies

* Missing a focuslock here

* Add a spinner to wait for the page to reload

* Update stripe again

* format

* Update dependencies again

* update

* Update lock

* Nightly

* Recover file

* format

* update

* Run install
2024-03-15 19:17:28 +00:00

43 lines
1.1 KiB
TypeScript

import { useToast } from "@chakra-ui/react";
import { useErrorHandler } from "contexts/error-handler";
import { useCallback } from "react";
import { useInvalidateContractQuery } from "thirdweb/react";
export function useTxNotifications(
successMessage: string,
errorMessage: string,
contract?: any,
) {
const toast = useToast();
const { onError } = useErrorHandler();
const invalidateContractQuery = useInvalidateContractQuery();
const onSuccess = useCallback(() => {
toast({
position: "bottom",
variant: "solid",
title: "Success",
description: successMessage,
status: "success",
duration: 5000,
isClosable: true,
});
if (contract) {
invalidateContractQuery({
chainId: contract.chainId,
contractAddress: contract.getAddress(),
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [successMessage]);
const _onError = useCallback(
(error: unknown) => {
onError(error, errorMessage);
},
[errorMessage, onError],
);
return { onSuccess, onError: _onError };
}