Skip to content

Commit

Permalink
Fix duplicate notifications when switching chains (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
garyghayrat authored Dec 4, 2023
1 parent 5d33d15 commit 9cff14d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion contexts/NotificationsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ const NotificationsContext = createContext<NotificationsContextType>({
export const NotificationsProvider = ({ children }: { children: ReactNode }) => {
const [notifications, setNotifications] = useState<TxNotificationWithId[]>([]);
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,
]);
Expand Down

0 comments on commit 9cff14d

Please sign in to comment.