Skip to content

Commit

Permalink
Merge pull request #751 from clrfund/feat/add-semaphore-user-registry
Browse files Browse the repository at this point in the history
Add semaphore user registry
  • Loading branch information
yuetloo authored Apr 25, 2024
2 parents 880e96b + 08dc551 commit 9ff8f87
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion vue-app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ VITE_SUBGRAPH_URL=http://localhost:8000/subgraphs/name/clrfund/clrfund

VITE_CLRFUND_ADDRESS=0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82

# Supported values: simple, brightid, snapshot, merkle
# Supported values: simple, brightid, snapshot, merkle, semaphore
VITE_USER_REGISTRY_TYPE=simple
# clr.fund (prod) or CLRFundTest (testing)
# Learn more about BrightID and context in /docs/brightid.md
Expand Down
7 changes: 6 additions & 1 deletion vue-app/src/api/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export enum UserRegistryType {
SIMPLE = 'simple',
SNAPSHOT = 'snapshot',
MERKLE = 'merkle',
SEMAPHORE = 'semaphore',
}

if (!Object.values(UserRegistryType).includes(userRegistryType as UserRegistryType)) {
Expand Down Expand Up @@ -92,7 +93,11 @@ export const showComplianceRequirement = /^yes$/i.test(import.meta.env.VITE_SHOW

export const isBrightIdRequired = userRegistryType === 'brightid'
export const isOptimisticRecipientRegistry = recipientRegistryType === 'optimistic'
export const isUserRegistrationRequired = userRegistryType !== UserRegistryType.SIMPLE
export const isUserRegistrationRequired = [
UserRegistryType.BRIGHT_ID,
UserRegistryType.MERKLE,
UserRegistryType.SNAPSHOT,
].includes(userRegistryType)

// Try to get the next scheduled start date
const nextStartDate = import.meta.env.VITE_NEXT_ROUND_START_DATE
Expand Down
4 changes: 2 additions & 2 deletions vue-app/src/components/CallToActionCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { computed } from 'vue'
import BrightIdWidget from '@/components/BrightIdWidget.vue'
import Links from '@/components/Links.vue'
import { userRegistryType, UserRegistryType, isBrightIdRequired } from '@/api/core'
import { isUserRegistrationRequired, isBrightIdRequired } from '@/api/core'
import { useAppStore, useUserStore } from '@/stores'
import { storeToRefs } from 'pinia'
Expand All @@ -69,7 +69,7 @@ const hasStartedVerification = computed(
)
const showUserVerification = computed(() => {
return (
userRegistryType !== UserRegistryType.SIMPLE &&
isUserRegistrationRequired &&
currentRound.value &&
currentUser.value?.isRegistered !== undefined &&
!currentUser.value.isRegistered
Expand Down
12 changes: 5 additions & 7 deletions vue-app/src/components/Cart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ import CartItems from '@/components/CartItems.vue'
import Links from '@/components/Links.vue'
import TimeLeft from '@/components/TimeLeft.vue'
import { MAX_CONTRIBUTION_AMOUNT, MAX_CART_SIZE, type CartItem, isContributionAmountValid } from '@/api/contributions'
import { userRegistryType, UserRegistryType, operator } from '@/api/core'
import { userRegistryType, UserRegistryType, operator, isUserRegistrationRequired } from '@/api/core'
import { RoundStatus } from '@/api/round'
import { formatAmount as _formatAmount } from '@/utils/amounts'
import FundsNeededWarning from '@/components/FundsNeededWarning.vue'
Expand Down Expand Up @@ -477,18 +477,16 @@ const isBrightIdRequired = computed(
() => userRegistryType === UserRegistryType.BRIGHT_ID && !currentUser.value?.isRegistered,
)
const isRegistrationRequired = computed(
() => userRegistryType !== UserRegistryType.SIMPLE && !currentUser.value?.isRegistered,
)
const isRegistrationRequired = computed(() => isUserRegistrationRequired && !currentUser.value?.isRegistered)
const errorMessage = computed<string | null>(() => {
if (isMessageLimitReached.value) return t('dynamic.cart.error.reached_contribution_limit')
if (!currentUser.value) return t('dynamic.cart.error.connect_wallet')
if (isBrightIdRequired.value) return t('dynamic.cart.error.need_to_setup_brightid')
if (!currentUser.value.isRegistered) {
return userRegistryType === UserRegistryType.SIMPLE
? t('dynamic.cart.error.user_not_registered', { operator })
: t('dynamic.cart.error.need_to_register')
return isUserRegistrationRequired
? t('dynamic.cart.error.need_to_register')
: t('dynamic.cart.error.user_not_registered', { operator })
}
if (!isFormValid()) return t('dynamic.cart.error.invalid_contribution_amount')
if (cart.value.length > MAX_CART_SIZE)
Expand Down

0 comments on commit 9ff8f87

Please sign in to comment.