From 17602b736608c87d57c90f934b971cf604ada679 Mon Sep 17 00:00:00 2001 From: waddaboo <56923450+waddaboo@users.noreply.github.com> Date: Tue, 3 Dec 2024 22:43:17 +0800 Subject: [PATCH 1/3] feat(client): add getCredentialGroupJoinUrl to client api --- apps/client/src/utils/api.ts | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/apps/client/src/utils/api.ts b/apps/client/src/utils/api.ts index 49aba4d2..3fa1e3a2 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,31 @@ 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 + } +} From 1e9013049a3254011359e156b851ea08883f72e5 Mon Sep 17 00:00:00 2001 From: waddaboo <56923450+waddaboo@users.noreply.github.com> Date: Tue, 3 Dec 2024 22:50:10 +0800 Subject: [PATCH 2/3] feat(client): replace redirect to use api sdk --- apps/client/src/pages/home.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/client/src/pages/home.tsx b/apps/client/src/pages/home.tsx index 82eab3f2..57b0b380 100644 --- a/apps/client/src/pages/home.tsx +++ b/apps/client/src/pages/home.tsx @@ -20,6 +20,8 @@ import { useSearchParams } from "react-router-dom" import icon1Image from "../assets/icon1.svg" import { addMemberByInviteCode, + DashboardUrl, + getCredentialGroupJoinUrl, getGroup, getInvite, isGroupMember @@ -129,12 +131,19 @@ export default function HomePage(): JSX.Element { 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 + const credentialGroupJoinUrl = getCredentialGroupJoinUrl( + dashboardUrl, + groupId, + identityCommitment, + providerName ) + if (credentialGroupJoinUrl) { + window.open(credentialGroupJoinUrl, "_blank") + } + setLoading(false) } }, 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 3/3] 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 + } +}