From 80050824ea774ea9fcf6e8b3c7750ad43dd2f2f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Fri, 30 Jun 2023 14:38:38 +0200 Subject: [PATCH] small seen msgs request impro --- .../notifications/NotificationsDrawer.tsx | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/components/notifications/NotificationsDrawer.tsx b/components/notifications/NotificationsDrawer.tsx index c956e26e..9ab06e66 100644 --- a/components/notifications/NotificationsDrawer.tsx +++ b/components/notifications/NotificationsDrawer.tsx @@ -19,6 +19,7 @@ import NotificationCookieStore from '@store/notificationCookieStore' import dayjs from 'dayjs' import { useTranslation } from 'next-i18next' import { notify } from 'utils/notifications' +import { chunk } from 'lodash' export const createSolanaMessage = ( wallet: WalletContextState, @@ -94,23 +95,26 @@ const NotificationsDrawer = ({ const markAsSeen = useCallback( async (ids: number[]) => { try { - const resp = await fetch(`${NOTIFICATION_API}notifications/seen`, { - method: 'POST', - headers: headers.headers, - body: JSON.stringify({ - ids: ids, - seen: true, - }), - }) - const body = await resp.json() - const error = body.error - if (error) { - notify({ - type: 'error', - title: 'Error', - description: error, + const idsChunk = chunk(ids, 200) + for (const c of idsChunk) { + const resp = await fetch(`${NOTIFICATION_API}notifications/seen`, { + method: 'POST', + headers: headers.headers, + body: JSON.stringify({ + ids: c, + seen: true, + }), }) - return + const body = await resp.json() + const error = body.error + if (error) { + notify({ + type: 'error', + title: 'Error', + description: error, + }) + return + } } refetch() } catch (e) {