Skip to content

Commit

Permalink
🐛 [FIX]: GetMember :Error: [useGetMembers, null] data is undefined (#…
Browse files Browse the repository at this point in the history
…7561)

[FIX]: GetMember :Error: [useGetMembers, null] data is undefined
  • Loading branch information
mcayuelas-ledger authored Aug 9, 2024
1 parent fa795d7 commit 1fb2b90
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changeset/eighty-rabbits-hope.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -32,6 +36,7 @@ export function useGetMembers() {
refetchOnReconnect: true,
refetchOnWindowFocus: true,
retry: false,
enabled: !!trustchain && !!memberCredentials,
});

useEffect(() => {
Expand Down
4 changes: 4 additions & 0 deletions apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions apps/ledger-live-mobile/src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -25,7 +20,7 @@ export function useGetMembers() {
}

if (!trustchain) {
throw new TrustchainNotFound(t("walletSync.walletSyncActivated.errors.trustchain"));
throw new TrustchainNotFound();
}

try {
Expand All @@ -42,6 +37,7 @@ export function useGetMembers() {
refetchOnReconnect: true,
refetchOnWindowFocus: true,
retry: false,
enabled: !!trustchain && !!memberCredentials,
});

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions libs/trustchain/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

0 comments on commit 1fb2b90

Please sign in to comment.