Skip to content

Commit

Permalink
refactor: use semaphore v4 for on-chain groups
Browse files Browse the repository at this point in the history
re #565
  • Loading branch information
vplasencia committed Sep 29, 2024
1 parent 31cb89c commit 9a5fa12
Show file tree
Hide file tree
Showing 10 changed files with 513 additions and 166 deletions.
2 changes: 1 addition & 1 deletion apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@emotion/styled": "^11.10.6",
"@fontsource-variable/unbounded": "^5.0.5",
"@rainbow-me/rainbowkit": "^0.12.8",
"@semaphore-protocol/data": "patch:@semaphore-protocol/data@npm%3A3.10.0#~/.yarn/patches/@semaphore-protocol-data-npm-3.10.0-48e6c0f59e.patch",
"@semaphore-protocol/data": "4.0.3",
"ethers": "5.5.1",
"framer-motion": "^10.0.1",
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/components/add-member-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ ${memberIds.join("\n")}
try {
const semaphore = getSemaphoreContract("sepolia", signer as any)

await semaphore.addMembers(group.name, memberIds)
await semaphore.addMembers(group.id, memberIds)

setIsLoading(false)
onClose(memberIds)
Expand Down
10 changes: 8 additions & 2 deletions apps/dashboard/src/components/group-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ export default function GroupCard({
? icon2Image
: icon1Image
}
filter={treeDepth ? "inherit" : "grayscale(100%)"}
opacity={treeDepth ? "inherit" : ".4"}
filter={
treeDepth || type === "on-chain"
? "inherit"
: "grayscale(100%)"
}
opacity={
treeDepth || type === "on-chain" ? "inherit" : ".4"
}
htmlWidth="35px"
alt="Bandada icon"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { formatBytes32String } from "@ethersproject/strings"
import { getSemaphoreContract } from "@bandada/utils"
import { Box, Button, Heading, HStack, VStack } from "@chakra-ui/react"
import { useCallback, useState } from "react"
Expand Down Expand Up @@ -28,9 +27,13 @@ export default function FinalPreviewStep({
const semaphore = getSemaphoreContract("sepolia", signer as any)
const admin = await signer.getAddress()

await semaphore.createGroup(group.name, group.treeDepth, admin)
const receipt = await semaphore.createGroup(admin)

const groupIdBigNumber =
receipt.events?.[0]?.args?.[0].toString()

const groupId = groupIdBigNumber.toString()

const groupId = BigInt(formatBytes32String(group.name))
navigate(`/groups/on-chain/${groupId}`)
} catch (error) {
setLoading(false)
Expand Down Expand Up @@ -98,7 +101,7 @@ export default function FinalPreviewStep({
Back
</Button>
<Button
isDisabled={!group.treeDepth}
isDisabled={group.type === "off-chain" && !group.treeDepth}
variant="solid"
colorScheme="primary"
onClick={createGroup}
Expand Down
29 changes: 16 additions & 13 deletions apps/dashboard/src/pages/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,20 +373,23 @@ ${memberIds.join("\n")}
{shortenNumber(_group.members.length)}
</Heading>
</Box>
<Box
flex="1"
bgColor="balticSea.50"
p="25px 30px 12px 30px"
borderRadius="8px"
>
<Text fontSize="13px" color="balticSea.500">
MAX CAPACITY
</Text>
{groupType === "off-chain" && (
<Box
flex="1"
bgColor="balticSea.50"
p="25px 30px 12px 30px"
borderRadius="8px"
>
<Text fontSize="13px" color="balticSea.500">
MAX CAPACITY
</Text>

<Heading fontSize="31px">
{shortenNumber(2 ** _group.treeDepth)}
</Heading>
</Box>
)}

<Heading fontSize="31px">
{shortenNumber(2 ** _group.treeDepth)}
</Heading>
</Box>
<Box
flex="1"
bgColor="balticSea.50"
Expand Down
3 changes: 1 addition & 2 deletions apps/dashboard/src/pages/new-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export default function NewGroupPage(): JSX.Element {
/>

<HStack w="100%" align="start">
{(_group.type === "on-chain" && _currentStep !== 2) ||
(_group.type === "off-chain" && _currentStep !== 3) ? (
{_group.type === "off-chain" && _currentStep !== 3 ? (
<>
<StepperPreview group={_group} />

Expand Down
4 changes: 2 additions & 2 deletions libs/utils/src/contractAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { ContractName, Network } from "./types"
const CONTRACT_ADDRESSES: { [K in Network]: { [Y in ContractName]: string } } =
{
localhost: {
Semaphore: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
Semaphore: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
Bandada: "0x5fbdb2315678afecb367f032d93f642f64180aa3",
BandadaSemaphore: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"
},
sepolia: {
Semaphore: "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131",
Semaphore: "0x1e0d7FF1610e480fC93BdEC510811ea2Ba6d7c2f",
Bandada: "0xD2873C967079D8B1eAd9dc86B8F8f3948e29564E",
BandadaSemaphore: "0x35ce7AFd20b031b4EEa83748D15f319Be9378d2C"
}
Expand Down
Loading

0 comments on commit 9a5fa12

Please sign in to comment.