Skip to content

Commit

Permalink
fix: Check if the notification has a mapped component
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinszuchet committed Sep 5, 2024
1 parent bd8697c commit 3950fa0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/components/Notifications/NotificationsFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ const NotificationHandler = ({
renderProfile?: (address: string) => JSX.Element | string | null
}) => {
const NotificationComponent = NotificationComponentByType[notification.type]

if (!NotificationComponent) {
return null
}

return (
<NotificationComponent
notification={notification}
Expand Down
15 changes: 8 additions & 7 deletions src/components/Notifications/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ export function getBGColorByRarity(rarity: Rarity) {
return Rarity.getGradient(rarity).join()
}

export type DecentralandNotificationComponentByType<T> = {
[k in NotificationType]: T extends DCLNotification
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
FunctionComponent<CommonNotificationProps<any>>
: never
}
export type DecentralandNotificationComponentByType<T> = Partial<
{
[k in NotificationType]: T extends DCLNotification
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
FunctionComponent<CommonNotificationProps<any>>
: never
}
>

export const NotificationComponentByType: DecentralandNotificationComponentByType<DCLNotification> =
{
Expand Down Expand Up @@ -101,7 +103,6 @@ export const NotificationComponentByType: DecentralandNotificationComponentByTyp
CampaignOutOfStockNotification,
[NotificationType.REWARD_CAMPAIGN_GAS_PRICE_HIGHER_THAN_EXPECTED]:
CampaignGasPriceHigherThanExpectedNotification,
[NotificationType.BADGE_GRANTED]: null,
[NotificationType.EVENTS_STARTS_SOON]: EventsStartsSoonNotification,
[NotificationType.EVENTS_STARTED]: EventsStartedNotification,
[NotificationType.WORLDS_PERMISSION_GRANTED]:
Expand Down

0 comments on commit 3950fa0

Please sign in to comment.