diff --git a/components/forms/DelegationForm.tsx b/components/forms/DelegationForm.tsx deleted file mode 100644 index 6f2ff60..0000000 --- a/components/forms/DelegationForm.tsx +++ /dev/null @@ -1,157 +0,0 @@ -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; - router: NextRouter; - closeForm: () => void; -} - -const DelegationForm = (props: Props) => { - const { state } = useAppContext(); - const [validatorAddress, setValidatorAddress] = useState(""); - const [amount, setAmount] = useState("0"); - 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, 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 msgDelegate = { - delegatorAddress: props.delegatorAddress, - validatorAddress: txValidatorAddress, - amount: { - amount: amountInAtomics, - denom: state.chain.denom, - }, - }; - const msg = { - typeUrl: "/cosmos.staking.v1beta1.MsgDelegate", - value: msgDelegate, - }; - assert(gasPrice, "gasPrice missing"); - const fee = calculateFee(gasLimit, gasPrice); - const { accountOnChain } = props; - assert(typeof accountOnChain.accountNumber === "number", "accountNumber 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 Delegation

-
- ) => 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)} - /> -
- -

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)} - /> -
- -

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)} - /> -
- -

Create New transaction

-
- ) => setToAddress(e.target.value)} - error={addressError} - placeholder={`E.g. ${exampleAddress(0, state.chain.addressPrefix)}`} - /> -
-
- ) => setAmount(e.target.value)} - /> -
-
- ) => - setGas(parseInt(e.target.value, 10)) - } - /> -
-
- -
-
- ) => setMemo(e.target.value)} - /> -
- -

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)} - /> -
-