Skip to content

Commit

Permalink
improve save ack ann
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Sep 12, 2023
1 parent 0c4618c commit 421cb96
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/Announcement/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom'
import AnnouncementApi from 'services/announcement'

import { AnnouncementTemplatePopup, PopupContentAnnouncement, PopupItemType } from 'components/Announcement/type'
import { TIMES_IN_SECS } from 'constants/index'
import { useActiveWeb3React } from 'hooks'
import { useChangeNetwork } from 'hooks/web3/useChangeNetwork'
import { useAppDispatch } from 'state/hooks'
Expand All @@ -13,11 +14,15 @@ export const getAnnouncementsAckMap = () => JSON.parse(localStorage[LsKey] || '{

export const ackAnnouncementPopup = (id: string | number) => {
const announcementsMap = getAnnouncementsAckMap()
const entries = Object.entries(announcementsMap).filter(
// keep only ids that was added in the last 30 days
([_, value]) => typeof value === 'number' && Date.now() - value < TIMES_IN_SECS.ONE_DAY * 30 * 1000,
)
localStorage.setItem(
LsKey,
JSON.stringify({
...announcementsMap,
[id]: '1',
...Object.fromEntries(entries),
[id]: Date.now(),
}),
)
}
Expand Down

0 comments on commit 421cb96

Please sign in to comment.