Skip to content

Commit

Permalink
Fixes census3 creation attemts to 100 (#617)
Browse files Browse the repository at this point in the history
* Fixes census3 census creation attemts to 100
* Remove unnecessary calculation + resort imports

---------

Co-authored-by: Òscar Casajuana <elboletaire@gmail.com>
  • Loading branch information
emmdim and elboletaire committed Apr 2, 2024
1 parent 526d009 commit 0988c92
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/components/ProcessCreate/Steps/Confirm.tsx
Expand Up @@ -19,7 +19,6 @@ import {
import { Button } from '@vocdoni/chakra-components'
import { ElectionProvider, errorToString, useClient } from '@vocdoni/react-providers'
import {
CensusType as VocdoniCensusType,
CspCensus,
Election,
ElectionCreationSteps,
Expand All @@ -35,13 +34,17 @@ import {
StrategyToken,
UnpublishedElection,
VocdoniCensus3Client,
CensusType as VocdoniCensusType,
WeightedCensus,
} from '@vocdoni/sdk'
import { useEffect, useMemo, useState } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import { Trans, useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom'
import { IElection, IElectionWithTokenResponse } from 'vocdoni-admin-sdk'
import { StampsUnionTypes } from '~components/ProcessCreate/Census/Gitcoin/StampsUnionType'
import { CensusType } from '~components/ProcessCreate/Census/TypeSelector'
import { CensusGitcoinValues } from '~components/ProcessCreate/StepForm/CensusGitcoin'
import { useCspAdmin } from '../Census/Csp/use-csp'
import Preview from '../Confirm/Preview'
import { CostPreview } from '../CostPreview'
Expand All @@ -50,9 +53,6 @@ import { Web3Address } from '../StepForm/CensusWeb3'
import { Option } from '../StepForm/Questions'
import { StepsFormValues, useProcessCreationSteps } from './use-steps'
import Wrapper from './Wrapper'
import { StampsUnionTypes } from '~components/ProcessCreate/Census/Gitcoin/StampsUnionType'
import { CensusGitcoinValues } from '~components/ProcessCreate/StepForm/CensusGitcoin'
import { CensusType } from '~components/ProcessCreate/Census/TypeSelector'

export const Confirm = () => {
const { env, client, account, fetchAccount } = useClient()
Expand Down Expand Up @@ -343,20 +343,17 @@ const getCensus = async (env: EnvOptions, form: StepsFormValues, salt: string) =
})

const retryTime = 5000
let attempts = form.timeToCreateCensus / retryTime

c3client.queueWait.retryTime = retryTime
// clamp attempts between 20 and 100
c3client.queueWait.attempts = Math.min(Math.max(Math.ceil(attempts), 20), 100)
c3client.queueWait.attempts = 100

if (form.censusType === 'gitcoin') {
// Calculate the strategy id
const strategyID = await getGitcoinStrategyId(form, c3client)

// Once strategy is created, we got the stimation again to update the awaiting time
const { timeToCreateCensus } = await c3client.getStrategyEstimation(strategyID, form.electionType.anonymous)
attempts = timeToCreateCensus / retryTime
c3client.queueWait.attempts = Math.min(Math.max(Math.ceil(attempts), 20), 100)
c3client.queueWait.attempts = 100

// Create the census
const census = await c3client.createCensus(strategyID, form.electionType.anonymous)
Expand Down Expand Up @@ -497,7 +494,7 @@ const getGitcoinStrategyId = async (form: CensusGitcoinValues, c3client: Vocdoni
if (form.gpsWeighted) {
predicate = `${scoreToken.symbol}`
} else {
predicate = `${scoreToken.symbol} OR ${scoreToken.symbol}`
predicate = `${scoreToken.symbol} AND ${scoreToken.symbol}`
}
} else {
predicate = `${scoreToken.symbol} ${predicate}`
Expand Down

3 comments on commit 0988c92

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.