Skip to content

Commit

Permalink
feat(client): add getMultipleCredentialsGroupJoinUrl api sdk to client
Browse files Browse the repository at this point in the history
  • Loading branch information
waddaboo committed Dec 4, 2024
1 parent 1e90130 commit 4ac5088
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
32 changes: 22 additions & 10 deletions apps/client/src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getCredentialGroupJoinUrl,
getGroup,
getInvite,
getMultipleCredentialsGroupJoinUrl,
isGroupMember
} from "../utils/api"

Expand Down Expand Up @@ -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.`
Expand All @@ -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")
Expand Down
24 changes: 24 additions & 0 deletions apps/client/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 4ac5088

Please sign in to comment.