Skip to content

Commit

Permalink
Merge pull request #293 from P4-Games/feature/notifications
Browse files Browse the repository at this point in the history
Feature/notifications
  • Loading branch information
dappsar authored Dec 24, 2023
2 parents fa4e9ed + c23783c commit 40e1ab3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/context/NotificationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,22 @@ export const NotificationProvider = ({ children }) => {

const getNotificationsByUser = (user) => {
if (!user) return notifications
return notifications.filter(
const myNotifications = notifications.filter(
(notification) => notification.walletAddress === user && notification.deleted === false
)
return filterUniqueNotifications(myNotifications)
}

const filterUniqueNotifications = (notificationList) => {
const uniqueIdentifiers = new Set()
return notificationList.filter((notification) => {
const identifier = `${notification.message}-${JSON.stringify(notification.data)}`
if (uniqueIdentifiers.has(identifier)) {
return false
}
uniqueIdentifiers.add(identifier)
return true
})
}

useEffect(() => {
Expand Down
20 changes: 20 additions & 0 deletions src/sections/Gamma/GammaMain.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ const GammaMain = () => {
}
}

useEffect(() => {
if (!gammaCardsContract || !walletAddress) return
gammaCardsContract.on('OfferCardsExchanged', (from, to) => {
if (
to.toUpperCase() === walletAddress.toUpperCase() ||
from.toUpperCase() === walletAddress.toUpperCase()
) {
updateUserData()
}
})
gammaCardsContract.on('CardTransfered', (from, to) => {
if (
to.toUpperCase() === walletAddress.toUpperCase() ||
from.toUpperCase() === walletAddress.toUpperCase()
) {
updateUserData()
}
})
}, [gammaCardsContract, walletAddress]) //eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
setCardsQtty(getCardsQtty(paginationObj))
}, [paginationObj]) //eslint-disable-line react-hooks/exhaustive-deps
Expand Down

0 comments on commit 40e1ab3

Please sign in to comment.