From 4ac5088109427d874771c11e2fc66db0b3bbcd16 Mon Sep 17 00:00:00 2001 From: waddaboo <56923450+waddaboo@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:55:08 +0800 Subject: [PATCH] feat(client): add getMultipleCredentialsGroupJoinUrl api sdk to client --- apps/client/src/pages/home.tsx | 32 ++++++++++++++++++++++---------- apps/client/src/utils/api.ts | 24 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/apps/client/src/pages/home.tsx b/apps/client/src/pages/home.tsx index 57b0b380..43886d43 100644 --- a/apps/client/src/pages/home.tsx +++ b/apps/client/src/pages/home.tsx @@ -24,6 +24,7 @@ import { getCredentialGroupJoinUrl, getGroup, getInvite, + getMultipleCredentialsGroupJoinUrl, isGroupMember } from "../utils/api" @@ -121,10 +122,6 @@ export default function HomePage(): JSX.Element { return } - const providerName = group.credentials.id - .split("_")[0] - .toLowerCase() - const signer = library.getSigner(account) const message = `Sign this message to generate your Semaphore identity.` @@ -133,12 +130,27 @@ export default function HomePage(): JSX.Element { const dashboardUrl = import.meta.env .VITE_DASHBOARD_URL as DashboardUrl - const credentialGroupJoinUrl = getCredentialGroupJoinUrl( - dashboardUrl, - groupId, - identityCommitment, - providerName - ) + + let credentialGroupJoinUrl + + if (Array.isArray(group.credentials.credentials)) { + credentialGroupJoinUrl = getMultipleCredentialsGroupJoinUrl( + dashboardUrl, + groupId, + identityCommitment + ) + } else { + const providerName = group.credentials.id + .split("_")[0] + .toLowerCase() + + credentialGroupJoinUrl = getCredentialGroupJoinUrl( + dashboardUrl, + groupId, + identityCommitment, + providerName + ) + } if (credentialGroupJoinUrl) { window.open(credentialGroupJoinUrl, "_blank") diff --git a/apps/client/src/utils/api.ts b/apps/client/src/utils/api.ts index 3fa1e3a2..b7c36ff6 100644 --- a/apps/client/src/utils/api.ts +++ b/apps/client/src/utils/api.ts @@ -102,3 +102,27 @@ export function getCredentialGroupJoinUrl( return null } } + +export function getMultipleCredentialsGroupJoinUrl( + dashboardUrl: DashboardUrl, + groupId: string, + commitment: string +): string | null { + try { + return api.getMultipleCredentialsGroupJoinUrl( + dashboardUrl, + groupId, + commitment + ) + } catch (error: any) { + console.error(error) + + if (error.response) { + alert(error.response.statusText) + } else { + alert("Some error occurred!") + } + + return null + } +}