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 + } +}