diff --git a/apps/client/src/pages/home.tsx b/apps/client/src/pages/home.tsx index 82eab3f2..43886d43 100644 --- a/apps/client/src/pages/home.tsx +++ b/apps/client/src/pages/home.tsx @@ -20,8 +20,11 @@ import { useSearchParams } from "react-router-dom" import icon1Image from "../assets/icon1.svg" import { addMemberByInviteCode, + DashboardUrl, + getCredentialGroupJoinUrl, getGroup, getInvite, + getMultipleCredentialsGroupJoinUrl, isGroupMember } from "../utils/api" @@ -119,21 +122,39 @@ 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.` const identity = new Identity(await signer.signMessage(message)) const identityCommitment = identity.getCommitment().toString() - window.open( - `${ - import.meta.env.VITE_DASHBOARD_URL - }/credentials?group=${groupId}&member=${identityCommitment}&provider=${providerName}` - ) + const dashboardUrl = import.meta.env + .VITE_DASHBOARD_URL as DashboardUrl + + 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") + } setLoading(false) } diff --git a/apps/client/src/utils/api.ts b/apps/client/src/utils/api.ts index 49aba4d2..b7c36ff6 100644 --- a/apps/client/src/utils/api.ts +++ b/apps/client/src/utils/api.ts @@ -1,7 +1,9 @@ -import { ApiSdk, Group, Invite } from "@bandada/api-sdk" +import { ApiSdk, DashboardUrl, Group, Invite } from "@bandada/api-sdk" const api = new ApiSdk(import.meta.env.VITE_API_URL) +export { DashboardUrl } + export async function getInvite(inviteCode: string): Promise { try { return await api.getInvite(inviteCode) @@ -72,3 +74,55 @@ export async function addMemberByInviteCode( return null } } + +export function getCredentialGroupJoinUrl( + dashboardUrl: DashboardUrl, + groupId: string, + commitment: string, + providerName: string, + redirectUri?: string +): string | null { + try { + return api.getCredentialGroupJoinUrl( + dashboardUrl, + groupId, + commitment, + providerName, + redirectUri + ) + } catch (error: any) { + console.error(error) + + if (error.response) { + alert(error.response.statusText) + } else { + alert("Some error occurred!") + } + + 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 + } +}