-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
912 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
packages/interface/src/features/admin/components/DeployContracts.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { useRouter } from "next/router"; | ||
import { useState, useCallback } from "react"; | ||
import { toast } from "sonner"; | ||
import { useAccount } from "wagmi"; | ||
|
||
import { Steps } from "~/components/Steps"; | ||
import { Form, FormSection, FormControl, Select } from "~/components/ui/Form"; | ||
import { Heading } from "~/components/ui/Heading"; | ||
import { DeploymentSchema, chainTypes, gatingStrategyTypes } from "~/features/rounds/types"; | ||
import { useIsCorrectNetwork } from "~/hooks/useIsCorrectNetwork"; | ||
|
||
import { useDeployContracts } from "../hooks/useDeployContracts"; | ||
|
||
import { EDeployContractsStep, DeployContractsButtons } from "./DeployContractsButtons"; | ||
import { ReviewDeployContractsDetails } from "./ReviewDeployContractsDetails"; | ||
import { VoiceCreditProxySelect } from "./VoiceCreditProxySelect"; | ||
|
||
export const DeployContracts = (): JSX.Element => { | ||
const router = useRouter(); | ||
const [step, setStep] = useState<EDeployContractsStep>(EDeployContractsStep.CONFIGURE); | ||
|
||
const { isCorrectNetwork, correctNetwork } = useIsCorrectNetwork(); | ||
|
||
const { address } = useAccount(); | ||
|
||
const handleNextStep = useCallback(() => { | ||
if (step === EDeployContractsStep.CONFIGURE) { | ||
setStep(EDeployContractsStep.REVIEW); | ||
} | ||
}, [step, setStep]); | ||
|
||
const handleBackStep = useCallback(() => { | ||
if (step === EDeployContractsStep.REVIEW) { | ||
setStep(EDeployContractsStep.CONFIGURE); | ||
} | ||
}, [step, setStep]); | ||
|
||
const create = useDeployContracts({ | ||
onSuccess: () => { | ||
router.push(`/`); | ||
}, | ||
onError: (err: Error) => | ||
toast.error("Contracts deploy error", { | ||
description: err.message, | ||
}), | ||
}); | ||
|
||
const { error: createError } = create; | ||
|
||
return ( | ||
<div> | ||
<Heading size="4xl">Deploy Core Contracts</Heading> | ||
|
||
<p className="text-gray-400">These initial MACI core contracts configuration will apply to all future rounds.</p> | ||
|
||
<div className="dark:border-lighterBlack rounded-lg border border-gray-200 p-4"> | ||
<Steps step={step} stepNames={["Configure Contracts", "Review & Deploy"]} /> | ||
|
||
<Form | ||
schema={DeploymentSchema} | ||
onSubmit={(round) => { | ||
create.mutate(round); | ||
}} | ||
> | ||
<FormSection | ||
className={step === EDeployContractsStep.CONFIGURE ? "block" : "hidden"} | ||
description="Please select from the available options:" | ||
title="Configure Contracts" | ||
> | ||
<FormControl required hint="Choose a chain to deploy your contracts" label="Chain to deploy" name="chain"> | ||
<Select> | ||
{Object.entries(chainTypes).map(([value, label]) => ( | ||
<option key={value} value={value}> | ||
{label} | ||
</option> | ||
))} | ||
</Select> | ||
</FormControl> | ||
|
||
<FormControl required hint="Choose a gating strategy" label="Gating strategy" name="gatingStrategy"> | ||
<Select> | ||
{Object.entries(gatingStrategyTypes).map(([value, label]) => ( | ||
<option key={value} value={label}> | ||
{label} | ||
</option> | ||
))} | ||
</Select> | ||
</FormControl> | ||
|
||
<VoiceCreditProxySelect /> | ||
</FormSection> | ||
|
||
{step === EDeployContractsStep.REVIEW && <ReviewDeployContractsDetails />} | ||
|
||
{step === EDeployContractsStep.REVIEW && ( | ||
<div className="mb-2 w-full text-right text-sm italic text-blue-400"> | ||
{!address && <p>You must connect wallet to create an application</p>} | ||
|
||
{!isCorrectNetwork && <p className="gap-2">You must be connected to {correctNetwork.name}</p>} | ||
|
||
{createError && ( | ||
<p> | ||
Make sure you're not connected to a VPN since this can cause problems with the RPC and your | ||
wallet. | ||
</p> | ||
)} | ||
</div> | ||
)} | ||
|
||
<DeployContractsButtons | ||
isPending={create.isPending} | ||
isUploading={create.isPending} | ||
step={step} | ||
onBackStep={handleBackStep} | ||
onNextStep={handleNextStep} | ||
/> | ||
</Form> | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.