From fb4152dac0cc7bd2d3717a07ad775279035c3f57 Mon Sep 17 00:00:00 2001 From: Lautaro Bustos Date: Fri, 8 Dec 2023 11:26:33 -0300 Subject: [PATCH] fix: state and timestamp bugs (#528) * fix: state bugs * chore: libs --- package-lock.json | 25 ++++++------------- package.json | 3 +-- .../UserInformation/UserInformation.tsx | 23 ++++------------- src/modules/notifications.ts | 9 ++++--- 4 files changed, 18 insertions(+), 42 deletions(-) diff --git a/package-lock.json b/package-lock.json index ade4d559..0303839d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,12 +22,11 @@ "decentraland-connect": "^5.1.0", "decentraland-crypto-fetch": "^2.0.1", "decentraland-transactions": "^1.47.0", - "decentraland-ui": "^4.30.2", + "decentraland-ui": "^4.30.3", "ethers": "^5.6.8", "events": "^3.3.0", "flat": "^5.0.2", "pusher-js": "^8.0.1", - "radash": "7.1.0", "react-intl": "^5.20.7", "redux-persistence": "^1.2.0", "redux-persistence-engine-localstorage": "^1.0.0", @@ -6286,9 +6285,9 @@ "integrity": "sha512-L4/bPD2fOeEdtFx+OnO3N81+/gsOkdensIuV9uFGYSN1mSTFaxHkWkhG8DOZ/8jlD0H2Qjkj6yDcWFaK+qu1Dg==" }, "node_modules/decentraland-ui": { - "version": "4.30.2", - "resolved": "https://registry.npmjs.org/decentraland-ui/-/decentraland-ui-4.30.2.tgz", - "integrity": "sha512-Q89MfsNxxLU7+vwEktU6jwzuo9iiKyW3jGbko0ehMe67+B8Pn6WtdVLOlawALzjsKUTkAMVkctStbJq5gkXPiQ==", + "version": "4.30.3", + "resolved": "https://registry.npmjs.org/decentraland-ui/-/decentraland-ui-4.30.3.tgz", + "integrity": "sha512-XyxFrDXa9y+FhTZFOm8+Bt5rf7nPsQxlju2PZl2CcDkQZvPjyoA63aoAuwpd91Oi0U1xWCAuLDQbLncJp1JYvw==", "dependencies": { "@dcl/schemas": "^9.7.0", "@dcl/ui-env": "^1.4.0", @@ -14505,11 +14504,6 @@ "rabin-wasm": "cli/bin.js" } }, - "node_modules/radash": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/radash/-/radash-7.1.0.tgz", - "integrity": "sha512-NOWTaF5YMY3mCgrNq9Fw9fK8yvJv92uqRb2StcVq5W8kcJ6949EbV2vk6nLJKAocYs29rzJafZZP1lFkEkoVGw==" - }, "node_modules/raf": { "version": "3.4.1", "resolved": "https://registry.npmjs.org/raf/-/raf-3.4.1.tgz", @@ -22665,9 +22659,9 @@ "integrity": "sha512-L4/bPD2fOeEdtFx+OnO3N81+/gsOkdensIuV9uFGYSN1mSTFaxHkWkhG8DOZ/8jlD0H2Qjkj6yDcWFaK+qu1Dg==" }, "decentraland-ui": { - "version": "4.30.2", - "resolved": "https://registry.npmjs.org/decentraland-ui/-/decentraland-ui-4.30.2.tgz", - "integrity": "sha512-Q89MfsNxxLU7+vwEktU6jwzuo9iiKyW3jGbko0ehMe67+B8Pn6WtdVLOlawALzjsKUTkAMVkctStbJq5gkXPiQ==", + "version": "4.30.3", + "resolved": "https://registry.npmjs.org/decentraland-ui/-/decentraland-ui-4.30.3.tgz", + "integrity": "sha512-XyxFrDXa9y+FhTZFOm8+Bt5rf7nPsQxlju2PZl2CcDkQZvPjyoA63aoAuwpd91Oi0U1xWCAuLDQbLncJp1JYvw==", "requires": { "@dcl/schemas": "^9.7.0", "@dcl/ui-env": "^1.4.0", @@ -28884,11 +28878,6 @@ "readable-stream": "^3.6.0" } }, - "radash": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/radash/-/radash-7.1.0.tgz", - "integrity": "sha512-NOWTaF5YMY3mCgrNq9Fw9fK8yvJv92uqRb2StcVq5W8kcJ6949EbV2vk6nLJKAocYs29rzJafZZP1lFkEkoVGw==" - }, "raf": { "version": "3.4.1", "resolved": "https://registry.npmjs.org/raf/-/raf-3.4.1.tgz", diff --git a/package.json b/package.json index 027f206b..b2dc16a1 100644 --- a/package.json +++ b/package.json @@ -16,12 +16,11 @@ "decentraland-connect": "^5.1.0", "decentraland-crypto-fetch": "^2.0.1", "decentraland-transactions": "^1.47.0", - "decentraland-ui": "^4.30.2", + "decentraland-ui": "^4.30.3", "ethers": "^5.6.8", "events": "^3.3.0", "flat": "^5.0.2", "pusher-js": "^8.0.1", - "radash": "7.1.0", "react-intl": "^5.20.7", "redux-persistence": "^1.2.0", "redux-persistence-engine-localstorage": "^1.0.0", diff --git a/src/containers/UserInformation/UserInformation.tsx b/src/containers/UserInformation/UserInformation.tsx index 4a056b92..c6a8a710 100644 --- a/src/containers/UserInformation/UserInformation.tsx +++ b/src/containers/UserInformation/UserInformation.tsx @@ -1,5 +1,4 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react' -import { diff } from 'radash/dist/array' import { MenuItemType, UserInformationContainer as UserMenuComponent @@ -16,7 +15,7 @@ import { DROPDOWN_MENU_SIGN_IN_EVENT, DROPDOWN_MENU_SIGN_OUT_EVENT } from './constants' -import { NotificationsAPI, checkIsOnboarding, parseNotification} from '../../modules/notifications' +import { NotificationsAPI, checkIsOnboarding} from '../../modules/notifications' const NOTIFICATIONS_QUERY_INTERVAL = 60000; @@ -130,17 +129,10 @@ export const UserInformation = (props: UserInformationProps) => { }, [analytics, onSignIn]) const fetchNotificationsState = () => { - setUserNotifications({ notifications, isLoading: true }) + setUserNotifications({ notifications: [], isLoading: true }) client.getNotifications() - .then((response) => { - const parsed = response.notifications.map(parseNotification) - - // check if needed to update notifications state - if(diff(notifications, parsed).length) { - setUserNotifications({ isLoading: false, notifications: parsed }) - } else { - setUserNotifications({ notifications, isLoading: false }) - } + .then((retrievedNotifications) => { + setUserNotifications({ isLoading: false, notifications: retrievedNotifications }) }) } @@ -160,12 +152,7 @@ export const UserInformation = (props: UserInformationProps) => { useEffect(() => { if (identity && withNotifications) { fetchNotificationsState() - } - }, [identity]) - - useEffect(() => { - if (identity && withNotifications) { const interval = setInterval(() => { fetchNotificationsState() }, NOTIFICATIONS_QUERY_INTERVAL) @@ -176,7 +163,7 @@ export const UserInformation = (props: UserInformationProps) => { } else { return () => {} } - }, [identity, notifications]) + }, [identity]) return ( }>(`/notifications${params.toString().length ? `?${params.toString()}` : ''}`) + const { notifications } = await this + .fetch<{notifications: Array}>(`/notifications${params.toString().length ? `?${params.toString()}` : ''}`) - return notificationsResponse + return notifications.map(parseNotification) } async markNotificationsAsRead(ids: string[]) { @@ -48,9 +49,9 @@ export const checkIsOnboarding = () => { } } -export const parseNotification = (notification: DCLNotification): DCLNotification => { +const parseNotification = (notification: DCLNotification): DCLNotification => { return ({ ...notification, - timestamp: Number(notification.timestamp) * 1000 + timestamp: Number(notification.timestamp) }) } \ No newline at end of file