Skip to content

Commit

Permalink
fix: Check if the notification has a mapped component (#560)
Browse files Browse the repository at this point in the history
* fix: Check if the notification has a mapped component

* chore: Bump schemas
  • Loading branch information
kevinszuchet authored Sep 5, 2024
1 parent bd8697c commit fad8d7e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"webpack-cli": "^3.3.2"
},
"dependencies": {
"@dcl/schemas": "^13.6.2",
"@dcl/schemas": "^13.9.0",
"@dcl/ui-env": "^1.5.1",
"balloon-css": "^0.5.0",
"classnames": "^2.3.2",
Expand Down
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 fad8d7e

Please sign in to comment.