Skip to content

Commit

Permalink
Merge pull request #615 from bandada-infra/feat/client/credential-gro…
Browse files Browse the repository at this point in the history
…up-api-sdk

feat(client): use API SDK for credential group and multiple credentials group
  • Loading branch information
vplasencia authored Dec 5, 2024
2 parents c299b60 + 4ac5088 commit 48c539a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 10 deletions.
39 changes: 30 additions & 9 deletions apps/client/src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}
Expand Down
56 changes: 55 additions & 1 deletion apps/client/src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -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<Invite | null> {
try {
return await api.getInvite(inviteCode)
Expand Down Expand Up @@ -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
}
}

0 comments on commit 48c539a

Please sign in to comment.