Skip to content

Commit

Permalink
wip: Govgen voting support
Browse files Browse the repository at this point in the history
  • Loading branch information
clockworkgr committed Sep 14, 2024
1 parent 13bfc43 commit 8791e89
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { OfflineSigner } from '@cosmjs/proto-signing';
import { registry } from '@atomone/govgen-types-long/govgen/gov/v1beta1/tx.registry';
import { OfflineSigner, Registry } from '@cosmjs/proto-signing';
import {
AminoTypes,
SigningStargateClient,
createDefaultAminoConverters,
defaultRegistryTypes,
} from '@cosmjs/stargate';
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
import { LCD } from '../../../../../shared/chain/types/cosmos';
Expand Down Expand Up @@ -51,8 +53,8 @@ export const getSigningClient = async (
...createAltGovAminoConverters(),
...createGovgenGovAminoConverters(),
});

return await SigningStargateClient.connectWithSigner(url, signer, {
registry: new Registry([...defaultRegistryTypes, ...registry]),
aminoTypes,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ export const getDepositParams = async (
): Promise<CosmosDepositParams> => {
const govController = cosmosChain.governance as CosmosGovernanceGovgen;
let minDeposit;
const { depositParams } = await cosmosChain.chain.api.gov.params('deposit');
const { depositParams } =
await cosmosChain.chain.api.govgen.params('deposit');

// TODO: support off-denom deposits
// @ts-expect-error StrictNullChecks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChainBase } from '@hicommonwealth/shared';
import { useQuery } from '@tanstack/react-query';
import Cosmos from 'controllers/chain/cosmos/adapter';
import { getDepositParams as getGovgenDepositParams } from 'controllers/chain/cosmos/gov/govgen/utils-v1beta1';
import {
CosmosDepositParams,
getDepositParams,
Expand All @@ -12,16 +13,22 @@ const DEPOSIT_PARAMS_STALE_TIME = 1000 * 60 * 15;

const fetchDepositParams = async (
stakingDenom: string,
isGovgen: boolean = false,
): Promise<CosmosDepositParams> => {
return getDepositParams(app.chain as Cosmos, stakingDenom);
return isGovgen
? getGovgenDepositParams(app.chain as Cosmos, stakingDenom)
: getDepositParams(app.chain as Cosmos, stakingDenom);
};

const useDepositParamsQuery = (stakingDenom: string) => {
const useDepositParamsQuery = (
stakingDenom: string,
isGovgen: boolean = false,
) => {
const communityId = app.activeChainId();
return useQuery({
// fetchDepositParams depends on stakingDenom being defined
queryKey: ['depositParams', communityId, stakingDenom],

Check failure on line 30 in packages/commonwealth/client/scripts/state/api/chainParams/fetchDepositParams.ts

View workflow job for this annotation

GitHub Actions / Code Quality Recommendations (20)

The following dependencies are missing in your queryKey: isGovgen
queryFn: () => fetchDepositParams(stakingDenom),
queryFn: () => fetchDepositParams(stakingDenom, isGovgen),
enabled: app.chain?.base === ChainBase.CosmosSDK && !!stakingDenom,
cacheTime: DEPOSIT_PARAMS_CACHE_TIME,
staleTime: DEPOSIT_PARAMS_STALE_TIME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { AnyProposal } from '../../../models/types';

import app from 'state';

import { CosmosProposalGovgen } from 'client/scripts/controllers/chain/cosmos/gov/govgen/proposal-v1beta1';
import Cosmos from 'controllers/chain/cosmos/adapter';
import { CosmosProposalV1 } from 'controllers/chain/cosmos/gov/v1/proposal-v1';
import { CosmosProposal } from 'controllers/chain/cosmos/gov/v1beta1/proposal-v1beta1';
Expand All @@ -26,8 +27,16 @@ type ProposalExtensionsProps = {
export const ProposalExtensions = (props: ProposalExtensionsProps) => {
const { setCosmosDepositAmount, setDemocracyVoteAmount, proposal } = props;
const { data: stakingDenom } = useStakingParamsQuery();

let isGovgen = false;
if (proposal instanceof CosmosProposalGovgen) {
isGovgen = true;
}
// @ts-expect-error <StrictNullChecks/>
const { data: cosmosDepositParams } = useDepositParamsQuery(stakingDenom);
const { data: cosmosDepositParams } = useDepositParamsQuery(
stakingDenom,
isGovgen,
);

useEffect(() => {
if (setDemocracyVoteAmount) setDemocracyVoteAmount(0);
Expand All @@ -39,7 +48,8 @@ export const ProposalExtensions = (props: ProposalExtensionsProps) => {

if (
(proposal instanceof CosmosProposal ||
proposal instanceof CosmosProposalV1) &&
proposal instanceof CosmosProposalV1 ||
proposal instanceof CosmosProposalGovgen) &&
proposal.status === 'DepositPeriod'
) {
const cosmos = app.chain as Cosmos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export const VotingActions = ({

if (
proposal instanceof CosmosProposal ||
proposal instanceof CosmosProposalV1
proposal instanceof CosmosProposalV1 ||
proposal instanceof CosmosProposalGovgen
) {
if (proposal.status === 'DepositPeriod') {
const chain = app.chain as Cosmos;
Expand Down Expand Up @@ -115,7 +116,8 @@ export const VotingActions = ({

if (
proposal instanceof CosmosProposal ||
proposal instanceof CosmosProposalV1
proposal instanceof CosmosProposalV1 ||
proposal instanceof CosmosProposalGovgen
) {
try {
await proposal.voteTx(new CosmosVote(user, 'No'));
Expand All @@ -139,7 +141,8 @@ export const VotingActions = ({

if (
proposal instanceof CosmosProposal ||
proposal instanceof CosmosProposalV1
proposal instanceof CosmosProposalV1 ||
proposal instanceof CosmosProposalGovgen
) {
proposal
.voteTx(new CosmosVote(user, 'Abstain'))
Expand All @@ -157,7 +160,8 @@ export const VotingActions = ({

if (
proposal instanceof CosmosProposal ||
proposal instanceof CosmosProposalV1
proposal instanceof CosmosProposalV1 ||
proposal instanceof CosmosProposalGovgen
) {
proposal
.voteTx(new CosmosVote(user, 'NoWithVeto'))
Expand Down

0 comments on commit 8791e89

Please sign in to comment.