Skip to content

Commit

Permalink
Fix duplicate notifications when switching chains
Browse files Browse the repository at this point in the history
  • Loading branch information
garyghayrat committed Dec 1, 2023
1 parent f4929a8 commit 556a365
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions hooks/useEasyWrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import {
UsePrepareContractWriteConfig,
} from 'wagmi';
import { useNotifications } from '@/contexts/NotificationsContext';
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import usePrevious from '@/hooks/usePrevious';

export const useEasyWrite = (
params: UsePrepareContractWriteConfig & { isCrossChain?: boolean }
) => {
const { notify } = useNotifications();
const [isNotificationShownAlready, setIsNotificationShownAlready] = useState(false);
const { config, error: prepareError } = usePrepareContractWrite(params);
const {
data: writeData,
Expand All @@ -35,6 +36,7 @@ export const useEasyWrite = (
status: transactionData?.status,
isTransactionDataLoading,
waitError,
isNotificationShownAlready,
});

useEffect(() => {
Expand All @@ -57,8 +59,14 @@ export const useEasyWrite = (
return;
}
// succeed
if (hash && transactionData?.status === 'success' && prev.status !== 'success') {
if (
hash &&
transactionData?.status === 'success' &&
prev.status !== 'success' &&
!prev.isNotificationShownAlready
) {
console.log('notify success');
setIsNotificationShownAlready(true);
if (params.isCrossChain) {
notify({
hash,
Expand Down

0 comments on commit 556a365

Please sign in to comment.