Skip to content

Commit

Permalink
feat(dashboard): add remove on-chain/associated group member
Browse files Browse the repository at this point in the history
  • Loading branch information
waddaboo committed Oct 24, 2024
1 parent 033d585 commit ebdd85d
Showing 1 changed file with 45 additions and 22 deletions.
67 changes: 45 additions & 22 deletions apps/dashboard/src/pages/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { useSigner } from "wagmi"
import { getSemaphoreContract } from "@bandada/utils"
import { Group as Semaphorev4Group } from "@semaphore-protocol/core"
import * as bandadaApi from "../api/bandadaAPI"
import { getGroup as getOnchainGroup } from "../api/semaphoreAPI"
import * as semaphoreApi from "../api/semaphoreAPI"
import image1 from "../assets/image1.svg"
import AddMemberModal from "../components/add-member-modal"
import { Group } from "../types"
Expand Down Expand Up @@ -75,7 +75,7 @@ export default function GroupPage(): JSX.Element {
if (groupId) {
const group =
groupType === "on-chain"
? await getOnchainGroup(groupId)
? await semaphoreApi.getAssociatedGroup(groupId)
: await bandadaApi.getGroup(groupId)

if (group === null) {
Expand Down Expand Up @@ -161,32 +161,55 @@ export default function GroupPage(): JSX.Element {
return
}

try {
const semaphore = getSemaphoreContract(
"sepolia",
signer as any
)
const semaphoreGroup = await semaphoreApi.getGroup(_group!.id)

const semaphorev4Group = new Semaphorev4Group(
_group!.members
)
if (
semaphoreGroup &&
semaphoreGroup.members.includes(memberId)
) {
try {
const semaphore = getSemaphoreContract(
"sepolia",
signer as any
)

const index = semaphorev4Group.indexOf(memberId)
const semaphorev4Group = new Semaphorev4Group(
_group!.members
)

const merkleProof =
semaphorev4Group.generateMerkleProof(index)
const index = semaphorev4Group.indexOf(memberId)

await semaphore.removeMember(
_group!.id,
memberId,
merkleProof.siblings
)
} catch (error) {
alert(
"Some error occurred! Check if you're on Sepolia network and the transaction is signed and completed"
const merkleProof =
semaphorev4Group.generateMerkleProof(index)

await semaphore.removeMember(
_group!.id,
memberId,
merkleProof.siblings
)
} catch (error) {
alert(
"Some error occurred! Check if you're on Sepolia network and the transaction is signed and completed"
)
return
}
}

const associatedGroup = await bandadaApi.getGroupByName(
_group!.name
)

if (
associatedGroup &&
associatedGroup.length > 0 &&
associatedGroup[0].members.includes(memberId)
) {
await bandadaApi.removeMember(
associatedGroup[0].id,
memberId
)
return
}

_group!.members = _group!.members.map((m) =>
m !== memberId ? m : "0"
)
Expand Down

0 comments on commit ebdd85d

Please sign in to comment.