-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OC add and adapt to Grant Engagement (#219)
* Changes main address * Adapt Dso to Oc * Add storage for oc proposals contract * Add OC proposals contract address to Provider * Adapt undefined votes for dso * Add proposal for Grant Engagement * Remove WhitelistPair and add GrantEngagement * Add grant detail. Adapt to 2 proposal contracts * Adapt table to 2 proposal contracts. Check isVoting
- Loading branch information
Showing
16 changed files
with
340 additions
and
331 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
13 changes: 0 additions & 13 deletions
13
...onents/ConfirmationWhitelistPair/style.ts → ...ents/ConfirmationGrantEngagement/style.ts
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
79 changes: 79 additions & 0 deletions
79
...ProposalModal/components/ProposalGrantEngagement/components/FormGrantEngagement/index.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,79 @@ | ||
import BackButtonOrLink from "App/components/BackButtonOrLink"; | ||
import Button from "App/components/Button"; | ||
import Field from "App/components/Field"; | ||
import Stack from "App/components/Stack/style"; | ||
import { Formik } from "formik"; | ||
import { Form } from "formik-antd"; | ||
import { getFormItemName } from "utils/forms"; | ||
import * as Yup from "yup"; | ||
|
||
import { ButtonGroup, Separator } from "./style"; | ||
|
||
const memberLabel = "Member to grant Engagements Points to"; | ||
const pointsLabel = "Number of Engagement Points"; | ||
const commentLabel = "Comment"; | ||
|
||
const validationSchema = Yup.object().shape({ | ||
[getFormItemName(memberLabel)]: Yup.string() | ||
.typeError("Address must be alphanumeric") | ||
.required("Member is required"), | ||
[getFormItemName(pointsLabel)]: Yup.number() | ||
.typeError("Engagement Points must be numeric") | ||
.required("Engagement Points are required"), | ||
[getFormItemName(commentLabel)]: Yup.string().typeError("Comment must be alphanumeric"), | ||
}); | ||
|
||
export interface FormGrantEngagementValues { | ||
readonly member: string; | ||
readonly points: string; | ||
readonly comment: string; | ||
} | ||
|
||
interface FormGrantEngagementProps extends FormGrantEngagementValues { | ||
readonly goBack: () => void; | ||
readonly handleSubmit: (values: FormGrantEngagementValues) => void; | ||
} | ||
|
||
export default function FormGrantEngagement({ | ||
member, | ||
comment, | ||
goBack, | ||
handleSubmit, | ||
}: FormGrantEngagementProps): JSX.Element { | ||
return ( | ||
<Formik | ||
initialValues={{ | ||
[getFormItemName(memberLabel)]: member, | ||
[getFormItemName(commentLabel)]: comment, | ||
}} | ||
enableReinitialize | ||
validationSchema={validationSchema} | ||
onSubmit={(values) => | ||
handleSubmit({ | ||
member: values[getFormItemName(memberLabel)], | ||
points: values[getFormItemName(pointsLabel)], | ||
comment: values[getFormItemName(commentLabel)], | ||
}) | ||
} | ||
> | ||
{({ isValid, submitForm }) => ( | ||
<> | ||
<Form> | ||
<Stack gap="s1"> | ||
<Field label={memberLabel} placeholder="Enter address" /> | ||
<Field label={pointsLabel} placeholder="Enter points" /> | ||
<Field label={commentLabel} placeholder="Enter comment" optional /> | ||
<Separator /> | ||
<ButtonGroup> | ||
<BackButtonOrLink onClick={() => goBack()} text="Back" /> | ||
<Button disabled={!isValid} onClick={() => submitForm()}> | ||
<div>Create proposal</div> | ||
</Button> | ||
</ButtonGroup> | ||
</Stack> | ||
</Form> | ||
</> | ||
)} | ||
</Formik> | ||
); | ||
} |
17 changes: 10 additions & 7 deletions
17
...air/components/FormWhitelistPair/style.ts → ...t/components/FormGrantEngagement/style.ts
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
98 changes: 98 additions & 0 deletions
98
src/App/components/OcCreateProposalModal/components/ProposalGrantEngagement/index.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,98 @@ | ||
import { TxResult } from "App/components/ShowTxResult"; | ||
import { useState } from "react"; | ||
import { useError, useOc, useSdk } from "service"; | ||
import { DsoContract } from "utils/dso"; | ||
import { getErrorFromStackTrace } from "utils/errors"; | ||
|
||
import { ProposalStep, ProposalType } from "../.."; | ||
import ConfirmationGrantEngagement from "./components/ConfirmationGrantEngagement"; | ||
import FormGrantEngagement, { FormGrantEngagementValues } from "./components/FormGrantEngagement"; | ||
|
||
interface ProposalGrantEngagementProps { | ||
readonly proposalStep: ProposalStep; | ||
readonly setProposalStep: React.Dispatch<React.SetStateAction<ProposalStep | undefined>>; | ||
readonly isSubmitting: boolean; | ||
readonly setSubmitting: React.Dispatch<React.SetStateAction<boolean>>; | ||
readonly setTxResult: React.Dispatch<React.SetStateAction<TxResult | undefined>>; | ||
} | ||
|
||
export default function ProposalGrantEngagement({ | ||
proposalStep, | ||
setProposalStep, | ||
isSubmitting, | ||
setSubmitting, | ||
setTxResult, | ||
}: ProposalGrantEngagementProps): JSX.Element { | ||
const { handleError } = useError(); | ||
const { | ||
sdkState: { address, signingClient, config }, | ||
} = useSdk(); | ||
const { | ||
ocState: { ocProposalsAddress }, | ||
} = useOc(); | ||
|
||
const [member, setMember] = useState(""); | ||
const [points, setPoints] = useState(""); | ||
const [comment, setComment] = useState(""); | ||
|
||
async function submitGrantEngagement({ member, points, comment }: FormGrantEngagementValues) { | ||
setMember(member); | ||
setPoints(points); | ||
setComment(comment); | ||
setProposalStep({ type: ProposalType.GrantEngagement, confirmation: true }); | ||
} | ||
|
||
async function submitCreateProposal() { | ||
if (!ocProposalsAddress || !signingClient || !address) return; | ||
setSubmitting(true); | ||
|
||
try { | ||
const dsoContract = new DsoContract(ocProposalsAddress, signingClient, config.gasPrice); | ||
const transactionHash = await dsoContract.propose( | ||
signingClient, | ||
config.factoryAddress, | ||
address, | ||
comment, | ||
{ | ||
grant_engagement: { | ||
member, | ||
points: parseInt(points, 10), | ||
}, | ||
}, | ||
); | ||
|
||
setTxResult({ | ||
msg: `Created proposal for granting Engagement Points from Oversight Community Proposals (${ocProposalsAddress}). Transaction ID: ${transactionHash}`, | ||
}); | ||
} catch (error) { | ||
if (!(error instanceof Error)) return; | ||
setTxResult({ error: getErrorFromStackTrace(error) }); | ||
handleError(error); | ||
} finally { | ||
setSubmitting(false); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
{proposalStep.confirmation ? ( | ||
<ConfirmationGrantEngagement | ||
member={member} | ||
points={points} | ||
comment={comment} | ||
isSubmitting={isSubmitting} | ||
goBack={() => setProposalStep({ type: ProposalType.GrantEngagement })} | ||
submitForm={submitCreateProposal} | ||
/> | ||
) : ( | ||
<FormGrantEngagement | ||
member={member} | ||
points={points} | ||
comment={comment} | ||
goBack={() => setProposalStep(undefined)} | ||
handleSubmit={submitGrantEngagement} | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
File renamed without changes.
Oops, something went wrong.