Skip to content

Commit

Permalink
Merge pull request #56 from gacogo/commspend
Browse files Browse the repository at this point in the history
community spend proposal  #51
  • Loading branch information
FredRadford authored Jun 17, 2024
2 parents 910cfd0 + fe4227d commit 0b42096
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 3 deletions.
39 changes: 38 additions & 1 deletion src/components/ProposalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export type SelectorReturnType = ReturnType<
export type ProposalDetail =
| { msgType: "textProposal" }
| { msgType: "coreEvalProposal"; evals: CoreEval[] }
| { msgType: "parameterChangeProposal"; changes: ParamChange[] };
| { msgType: "parameterChangeProposal"; changes: ParamChange[] }
| {
msgType: "communityPoolSpendProposal";
recipient: string;
amount: string;
};

interface ProposalFormProps {
title: string;
Expand Down Expand Up @@ -84,6 +89,10 @@ const ProposalForm = forwardRef<ProposalFormMethods, ProposalFormProps>(
const changes = paramChangeRef.current?.getChanges();
if (!Array.isArray(changes)) throw new Error("No changes");
return handleSubmit({ ...args, msgType, changes });
} else if (msgType === "communityPoolSpendProposal") {
const recipient = (formData.get("recipient") as string) || "";
const amount = (formData.get("amount") as string) || "";
return handleSubmit({ ...args, msgType, recipient, amount });
}
}
}
Expand Down Expand Up @@ -113,7 +122,35 @@ const ProposalForm = forwardRef<ProposalFormMethods, ProposalFormProps>(
<TitleDescriptionInputs
communityForumLink={governanceForumLink}
/>
{msgType === "communityPoolSpendProposal" ? (
<div className="grid grid-cols-2 gap-[10px] pt-[20px]">
<label
htmlFor="recipient"
className="text-sm font-medium text-blue"
>
Recipient
</label>
<input
type="text"
id="recipient"
name="recipient"
className="col-span-2 mt-0"
/>

<label
htmlFor="amount"
className="text-sm font-medium text-blue"
>
Amount
</label>
<input
type="text"
id="amount"
name="amount"
className="col-span-2 mt-0"
/>
</div>
) : null}
{msgType === "coreEvalProposal" ? (
<div className="grid grid-cols-2 gap-[10px] pt-[20px]">
<label
Expand Down
42 changes: 41 additions & 1 deletion src/config/agoric/agoric.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "../../installSesLockdown";
import { render, screen } from "@testing-library/react";
import { fireEvent, render, screen } from "@testing-library/react";
import { Router } from "wouter";
import App from "../../App";
import { ContextProviders } from "../../contexts/providers";
Expand All @@ -26,6 +26,46 @@ describe("Agoric Config", () => {
"CoreEval Proposal",
"Install Bundle",
"Parameter Change Proposal",
"Community Pool Spend",
]);
});

vi.mock("../../hooks/useWallet", () => ({
useWallet: vi.fn(() => ({
walletAddress: "agoric12se",
stargateClient: {
simulate: vi.fn(),
signAndBroadcast: vi.fn(),
},
})),
}));

vi.mock("../../lib/signAndBroadcast", () => ({
makeSignAndBroadcast: vi.fn(),
}));
it(" renders comm spend proposal form", async () => {

render(
<Router hook={memoryLocation("/agoric")}>
<ContextProviders>
<App />
</ContextProviders>
,
</Router>,
);
const communityPoolSpendTab = await screen.findByRole("tab", {
name: "Community Pool Spend",
});
fireEvent.click(communityPoolSpendTab);

const recipientField = await screen.findByLabelText("Recipient");
expect(recipientField).toBeTruthy();

const amountField = await screen.findByLabelText("Amount");
expect(amountField).toBeTruthy();

fireEvent.change(recipientField, { target: { value: "agoric12se" } });
fireEvent.change(amountField, { target: { value: "1000000" } });

});
});
25 changes: 25 additions & 0 deletions src/config/agoric/agoric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
makeTextProposalMsg,
makeInstallBundleMsg,
makeParamChangeProposalMsg,
makeCommunityPoolSpendProposalMsg,
} from "../../lib/messageBuilder";
import { isValidBundle } from "../../utils/validate";
import { makeSignAndBroadcast } from "../../lib/signAndBroadcast";
Expand Down Expand Up @@ -98,6 +99,17 @@ const Agoric = () => {
proposer: walletAddress,
});
}

if (msgType === "communityPoolSpendProposal") {
if (!("recipient" in vals) || !("amount" in vals)) {
throw new Error("Missing recipient or amount");
}
proposalMsg = makeCommunityPoolSpendProposalMsg({
...vals,
proposer: walletAddress,
});
}

if (msgType === "parameterChangeProposal") {
if (vals.msgType !== "parameterChangeProposal") return;
proposalMsg = makeParamChangeProposalMsg({
Expand Down Expand Up @@ -280,6 +292,19 @@ const Agoric = () => {
/>
),
},
{
title: "Community Pool Spend",
msgType: "communityPoolSpendProposal",
content: (
<ProposalForm
title="Community Pool Spend Proposal"
handleSubmit={handleProposal("communityPoolSpendProposal")}
description="This is a governance proposal to spend funds from the community pool."
governanceForumLink="https://community.agoric.com/c/governance/community-pool-spend-proposals/15"
msgType="communityPoolSpendProposal"
/>
),
},
]}
/>
</>
Expand Down
3 changes: 2 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ declare global {
| "installBundle"
| "parameterChangeProposal"
| "addPSM"
| "addVault";
| "addVault"
| "communityPoolSpendProposal";
paramType: string;
}

Expand Down
39 changes: 39 additions & 0 deletions src/lib/messageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,51 @@ import { TextProposal } from "cosmjs-types/cosmos/gov/v1beta1/gov";
import { ParameterChangeProposal } from "cosmjs-types/cosmos/params/v1beta1/params";
import { Any } from "cosmjs-types/google/protobuf/any";
import type { ParamChange } from "cosmjs-types/cosmos/params/v1beta1/params";
import { CommunityPoolSpendProposal } from "cosmjs-types/cosmos/distribution/v1beta1/distribution";

export const registry = new Registry([
...defaultRegistryTypes,
["/agoric.swingset.MsgInstallBundle", MsgInstallBundle],
]);

export const makeCommunityPoolSpendProposalMsg = ({
proposer,
recipient,
amount,
title,
description,
deposit,
}: {
proposer: string;
recipient: string;
amount: string;
title: string;
description: string;
deposit?: number | string;
}) => {
const communityPoolSpendProposal: CommunityPoolSpendProposal = {
title,
description,
recipient,
amount: coins(amount, "ubld"),
};
const msgSubmitProposal = {
typeUrl: "/cosmos.gov.v1beta1.MsgSubmitProposal",
value: {
content: {
typeUrl: "/cosmos.distribution.v1beta1.CommunityPoolSpendProposal",
value: CommunityPoolSpendProposal.encode(
communityPoolSpendProposal,
).finish(),
},
proposer: proposer,
...(deposit &&
Number(deposit) && { initialDeposit: coins(deposit, "ubld") }),
},
};
return msgSubmitProposal;
};

interface MakeTextProposalArgs {
title: string;
description: string;
Expand Down

0 comments on commit 0b42096

Please sign in to comment.