-
+
+
>
+ ) : msg.typeUrl === "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward" ? (
+
+
+
+
+
+
) : null,
)}
{props.tx.fee && (
diff --git a/components/forms/DelegationForm.tsx b/components/forms/DelegationForm.tsx
index 3a025bb..e8cfddd 100644
--- a/components/forms/DelegationForm.tsx
+++ b/components/forms/DelegationForm.tsx
@@ -11,7 +11,7 @@ import Input from "../inputs/Input";
import StackableContainer from "../layout/StackableContainer";
interface Props {
- address: string | null;
+ delegatorAddress: string;
accountOnChain: Account | null;
router: NextRouter;
closeForm: () => void;
@@ -35,7 +35,7 @@ const DelegationForm = (props: Props) => {
Number(state.chain.displayDenomExponent),
).atomics;
const msgDelegate = {
- delegatorAddress: props.address,
+ delegatorAddress: props.delegatorAddress,
validatorAddress: txValidatorAddress,
amount: {
amount: amountInAtomics,
@@ -77,7 +77,7 @@ const DelegationForm = (props: Props) => {
const res = await axios.post("/api/transaction", { dataJSON });
console.log(dataJSON, "tx dataJSON", res);
const { transactionID } = res.data;
- props.router.push(`${props.address}/transaction/${transactionID}`);
+ props.router.push(`${props.delegatorAddress}/transaction/${transactionID}`);
};
assert(state.chain.addressPrefix, "addressPrefix missing");
diff --git a/components/forms/ReDelegationForm.tsx b/components/forms/ReDelegationForm.tsx
new file mode 100644
index 0000000..9ffb758
--- /dev/null
+++ b/components/forms/ReDelegationForm.tsx
@@ -0,0 +1,185 @@
+import { Decimal } from "@cosmjs/math";
+import { Account, calculateFee } from "@cosmjs/stargate";
+import { assert } from "@cosmjs/utils";
+import axios from "axios";
+import { NextRouter, withRouter } from "next/router";
+import { useState } from "react";
+import { useAppContext } from "../../context/AppContext";
+import { checkAddress, exampleValidatorAddress } from "../../lib/displayHelpers";
+import Button from "../inputs/Button";
+import Input from "../inputs/Input";
+import StackableContainer from "../layout/StackableContainer";
+
+interface Props {
+ delegatorAddress: string;
+ accountOnChain: Account | null;
+ router: NextRouter;
+ closeForm: () => void;
+}
+
+const ReDelegationForm = (props: Props) => {
+ const { state } = useAppContext();
+ const [validatorSrcAddress, setValidatorSrcAddress] = useState("");
+ const [validatorDstAddress, setValidatorDstAddress] = useState("");
+ const [amount, setAmount] = useState("0");
+ const [memo, setMemo] = useState("");
+ const [gas, setGas] = useState(300000);
+ const [gasPrice, _setGasPrice] = useState(state.chain.gasPrice);
+ const [_processing, setProcessing] = useState(false);
+ const [addressErrors, setAddressErrors] = useState({ src: "", dst: "" });
+
+ const createTransaction = (
+ txValidatorSrcAddress: string,
+ txValidatorDstAddress: string,
+ txAmount: string,
+ gasLimit: number,
+ ) => {
+ assert(Number.isSafeInteger(gasLimit) && gasLimit > 0, "gas limit must be a positive integer");
+
+ const amountInAtomics = Decimal.fromUserInput(
+ txAmount,
+ Number(state.chain.displayDenomExponent),
+ ).atomics;
+ const msgRedelegate = {
+ delegatorAddress: props.delegatorAddress,
+ validatorSrcAddress: txValidatorSrcAddress,
+ validatorDstAddress: txValidatorDstAddress,
+ amount: {
+ amount: amountInAtomics,
+ denom: state.chain.denom,
+ },
+ };
+ const msg = {
+ typeUrl: "/cosmos.staking.v1beta1.MsgBeginRedelegate",
+ value: msgRedelegate,
+ };
+ assert(gasPrice, "gasPrice missing");
+ const fee = calculateFee(gasLimit, gasPrice);
+ const { accountOnChain } = props;
+ assert(accountOnChain, "accountOnChain missing");
+ return {
+ accountNumber: accountOnChain.accountNumber,
+ sequence: accountOnChain.sequence,
+ chainId: state.chain.chainId,
+ msgs: [msg],
+ fee: fee,
+ memo: memo,
+ };
+ };
+
+ const handleCreate = async () => {
+ assert(state.chain.addressPrefix, "addressPrefix missing");
+ const validatorSrcAddressError = checkAddress(validatorSrcAddress, state.chain.addressPrefix);
+ const validatorDstAddressError = checkAddress(validatorDstAddress, state.chain.addressPrefix);
+
+ setAddressErrors({
+ src: validatorSrcAddressError
+ ? `Invalid address for network ${state.chain.chainId}: ${validatorSrcAddressError}`
+ : "",
+ dst: validatorDstAddressError
+ ? `Invalid address for network ${state.chain.chainId}: ${validatorDstAddressError}`
+ : "",
+ });
+ if (validatorSrcAddressError || validatorDstAddressError) {
+ return;
+ }
+
+ setProcessing(true);
+ const tx = createTransaction(validatorSrcAddress, validatorDstAddress, amount, gas);
+ console.log(tx, "tx data");
+ const dataJSON = JSON.stringify(tx);
+ const res = await axios.post("/api/transaction", { dataJSON });
+ console.log(dataJSON, "tx dataJSON", res);
+ const { transactionID } = res.data;
+ props.router.push(`${props.delegatorAddress}/transaction/${transactionID}`);
+ };
+
+ assert(state.chain.addressPrefix, "addressPrefix missing");
+
+ return (
+
+
+ Create ReDelegation
+
+ ) =>
+ setValidatorSrcAddress(e.target.value)
+ }
+ error={addressErrors.src}
+ placeholder={`E.g. ${exampleValidatorAddress(0, state.chain.addressPrefix)}`}
+ />
+
+
+ ) =>
+ setValidatorDstAddress(e.target.value)
+ }
+ error={addressErrors.dst}
+ placeholder={`E.g. ${exampleValidatorAddress(1, state.chain.addressPrefix)}`}
+ />
+
+
+ ) => setAmount(e.target.value)}
+ />
+
+
+ ) =>
+ setGas(parseInt(e.target.value, 10))
+ }
+ />
+
+
+
+
+
+ ) => setMemo(e.target.value)}
+ />
+
+
+
+
+ );
+};
+
+export default withRouter(ReDelegationForm);
diff --git a/components/forms/RewardsForm.tsx b/components/forms/RewardsForm.tsx
new file mode 100644
index 0000000..e4b630e
--- /dev/null
+++ b/components/forms/RewardsForm.tsx
@@ -0,0 +1,138 @@
+import { Account, calculateFee } from "@cosmjs/stargate";
+import { assert } from "@cosmjs/utils";
+import axios from "axios";
+import { NextRouter, withRouter } from "next/router";
+import { useState } from "react";
+import { useAppContext } from "../../context/AppContext";
+import { checkAddress, exampleValidatorAddress } from "../../lib/displayHelpers";
+import Button from "../inputs/Button";
+import Input from "../inputs/Input";
+import StackableContainer from "../layout/StackableContainer";
+
+interface Props {
+ delegatorAddress: string;
+ accountOnChain: Account | null;
+ router: NextRouter;
+ closeForm: () => void;
+}
+
+const RewardsForm = (props: Props) => {
+ const { state } = useAppContext();
+ const [validatorAddress, setValidatorAddress] = useState("");
+ const [memo, setMemo] = useState("");
+ const [gas, setGas] = useState(200000);
+ const [gasPrice, _setGasPrice] = useState(state.chain.gasPrice);
+ const [_processing, setProcessing] = useState(false);
+ const [addressError, setAddressError] = useState("");
+
+ const createTransaction = (txValidatorAddress: string, gasLimit: number) => {
+ assert(Number.isSafeInteger(gasLimit) && gasLimit > 0, "gas limit must be a positive integer");
+
+ const msgDelegatorReward = {
+ delegatorAddress: props.delegatorAddress,
+ validatorAddress: txValidatorAddress,
+ };
+ const msg = {
+ typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
+ value: msgDelegatorReward,
+ };
+ assert(gasPrice, "gasPrice missing");
+ const fee = calculateFee(gasLimit, gasPrice);
+ const { accountOnChain } = props;
+ assert(accountOnChain, "accountOnChain missing");
+ return {
+ accountNumber: accountOnChain.accountNumber,
+ sequence: accountOnChain.sequence,
+ chainId: state.chain.chainId,
+ msgs: [msg],
+ fee: fee,
+ memo: memo,
+ };
+ };
+
+ const handleCreate = async () => {
+ assert(state.chain.addressPrefix, "addressPrefix missing");
+ const validatorAddressError = checkAddress(validatorAddress, state.chain.addressPrefix);
+ if (validatorAddressError) {
+ setAddressError(
+ `Invalid address for network ${state.chain.chainId}: ${validatorAddressError}`,
+ );
+ return;
+ }
+
+ setProcessing(true);
+ const tx = createTransaction(validatorAddress, gas);
+ console.log(tx, "tx data");
+ const dataJSON = JSON.stringify(tx);
+ const res = await axios.post("/api/transaction", { dataJSON });
+ console.log(dataJSON, "tx dataJSON", res);
+ const { transactionID } = res.data;
+ props.router.push(`${props.delegatorAddress}/transaction/${transactionID}`);
+ };
+
+ assert(state.chain.addressPrefix, "addressPrefix missing");
+
+ return (
+
+
+ Claim Rewards
+
+ ) => setValidatorAddress(e.target.value)}
+ error={addressError}
+ placeholder={`E.g. ${exampleValidatorAddress(0, state.chain.addressPrefix)})}`}
+ />
+
+
+ ) =>
+ setGas(parseInt(e.target.value, 10))
+ }
+ />
+
+
+
+
+
+ ) => setMemo(e.target.value)}
+ />
+
+
+
+
+ );
+};
+
+export default withRouter(RewardsForm);
diff --git a/components/forms/UnDelegationForm.tsx b/components/forms/UnDelegationForm.tsx
new file mode 100644
index 0000000..2fb9342
--- /dev/null
+++ b/components/forms/UnDelegationForm.tsx
@@ -0,0 +1,157 @@
+import { Decimal } from "@cosmjs/math";
+import { Account, calculateFee } from "@cosmjs/stargate";
+import { assert } from "@cosmjs/utils";
+import axios from "axios";
+import { NextRouter, withRouter } from "next/router";
+import { useState } from "react";
+import { useAppContext } from "../../context/AppContext";
+import { checkAddress, exampleValidatorAddress } from "../../lib/displayHelpers";
+import Button from "../inputs/Button";
+import Input from "../inputs/Input";
+import StackableContainer from "../layout/StackableContainer";
+
+interface Props {
+ delegatorAddress: string;
+ accountOnChain: Account | null;
+ router: NextRouter;
+ closeForm: () => void;
+}
+
+const UnDelegationForm = (props: Props) => {
+ const { state } = useAppContext();
+ const [validatorAddress, setValidatorAddress] = useState("");
+ const [amount, setAmount] = useState("0");
+ const [memo, setMemo] = useState("");
+ const [gas, setGas] = useState(300000);
+ const [gasPrice, _setGasPrice] = useState(state.chain.gasPrice);
+ const [_processing, setProcessing] = useState(false);
+ const [addressError, setAddressError] = useState("");
+
+ const createTransaction = (txValidatorAddress: string, txAmount: string, gasLimit: number) => {
+ assert(Number.isSafeInteger(gasLimit) && gasLimit > 0, "gas limit must be a positive integer");
+
+ const amountInAtomics = Decimal.fromUserInput(
+ txAmount,
+ Number(state.chain.displayDenomExponent),
+ ).atomics;
+ const msgUndelegate = {
+ delegatorAddress: props.delegatorAddress,
+ validatorAddress: txValidatorAddress,
+ amount: {
+ amount: amountInAtomics,
+ denom: state.chain.denom,
+ },
+ };
+ const msg = {
+ typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate",
+ value: msgUndelegate,
+ };
+ assert(gasPrice, "gasPrice missing");
+ const fee = calculateFee(gasLimit, gasPrice);
+ const { accountOnChain } = props;
+ assert(accountOnChain, "accountOnChain missing");
+ return {
+ accountNumber: accountOnChain.accountNumber,
+ sequence: accountOnChain.sequence,
+ chainId: state.chain.chainId,
+ msgs: [msg],
+ fee: fee,
+ memo: memo,
+ };
+ };
+
+ const handleCreate = async () => {
+ assert(state.chain.addressPrefix, "addressPrefix missing");
+ const validatorAddressError = checkAddress(validatorAddress, state.chain.addressPrefix);
+ if (validatorAddressError) {
+ setAddressError(
+ `Invalid address for network ${state.chain.chainId}: ${validatorAddressError}`,
+ );
+ return;
+ }
+
+ setProcessing(true);
+ const tx = createTransaction(validatorAddress, amount, gas);
+ console.log(tx, "tx data");
+ const dataJSON = JSON.stringify(tx);
+ const res = await axios.post("/api/transaction", { dataJSON });
+ console.log(dataJSON, "tx dataJSON", res);
+ const { transactionID } = res.data;
+ props.router.push(`${props.delegatorAddress}/transaction/${transactionID}`);
+ };
+
+ assert(state.chain.addressPrefix, "addressPrefix missing");
+
+ return (
+
+
+ Create UnDelegation
+
+ ) => setValidatorAddress(e.target.value)}
+ error={addressError}
+ placeholder={`E.g. ${exampleValidatorAddress(0, state.chain.addressPrefix)})}`}
+ />
+
+
+ ) => setAmount(e.target.value)}
+ />
+
+
+ ) =>
+ setGas(parseInt(e.target.value, 10))
+ }
+ />
+
+
+
+
+
+ ) => setMemo(e.target.value)}
+ />
+
+
+
+
+ );
+};
+
+export default withRouter(UnDelegationForm);
diff --git a/pages/multi/[address]/index.tsx b/pages/multi/[address]/index.tsx
index dc46848..8fc3b5f 100644
--- a/pages/multi/[address]/index.tsx
+++ b/pages/multi/[address]/index.tsx
@@ -8,13 +8,18 @@ import HashView from "../../../components/dataViews/HashView";
import MultisigHoldings from "../../../components/dataViews/MultisigHoldings";
import MultisigMembers from "../../../components/dataViews/MultisigMembers";
import DelegationForm from "../../../components/forms/DelegationForm";
+import ReDelegationForm from "../../../components/forms/ReDelegationForm";
+import RewardsForm from "../../../components/forms/RewardsForm";
import TransactionForm from "../../../components/forms/TransactionForm";
+import UnDelegationForm from "../../../components/forms/UnDelegationForm";
import Button from "../../../components/inputs/Button";
import Page from "../../../components/layout/Page";
import StackableContainer from "../../../components/layout/StackableContainer";
import { useAppContext } from "../../../context/AppContext";
import { getMultisigAccount } from "../../../lib/multisigHelpers";
+type TxView = null | "send" | "delegate" | "undelegate" | "redelegate" | "claimRewards";
+
function participantPubkeysFromMultisig(
multisig: MultisigThresholdPubkey,
): readonly SinglePubkey[] {
@@ -23,8 +28,7 @@ function participantPubkeysFromMultisig(
const Multipage = () => {
const { state } = useAppContext();
- const [showSendTxForm, setShowSendTxForm] = useState(false);
- const [showDelegateTxForm, setShowDelegateTxForm] = useState(false);
+ const [txView, setTxView] = useState
(null);
const [holdings, setHoldings] = useState(null);
const [multisigAddress, setMultisigAddress] = useState("");
const [accountOnChain, setAccountOnChain] = useState(null);
@@ -32,6 +36,10 @@ const Multipage = () => {
const [accountError, setAccountError] = useState(null);
const router = useRouter();
+ const closeForm = () => {
+ setTxView(null);
+ };
+
const fetchMultisig = useCallback(
async (address: string) => {
setAccountError(null);
@@ -98,25 +106,42 @@ const Multipage = () => {
)}
- {showSendTxForm && (
+ {txView === "send" && (