-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] : Get members from trustchain (#7387)
- Loading branch information
1 parent
0a1011e
commit fc0474e
Showing
8 changed files
with
128 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"live-mobile": patch | ||
--- | ||
|
||
Add Banner when error throws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"live-mobile": patch | ||
--- | ||
|
||
Get members of trutchain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/type.hooks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum QueryKey { | ||
getMembers = "useGetMembers", | ||
} |
44 changes: 44 additions & 0 deletions
44
apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useGetMembers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { memberCredentialsSelector, trustchainSelector } from "@ledgerhq/trustchain/store"; | ||
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"; | ||
|
||
export const TrustchainNotFound = createCustomErrorClass("TrustchainNotFound"); | ||
export const MemberCredentialsNotFound = createCustomErrorClass("MemberCredentialsNotFound"); | ||
|
||
export function useGetMembers() { | ||
const sdk = useTrustchainSdk(); | ||
const trustchain = useSelector(trustchainSelector); | ||
const memberCredentials = useSelector(memberCredentialsSelector); | ||
const { t } = useTranslation(); | ||
|
||
function getMembers() { | ||
if (!memberCredentials) { | ||
throw new MemberCredentialsNotFound( | ||
t("walletSync.walletSyncActivated.errors.memberCredentials"), | ||
); | ||
} | ||
|
||
if (!trustchain) { | ||
throw new TrustchainNotFound(t("walletSync.walletSyncActivated.errors.trustchain")); | ||
} | ||
|
||
try { | ||
return sdk.getMembers(trustchain, memberCredentials); | ||
} catch (e) { | ||
throw e as Error; | ||
} | ||
} | ||
|
||
return useQuery({ | ||
queryKey: [QueryKey.getMembers, trustchain], | ||
queryFn: () => getMembers(), | ||
refetchOnMount: true, | ||
refetchOnReconnect: true, | ||
refetchOnWindowFocus: true, | ||
retry: false, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters