Skip to content

Commit

Permalink
OC add and adapt to Grant Engagement (#219)
Browse files Browse the repository at this point in the history
* 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
abefernan authored Nov 17, 2021
1 parent 2761839 commit 8bacfe9
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 331 deletions.
17 changes: 6 additions & 11 deletions scripts/tgrade/template/node0/tgrade/config/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"accounts": [
{
"@type": "/cosmos.auth.v1beta1.BaseAccount",
"address": "tgrade12g76yu4hh2vahak8f2wawf4zpafl73tt7lp6r8"
"address": "tgrade1kalzk5cvq5yu6f5u73k7r905yw52sawckddsc3"
},
{
"@type": "/cosmos.auth.v1beta1.BaseAccount",
Expand All @@ -27,7 +27,7 @@
"bank": {
"balances": [
{
"address": "tgrade12g76yu4hh2vahak8f2wawf4zpafl73tt7lp6r8",
"address": "tgrade1kalzk5cvq5yu6f5u73k7r905yw52sawckddsc3",
"coins": [
{
"amount": "100000000000",
Expand Down Expand Up @@ -97,10 +97,7 @@
"clients": [],
"clients_consensus": [],
"params": {
"allowed_clients": [
"06-solomachine",
"07-tendermint"
]
"allowed_clients": ["06-solomachine", "07-tendermint"]
}
},
"connection_genesis": {
Expand All @@ -113,7 +110,7 @@
"bond_denom": "utgd",
"engagement": [
{
"address": "tgrade12g76yu4hh2vahak8f2wawf4zpafl73tt7lp6r8",
"address": "tgrade1kalzk5cvq5yu6f5u73k7r905yw52sawckddsc3",
"weight": "2"
},
{
Expand Down Expand Up @@ -203,7 +200,7 @@
"tokens_per_weight": "1",
"unbonding_period": "1814400s"
},
"system_admin_address": "tgrade12g76yu4hh2vahak8f2wawf4zpafl73tt7lp6r8",
"system_admin_address": "tgrade1kalzk5cvq5yu6f5u73k7r905yw52sawckddsc3",
"valset_contract_config": {
"ValidatorsRewardRatio": 50,
"epoch_length": "60s",
Expand Down Expand Up @@ -252,9 +249,7 @@
"max_bytes": "1048576"
},
"validator": {
"pub_key_types": [
"ed25519"
]
"pub_key_types": ["ed25519"]
},
"version": {}
},
Expand Down
6 changes: 3 additions & 3 deletions src/App/components/DsoProposalDetailModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,13 @@ export default function DsoProposalDetailModal({
</b>
</Paragraph>
<Paragraph>
Yes: <b>{proposal.votes.yes}</b>
Yes: <b>{proposal.votes?.yes ?? 0}</b>
</Paragraph>
<Paragraph>
No: <b>{proposal.votes.no}</b>
No: <b>{proposal.votes?.no ?? 0}</b>
</Paragraph>
<Paragraph>
Abstain: <b>{proposal.votes.abstain}</b>
Abstain: <b>{proposal.votes?.abstain ?? 0}</b>
</Paragraph>
</SectionWrapper>
</SectionWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import { calculateFee } from "@cosmjs/stargate";
import { Typography } from "antd";
import AddressTag from "App/components/AddressTag";
import BackButtonOrLink from "App/components/BackButtonOrLink";
import Button from "App/components/Button";
import { lazy, useEffect, useState } from "react";
import { useError, useSdk } from "service";
import { getDisplayAmountFromFee } from "utils/currency";
import { DsoContract } from "utils/dso";

import { AddressStack, ButtonGroup, FeeGroup, FieldLabel, Separator, TextComment } from "./style";
import { ButtonGroup, FeeGroup, Separator, TextComment } from "./style";

const ConnectWalletModal = lazy(() => import("App/components/ConnectWalletModal"));
const { Paragraph } = Typography;
const { Text, Paragraph } = Typography;

interface ConfirmationWhitelistPairProps {
readonly pairAddress: string;
interface ConfirmationGrantEngagementProps {
readonly member: string;
readonly points: string;
readonly comment: string;
readonly isSubmitting: boolean;
readonly goBack: () => void;
readonly submitForm: () => void;
}

export default function ConfirmationWhitelistPair({
pairAddress,
export default function ConfirmationGrantEngagement({
member,
points,
comment,
isSubmitting,
goBack,
submitForm,
}: ConfirmationWhitelistPairProps): JSX.Element {
}: ConfirmationGrantEngagementProps): JSX.Element {
const { handleError } = useError();
const {
sdkState: { config, signer, signingClient },
Expand All @@ -52,10 +53,10 @@ export default function ConfirmationWhitelistPair({

return (
<>
<AddressStack gap="s-3">
<FieldLabel>Pair to be whitelisted</FieldLabel>
<AddressTag address={pairAddress} />
</AddressStack>
<TextComment>Member to be granted Engagement Points</TextComment>
<Text>{member}</Text>
<TextComment>Number of Engagement Points to be granted</TextComment>
<Text>{points}</Text>
<TextComment>{comment}</TextComment>
<Separator />
<ButtonGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
import { Typography } from "antd";
import Stack from "App/components/Stack/style";
import styled from "styled-components";

const { Text } = Typography;

export const AddressStack = styled(Stack)`
align-items: flex-start;
`;

export const FieldLabel = styled(Text)`
&& {
font-size: var(--s0);
color: var(--color-text-1ary);
font-weight: 500;
}
`;

export const TextComment = styled(Text)`
&& {
color: var(--color-text-1ary);
Expand Down
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>
);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import Select from "App/components/Select";
import styled from "styled-components";

export const StyledSelect = styled(Select)`
.ant-select-arrow {
color: #8692a6;
}
`;

export const Separator = styled.hr`
margin: 0 -20px 0 -20px;
border: none;
border-top: 1px solid var(--color-input-border);
`;

export const FieldGroup = styled.div`
display: flex;
justify-content: space-between;
flex-wrap: wrap;
& .ant-form-item {
flex-basis: 18rem;
}
`;

export const ButtonGroup = styled.div`
display: flex;
justify-content: space-between;
Expand Down
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}
/>
)}
</>
);
}
Loading

0 comments on commit 8bacfe9

Please sign in to comment.