From 9cff14d0de79ef02bdd2929b04ac86e408d55ea3 Mon Sep 17 00:00:00 2001 From: Gary Ghayrat <61768337+garyghayrat@users.noreply.github.com> Date: Mon, 4 Dec 2023 11:15:50 -0500 Subject: [PATCH] Fix duplicate notifications when switching chains (#146) --- contexts/NotificationsContext.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contexts/NotificationsContext.tsx b/contexts/NotificationsContext.tsx index 031156a..70f3ea3 100644 --- a/contexts/NotificationsContext.tsx +++ b/contexts/NotificationsContext.tsx @@ -27,10 +27,14 @@ const NotificationsContext = createContext({ export const NotificationsProvider = ({ children }: { children: ReactNode }) => { const [notifications, setNotifications] = useState([]); const notify = (notification: TxNotification) => { + //if notification id already exists, don't add it again + const txId = `${notification.hash}-${notification.txStatus}-${notification.chainId}`; + if (notifications.some((n) => n.id === txId)) return; + setNotifications([ { ...notification, - id: `${notification.hash}-${notification.txStatus}-${notification.chainId}`, + id: txId, }, ...notifications, ]);