From 1fb2b909c5d97e373a0f72baa37578132bd8b24a Mon Sep 17 00:00:00 2001 From: Martin CAYUELAS <112866305+mcayuelas-ledger@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:00:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20[FIX]:=20GetMember=20:Error:=20[?= =?UTF-8?q?useGetMembers,=20null]=20data=20is=20undefined=20(#7561)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [FIX]: GetMember :Error: [useGetMembers, null] data is undefined --- .changeset/eighty-rabbits-hope.md | 7 +++++++ .../newArch/features/WalletSync/hooks/useGetMembers.ts | 9 +++++++-- apps/ledger-live-desktop/static/i18n/en/app.json | 4 ++++ apps/ledger-live-mobile/src/locales/en/common.json | 4 ++++ .../newArch/features/WalletSync/hooks/useGetMembers.ts | 10 +++------- .../features/WalletSync/screens/Manage/index.tsx | 2 +- libs/trustchain/src/errors.ts | 1 + 7 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 .changeset/eighty-rabbits-hope.md diff --git a/.changeset/eighty-rabbits-hope.md b/.changeset/eighty-rabbits-hope.md new file mode 100644 index 000000000000..3d0690b9193b --- /dev/null +++ b/.changeset/eighty-rabbits-hope.md @@ -0,0 +1,7 @@ +--- +"ledger-live-desktop": patch +"live-mobile": patch +"@ledgerhq/trustchain": patch +--- + +Fix get Members errors GetMember :Error: ["useGetMembers", null] data is undefined diff --git a/apps/ledger-live-desktop/src/newArch/features/WalletSync/hooks/useGetMembers.ts b/apps/ledger-live-desktop/src/newArch/features/WalletSync/hooks/useGetMembers.ts index 6d48b83adb4e..e1e6bf0befc9 100644 --- a/apps/ledger-live-desktop/src/newArch/features/WalletSync/hooks/useGetMembers.ts +++ b/apps/ledger-live-desktop/src/newArch/features/WalletSync/hooks/useGetMembers.ts @@ -5,6 +5,7 @@ import { QueryKey } from "./type.hooks"; import { useQuery } from "@tanstack/react-query"; import { useEffect } from "react"; import { useLifeCycle } from "./walletSync.hooks"; +import { TrustchainNotFound } from "@ledgerhq/trustchain/errors"; export function useGetMembers() { const sdk = useTrustchainSdk(); @@ -13,8 +14,11 @@ export function useGetMembers() { const errorHandler = useLifeCycle(); function fetchMembers() { - if (!trustchain || !memberCredentials) { - throw new Error("Trustchain or MemberCredentials is falsy"); + if (!memberCredentials) { + return; + } + if (!trustchain) { + throw new TrustchainNotFound(); } return sdk.getMembers(trustchain, memberCredentials); @@ -32,6 +36,7 @@ export function useGetMembers() { refetchOnReconnect: true, refetchOnWindowFocus: true, retry: false, + enabled: !!trustchain && !!memberCredentials, }); useEffect(() => { diff --git a/apps/ledger-live-desktop/static/i18n/en/app.json b/apps/ledger-live-desktop/static/i18n/en/app.json index 0a6bf90803e9..b869b58c0098 100644 --- a/apps/ledger-live-desktop/static/i18n/en/app.json +++ b/apps/ledger-live-desktop/static/i18n/en/app.json @@ -5670,6 +5670,10 @@ "title": "Something went wrong. Please reconnect your device", "description": "{{message}}" }, + "TrustchainNotFound": { + "title": "Something went wrong while fetching your data", + "description": "Please try again or contact Ledger Support." + }, "DeviceShouldStayInApp": { "title": "Please open the {{appName}} app", "description": "Keep the {{appName}} app open while we find your accounts" diff --git a/apps/ledger-live-mobile/src/locales/en/common.json b/apps/ledger-live-mobile/src/locales/en/common.json index 791f715863b4..1a0fc7591c72 100644 --- a/apps/ledger-live-mobile/src/locales/en/common.json +++ b/apps/ledger-live-mobile/src/locales/en/common.json @@ -937,6 +937,10 @@ "title": "Sorry, try again.", "description": "The server could not handle your request. Please try again later or contact Ledger Support.", "errorCode": "Code: {{errorCode}}" + }, + "TrustchainNotFound": { + "title": "Something went wrong while fetching your data", + "description": "Please try again or contact Ledger Support." } }, "crash": { diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useGetMembers.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useGetMembers.ts index ac429cbfe9b9..2464a8b3694d 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useGetMembers.ts +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useGetMembers.ts @@ -3,19 +3,14 @@ import { useSelector } from "react-redux"; import { useTrustchainSdk } from "./useTrustchainSdk"; import { useQuery } from "@tanstack/react-query"; import { QueryKey } from "./type.hooks"; -import { useTranslation } from "react-i18next"; -import { createCustomErrorClass } from "@ledgerhq/errors"; import { useLifeCycle } from "./walletSync.hooks"; import { useEffect } from "react"; - -export const TrustchainNotFound = createCustomErrorClass("TrustchainNotFound"); -export const MemberCredentialsNotFound = createCustomErrorClass("MemberCredentialsNotFound"); +import { TrustchainNotFound } from "@ledgerhq/trustchain/errors"; export function useGetMembers() { const sdk = useTrustchainSdk(); const trustchain = useSelector(trustchainSelector); const memberCredentials = useSelector(memberCredentialsSelector); - const { t } = useTranslation(); const errorHandler = useLifeCycle(); @@ -25,7 +20,7 @@ export function useGetMembers() { } if (!trustchain) { - throw new TrustchainNotFound(t("walletSync.walletSyncActivated.errors.trustchain")); + throw new TrustchainNotFound(); } try { @@ -42,6 +37,7 @@ export function useGetMembers() { refetchOnReconnect: true, refetchOnWindowFocus: true, retry: false, + enabled: !!trustchain && !!memberCredentials, }); useEffect(() => { diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Manage/index.tsx b/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Manage/index.tsx index 4ac54b862850..eb25be020b4b 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Manage/index.tsx +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Manage/index.tsx @@ -10,7 +10,6 @@ import { } from "../../hooks/useLedgerSyncAnalytics"; import { Separator } from "../../components/Separator"; import { TouchableOpacity } from "react-native"; -import { TrustchainNotFound } from "../../hooks/useGetMembers"; import ManageKeyDrawer from "../ManageKey/ManageKeyDrawer"; import { useManageKeyDrawer } from "../ManageKey/useManageKeyDrawer"; import ManageInstanceDrawer from "../ManageInstances/ManageInstancesDrawer"; @@ -20,6 +19,7 @@ import { Steps } from "../../types/Activation"; import { TrackScreen } from "~/analytics"; import { AlertLedgerSyncDown } from "../../components/AlertLedgerSyncDown"; import { useLedgerSyncStatus } from "../../hooks/useLedgerSyncStatus"; +import { TrustchainNotFound } from "@ledgerhq/trustchain/errors"; const WalletSyncManage = () => { const { t } = useTranslation(); diff --git a/libs/trustchain/src/errors.ts b/libs/trustchain/src/errors.ts index 6ee9dccb4cc3..9bb8eac49168 100644 --- a/libs/trustchain/src/errors.ts +++ b/libs/trustchain/src/errors.ts @@ -5,3 +5,4 @@ export const InvalidEncryptionKeyError = createCustomErrorClass("InvalidEncrypti export const TrustchainEjected = createCustomErrorClass("TrustchainEjected"); export const TrustchainNotAllowed = createCustomErrorClass("TrustchainNotAllowed"); export const TrustchainOutdated = createCustomErrorClass("TrustchainOutdated"); +export const TrustchainNotFound = createCustomErrorClass("TrustchainNotFound");