Skip to content

Commit

Permalink
Merge pull request #216 from cosmos/feat/msg-fund-cpool
Browse files Browse the repository at this point in the history
Add fund cpool and tweaks
  • Loading branch information
abefernan authored Jun 11, 2024
2 parents c71d25a + 085856d commit b89faef
Show file tree
Hide file tree
Showing 23 changed files with 464 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { useChains } from "../../../context/ChainsContext";
import { printableCoin } from "../../../lib/displayHelpers";
import HashView from "../HashView";

interface TxMsgRedelegateDetailsProps {
interface TxMsgBeginRedelegateDetailsProps {
readonly msgValue: MsgBeginRedelegate;
}

const TxMsgRedelegateDetails = ({ msgValue }: TxMsgRedelegateDetailsProps) => {
const TxMsgBeginRedelegateDetails = ({ msgValue }: TxMsgBeginRedelegateDetailsProps) => {
const { chain } = useChains();
assert(
msgValue.amount,
Expand Down Expand Up @@ -65,4 +65,4 @@ const TxMsgRedelegateDetails = ({ msgValue }: TxMsgRedelegateDetailsProps) => {
);
};

export default TxMsgRedelegateDetails;
export default TxMsgBeginRedelegateDetails;
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { MsgFundCommunityPool } from "cosmjs-types/cosmos/distribution/v1beta1/tx";
import { useChains } from "../../../context/ChainsContext";
import { printableCoins } from "../../../lib/displayHelpers";

interface TxMsgFundCommunityPoolDetailsProps {
readonly msgValue: MsgFundCommunityPool;
}

const TxMsgFundCommunityPoolDetails = ({ msgValue }: TxMsgFundCommunityPoolDetailsProps) => {
const { chain } = useChains();

return (
<>
<li>
<h3>MsgFundCommunityPool</h3>
</li>
<li>
<label>Amount:</label>
<div>{printableCoins(msgValue.amount, chain) || "None"}</div>
</li>
<style jsx>{`
li:not(:has(h3)) {
background: rgba(255, 255, 255, 0.03);
padding: 6px 10px;
border-radius: 8px;
display: flex;
align-items: center;
}
li + li:nth-child(2) {
margin-top: 25px;
}
li + li {
margin-top: 10px;
}
li div {
padding: 3px 6px;
}
label {
font-size: 12px;
background: rgba(255, 255, 255, 0.1);
padding: 3px 6px;
border-radius: 5px;
display: block;
}
`}</style>
</>
);
};

export default TxMsgFundCommunityPoolDetails;
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx";
import HashView from "../HashView";

interface TxMsgClaimRewardsDetailsProps {
interface TxMsgWithdrawDelegatorRewardDetailsProps {
readonly msgValue: MsgWithdrawDelegatorReward;
}

const TxMsgClaimRewardsDetails = ({ msgValue }: TxMsgClaimRewardsDetailsProps) => (
const TxMsgWithdrawDelegatorRewardDetails = ({
msgValue,
}: TxMsgWithdrawDelegatorRewardDetailsProps) => (
<>
<li>
<h3>MsgWithdrawDelegatorReward</h3>
Expand Down Expand Up @@ -44,4 +46,4 @@ const TxMsgClaimRewardsDetails = ({ msgValue }: TxMsgClaimRewardsDetailsProps) =
</>
);

export default TxMsgClaimRewardsDetails;
export default TxMsgWithdrawDelegatorRewardDetails;
32 changes: 21 additions & 11 deletions components/dataViews/TransactionInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,61 @@ import { printableCoins } from "../../../lib/displayHelpers";
import { DbTransaction } from "../../../types";
import { MsgTypeUrls } from "../../../types/txMsg";
import StackableContainer from "../../layout/StackableContainer";
import TxMsgClaimRewardsDetails from "./TxMsgClaimRewardsDetails";
import TxMsgBeginRedelegateDetails from "./TxMsgBeginRedelegateDetails";
import TxMsgCreateVestingAccountDetails from "./TxMsgCreateVestingAccountDetails";
import TxMsgDelegateDetails from "./TxMsgDelegateDetails";
import TxMsgExecuteContractDetails from "./TxMsgExecuteContractDetails";
import TxMsgFundCommunityPoolDetails from "./TxMsgFundCommunityPoolDetails";
import TxMsgInstantiateContract2Details from "./TxMsgInstantiateContract2Details";
import TxMsgInstantiateContractDetails from "./TxMsgInstantiateContractDetails";
import TxMsgMigrateContractDetails from "./TxMsgMigrateContractDetails";
import TxMsgRedelegateDetails from "./TxMsgRedelegateDetails";
import TxMsgSendDetails from "./TxMsgSendDetails";
import TxMsgSetWithdrawAddressDetails from "./TxMsgSetWithdrawAddressDetails";
import TxMsgTransferDetails from "./TxMsgTransferDetails";
import TxMsgUndelegateDetails from "./TxMsgUndelegateDetails";
import TxMsgUpdateAdminDetails from "./TxMsgUpdateAdminDetails";
import TxMsgVoteDetails from "./TxMsgVoteDetails";
import TxMsgWithdrawDelegatorRewardDetails from "./TxMsgWithdrawDelegatorRewardDetails";

const TxMsgDetails = ({ typeUrl, value: msgValue }: EncodeObject) => {
switch (typeUrl) {
// Bank
case MsgTypeUrls.Send:
return <TxMsgSendDetails msgValue={msgValue} />;
// Staking
case MsgTypeUrls.Delegate:
return <TxMsgDelegateDetails msgValue={msgValue} />;
case MsgTypeUrls.Undelegate:
return <TxMsgUndelegateDetails msgValue={msgValue} />;
case MsgTypeUrls.BeginRedelegate:
return <TxMsgRedelegateDetails msgValue={msgValue} />;
case MsgTypeUrls.WithdrawDelegatorReward:
return <TxMsgClaimRewardsDetails msgValue={msgValue} />;
return <TxMsgBeginRedelegateDetails msgValue={msgValue} />;
// Distribution
case MsgTypeUrls.FundCommunityPool:
return <TxMsgFundCommunityPoolDetails msgValue={msgValue} />;
case MsgTypeUrls.SetWithdrawAddress:
return <TxMsgSetWithdrawAddressDetails msgValue={msgValue} />;
case MsgTypeUrls.WithdrawDelegatorReward:
return <TxMsgWithdrawDelegatorRewardDetails msgValue={msgValue} />;
// Vesting
case MsgTypeUrls.CreateVestingAccount:
return <TxMsgCreateVestingAccountDetails msgValue={msgValue} />;
// Governance
case MsgTypeUrls.Vote:
return <TxMsgVoteDetails msgValue={msgValue} />;
// IBC
case MsgTypeUrls.Transfer:
return <TxMsgTransferDetails msgValue={msgValue} />;
case MsgTypeUrls.Execute:
return <TxMsgExecuteContractDetails msgValue={msgValue} />;
case MsgTypeUrls.Instantiate:
// CosmWasm
case MsgTypeUrls.InstantiateContract:
return <TxMsgInstantiateContractDetails msgValue={msgValue} />;
case MsgTypeUrls.Instantiate2:
case MsgTypeUrls.InstantiateContract2:
return <TxMsgInstantiateContract2Details msgValue={msgValue} />;
case MsgTypeUrls.Migrate:
return <TxMsgMigrateContractDetails msgValue={msgValue} />;
case MsgTypeUrls.UpdateAdmin:
return <TxMsgUpdateAdminDetails msgValue={msgValue} />;
case MsgTypeUrls.ExecuteContract:
return <TxMsgExecuteContractDetails msgValue={msgValue} />;
case MsgTypeUrls.MigrateContract:
return <TxMsgMigrateContractDetails msgValue={msgValue} />;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SelectValidator from "@/components/SelectValidator";
import { EncodeObject } from "@cosmjs/proto-signing";
import { MsgBeginRedelegateEncodeObject } from "@cosmjs/stargate";
import { useEffect, useState } from "react";
import { MsgGetter } from "..";
import { useChains } from "../../../../context/ChainsContext";
Expand All @@ -9,17 +9,17 @@ import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg";
import Input from "../../../inputs/Input";
import StackableContainer from "../../../layout/StackableContainer";

interface MsgRedelegateFormProps {
readonly delegatorAddress: string;
interface MsgBeginRedelegateFormProps {
readonly senderAddress: string;
readonly setMsgGetter: (msgGetter: MsgGetter) => void;
readonly deleteMsg: () => void;
}

const MsgRedelegateForm = ({
delegatorAddress,
const MsgBeginRedelegateForm = ({
senderAddress,
setMsgGetter,
deleteMsg,
}: MsgRedelegateFormProps) => {
}: MsgBeginRedelegateFormProps) => {
const { chain } = useChains();

const [validatorSrcAddress, setValidatorSrcAddress] = useState("");
Expand Down Expand Up @@ -81,21 +81,24 @@ const MsgRedelegateForm = ({
})();

const msgValue = MsgCodecs[MsgTypeUrls.BeginRedelegate].fromPartial({
delegatorAddress,
delegatorAddress: senderAddress,
validatorSrcAddress,
validatorDstAddress,
amount: microCoin,
});

const msg: EncodeObject = { typeUrl: MsgTypeUrls.BeginRedelegate, value: msgValue };
const msg: MsgBeginRedelegateEncodeObject = {
typeUrl: MsgTypeUrls.BeginRedelegate,
value: msgValue,
};

setMsgGetter({ isMsgValid, msg });
}, [
chain.addressPrefix,
chain.assets,
chain.chainId,
chain.displayDenom,
delegatorAddress,
senderAddress,
setMsgGetter,
trimmedInputs,
]);
Expand Down Expand Up @@ -173,4 +176,4 @@ const MsgRedelegateForm = ({
);
};

export default MsgRedelegateForm;
export default MsgBeginRedelegateForm;
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import Input from "../../../inputs/Input";
import StackableContainer from "../../../layout/StackableContainer";

interface MsgCreateVestingAccountFormProps {
readonly fromAddress: string;
readonly senderAddress: string;
readonly setMsgGetter: (msgGetter: MsgGetter) => void;
readonly deleteMsg: () => void;
}

const MsgCreateVestingAccountForm = ({
fromAddress,
senderAddress,
setMsgGetter,
deleteMsg,
}: MsgCreateVestingAccountFormProps) => {
Expand Down Expand Up @@ -87,7 +87,7 @@ const MsgCreateVestingAccountForm = ({
})();

const msgValue = MsgCodecs[MsgTypeUrls.CreateVestingAccount].fromPartial({
fromAddress,
fromAddress: senderAddress,
toAddress,
amount: microCoin ? [microCoin] : [],
endTime: timestampFromDatetimeLocal(endTime, "s"),
Expand All @@ -103,7 +103,7 @@ const MsgCreateVestingAccountForm = ({
chain.chainId,
chain.displayDenom,
delayed,
fromAddress,
senderAddress,
setMsgGetter,
trimmedInputs,
]);
Expand Down
8 changes: 4 additions & 4 deletions components/forms/CreateTxForm/MsgForm/MsgDelegateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import Input from "../../../inputs/Input";
import StackableContainer from "../../../layout/StackableContainer";

interface MsgDelegateFormProps {
readonly delegatorAddress: string;
readonly senderAddress: string;
readonly setMsgGetter: (msgGetter: MsgGetter) => void;
readonly deleteMsg: () => void;
}

const MsgDelegateForm = ({ delegatorAddress, setMsgGetter, deleteMsg }: MsgDelegateFormProps) => {
const MsgDelegateForm = ({ senderAddress, setMsgGetter, deleteMsg }: MsgDelegateFormProps) => {
const { chain } = useChains();

const [validatorAddress, setValidatorAddress] = useState("");
Expand Down Expand Up @@ -66,7 +66,7 @@ const MsgDelegateForm = ({ delegatorAddress, setMsgGetter, deleteMsg }: MsgDeleg
})();

const msgValue = MsgCodecs[MsgTypeUrls.Delegate].fromPartial({
delegatorAddress,
delegatorAddress: senderAddress,
validatorAddress,
amount: microCoin,
});
Expand All @@ -79,7 +79,7 @@ const MsgDelegateForm = ({ delegatorAddress, setMsgGetter, deleteMsg }: MsgDeleg
chain.assets,
chain.chainId,
chain.displayDenom,
delegatorAddress,
senderAddress,
setMsgGetter,
trimmedInputs,
]);
Expand Down
15 changes: 9 additions & 6 deletions components/forms/CreateTxForm/MsgForm/MsgExecuteContractForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ const getDenomOptions = (assets: ChainInfo["assets"]) => {
};

interface MsgExecuteContractFormProps {
readonly fromAddress: string;
readonly senderAddress: string;
readonly setMsgGetter: (msgGetter: MsgGetter) => void;
readonly deleteMsg: () => void;
}

const MsgExecuteContractForm = ({
fromAddress,
senderAddress,
setMsgGetter,
deleteMsg,
}: MsgExecuteContractFormProps) => {
Expand Down Expand Up @@ -126,23 +126,26 @@ const MsgExecuteContractForm = ({
}
})();

const msgValue = MsgCodecs[MsgTypeUrls.Execute].fromPartial({
sender: fromAddress,
const msgValue = MsgCodecs[MsgTypeUrls.ExecuteContract].fromPartial({
sender: senderAddress,
contract: contractAddress,
msg: msgContentUtf8Array,
funds: microCoin ? [microCoin] : [],
});

const msg: MsgExecuteContractEncodeObject = { typeUrl: MsgTypeUrls.Execute, value: msgValue };
const msg: MsgExecuteContractEncodeObject = {
typeUrl: MsgTypeUrls.ExecuteContract,
value: msgValue,
};

setMsgGetter({ isMsgValid, msg });
}, [
chain.addressPrefix,
chain.assets,
chain.chainId,
fromAddress,
msgContent,
selectedDenom.value,
senderAddress,
setMsgGetter,
trimmedInputs,
]);
Expand Down
Loading

0 comments on commit b89faef

Please sign in to comment.