) => {
try {
const tempPubkeys = [...pubkeys];
let pubkey;
@@ -82,7 +90,7 @@ const MultiSigForm = (props) => {
tempPubkeys[index].compressedPubkey = pubkey;
tempPubkeys[index].keyError = "";
setPubkeys(tempPubkeys);
- } catch (error) {
+ } catch (error: any) {
console.log(error);
const tempPubkeys = [...pubkeys];
tempPubkeys[index].keyError = error.message;
@@ -97,9 +105,9 @@ const MultiSigForm = (props) => {
try {
multisigAddress = await createMultisigFromCompressedSecp256k1Pubkeys(
compressedPubkeys,
- parseInt(threshold, 10),
- state.chain.addressPrefix,
- state.chain.chainId,
+ threshold,
+ state!.chain.addressPrefix!,
+ state!.chain.chainId!,
);
props.router.push(`/multi/${multisigAddress}`);
} catch (error) {
@@ -107,7 +115,7 @@ const MultiSigForm = (props) => {
}
};
- const togglePubkey = (index) => {
+ const togglePubkey = (index: number) => {
const tempPubkeys = [...pubkeys];
tempPubkeys[index].isPubkey = !tempPubkeys[index].isPubkey;
setPubkeys(tempPubkeys);
@@ -134,7 +142,7 @@ const MultiSigForm = (props) => {
)}
{
+ onChange={(e: React.ChangeEvent) => {
handleKeyGroupChange(index, e);
}}
value={pubkeyGroup.isPubkey ? pubkeyGroup.compressedPubkey : pubkeyGroup.address}
@@ -144,10 +152,10 @@ const MultiSigForm = (props) => {
placeholder={`E.g. ${
pubkeyGroup.isPubkey
? examplePubkey(index)
- : exampleAddress(index, state.chain.addressPrefix)
+ : exampleAddress(index, state!.chain.addressPrefix!)
}`}
error={pubkeyGroup.keyError}
- onBlur={(e) => {
+ onBlur={(e: React.ChangeEvent) => {
handleKeyBlur(index, e);
}}
/>
diff --git a/components/forms/TransactionForm.js b/components/forms/TransactionForm.tsx
similarity index 67%
rename from components/forms/TransactionForm.js
rename to components/forms/TransactionForm.tsx
index f67804c..30db9e2 100644
--- a/components/forms/TransactionForm.js
+++ b/components/forms/TransactionForm.tsx
@@ -1,29 +1,36 @@
import axios from "axios";
-import { calculateFee } from "@cosmjs/stargate";
+import { calculateFee, Account } from "@cosmjs/stargate";
import { Decimal } from "@cosmjs/math";
import React, { useState } from "react";
-import { withRouter } from "next/router";
+import { withRouter, NextRouter } from "next/router";
import { useAppContext } from "../../context/AppContext";
-import Button from "../../components/inputs/Button";
-import Input from "../../components/inputs/Input";
+import Button from "../inputs/Button";
+import Input from "../inputs/Input";
import StackableContainer from "../layout/StackableContainer";
import { checkAddress, exampleAddress } from "../../lib/displayHelpers";
-const TransactionForm = (props) => {
+interface Props {
+ address: string | null;
+ accountOnChain: Account | null;
+ router: NextRouter;
+ closeForm: () => void;
+}
+
+const TransactionForm = (props: Props) => {
const { state } = useAppContext();
const [toAddress, setToAddress] = useState("");
const [amount, setAmount] = useState("0");
const [memo, setMemo] = useState("");
const [gas, setGas] = useState(200000);
- const [gasPrice, _setGasPrice] = useState(state.chain.gasPrice);
+ const [gasPrice, _setGasPrice] = useState(state!.chain.gasPrice);
const [_processing, setProcessing] = useState(false);
const [addressError, setAddressError] = useState("");
- const createTransaction = (txToAddress, txAmount, txGas) => {
+ const createTransaction = (txToAddress: string, txAmount: string, txGas: number) => {
const amountInAtomics = Decimal.fromUserInput(
txAmount,
- Number(state.chain.displayDenomExponent),
+ Number(state!.chain.displayDenomExponent),
).atomics;
const msgSend = {
fromAddress: props.address,
@@ -31,7 +38,7 @@ const TransactionForm = (props) => {
amount: [
{
amount: amountInAtomics,
- denom: state.chain.denom,
+ denom: state!.chain.denom,
},
],
};
@@ -39,11 +46,11 @@ const TransactionForm = (props) => {
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: msgSend,
};
- const fee = calculateFee(Number(txGas), gasPrice);
+ const fee = calculateFee(Number(txGas), gasPrice!);
return {
- accountNumber: props.accountOnChain.accountNumber,
- sequence: props.accountOnChain.sequence,
- chainId: state.chain.chainId,
+ accountNumber: props.accountOnChain!.accountNumber,
+ sequence: props.accountOnChain!.sequence,
+ chainId: state!.chain.chainId,
msgs: [msg],
fee: fee,
memo: memo,
@@ -51,9 +58,9 @@ const TransactionForm = (props) => {
};
const handleCreate = async () => {
- const toAddressError = checkAddress(toAddress, state.chain.addressPrefix);
+ const toAddressError = checkAddress(toAddress, state!.chain.addressPrefix!);
if (toAddressError) {
- setAddressError(`Invalid address for network ${state.chain.chainId}: ${toAddressError}`);
+ setAddressError(`Invalid address for network ${state!.chain.chainId}: ${toAddressError}`);
return;
}
@@ -77,18 +84,18 @@ const TransactionForm = (props) => {
label="To Address"
name="toAddress"
value={toAddress}
- onChange={(e) => setToAddress(e.target.value)}
+ onChange={(e: React.ChangeEvent) => setToAddress(e.target.value)}
error={addressError}
- placeholder={`E.g. ${exampleAddress(0, state.chain.addressPrefix)}`}
+ placeholder={`E.g. ${exampleAddress(0, state!.chain.addressPrefix!)}`}
/>
setAmount(e.target.value)}
+ onChange={(e: React.ChangeEvent) => setAmount(e.target.value)}
/>
@@ -97,7 +104,7 @@ const TransactionForm = (props) => {
name="gas"
type="number"
value={gas}
- onChange={(e) => setGas(e.target.value)}
+ onChange={(e: React.ChangeEvent) => setGas(parseInt(e.target.value))}
/>
@@ -109,7 +116,7 @@ const TransactionForm = (props) => {
name="memo"
type="text"
value={memo}
- onChange={(e) => setMemo(e.target.value)}
+ onChange={(e: React.ChangeEvent) => setMemo(e.target.value)}
/>
diff --git a/components/forms/TransactionSigning.js b/components/forms/TransactionSigning.tsx
similarity index 83%
rename from components/forms/TransactionSigning.js
rename to components/forms/TransactionSigning.tsx
index 1327fa4..179cd40 100644
--- a/components/forms/TransactionSigning.js
+++ b/components/forms/TransactionSigning.tsx
@@ -8,23 +8,32 @@ import { useAppContext } from "../../context/AppContext";
import Button from "../inputs/Button";
import HashView from "../dataViews/HashView";
import StackableContainer from "../layout/StackableContainer";
+import { DbSignature, DbTransaction, WalletAccount } from "../../types";
import TransportWebUSB from "@ledgerhq/hw-transport-webusb";
import { LedgerSigner } from "@cosmjs/ledger-amino";
import { makeCosmoshubPath } from "@cosmjs/amino";
-const TransactionSigning = (props) => {
+interface Props {
+ signatures: DbSignature[];
+ tx: DbTransaction;
+ transactionID: string;
+ addSignature: (signature: DbSignature) => void;
+}
+
+const TransactionSigning = (props: Props) => {
const { state } = useAppContext();
- const [walletAccount, setWalletAccount] = useState(null);
- const [sigError, setSigError] = useState(null);
+ const [walletAccount, setWalletAccount] = useState();
+ const [sigError, setSigError] = useState("");
const [hasSigned, setHasSigned] = useState(false);
const [walletType, setWalletType] = useState("");
const [ledgerSigner, setLedgerSigner] = useState({});
const connectKeplr = async () => {
try {
- await window.keplr.enable(state.chain.chainId);
- const tempWalletAccount = await window.keplr.getKey(state.chain.chainId);
+ await window.keplr.enable(state!.chain.chainId!);
+ const tempWalletAccount = await window.keplr.getKey(state!.chain.chainId!);
+ console.log(tempWalletAccount);
const tempHasSigned = props.signatures.some(
(sig) => sig.address === tempWalletAccount.bech32Address,
);
@@ -43,11 +52,16 @@ const TransactionSigning = (props) => {
// Setup signer
const offlineSigner = new LedgerSigner(ledgerTransport, {
hdPaths: [makeCosmoshubPath(0)],
- prefix: state.chain.addressPrefix,
+ prefix: state!.chain.addressPrefix,
});
-
+ console.log(offlineSigner);
const accounts = await offlineSigner.getAccounts();
- const tempWalletAccount = accounts[0].address;
+ console.log(accounts);
+ const tempWalletAccount: WalletAccount = {
+ bech32Address: accounts[0].address,
+ pubkey: accounts[0].pubkey,
+ algo: accounts[0].algo,
+ };
const tempHasSigned = props.signatures.some(
(sig) => sig.address === tempWalletAccount.bech32Address,
@@ -60,19 +74,18 @@ const TransactionSigning = (props) => {
const signTransaction = async () => {
const offlineSigner =
- walletType === "keplr" ? window.getOfflineSignerOnlyAmino(state.chain.chainId) : ledgerSigner;
-
- const signerAddress =
walletType === "keplr"
- ? walletAccount.bech32Address
- : (await ledgerSigner.getAccounts())[0]?.address;
+ ? window.getOfflineSignerOnlyAmino(state!.chain.chainId)
+ : ledgerSigner;
+
+ const signerAddress = walletAccount?.bech32Address;
assert(signerAddress, "Missing signer address");
const signingClient = await SigningStargateClient.offline(offlineSigner);
const signerData = {
accountNumber: props.tx.accountNumber,
sequence: props.tx.sequence,
- chainId: state.chain.chainId,
+ chainId: state!.chain.chainId as string,
};
const { bodyBytes, signatures } = await signingClient.sign(
diff --git a/components/head.js b/components/head.tsx
similarity index 87%
rename from components/head.js
rename to components/head.tsx
index 5e70665..51be470 100644
--- a/components/head.js
+++ b/components/head.tsx
@@ -5,7 +5,13 @@ import { string } from "prop-types";
const defaultDescription = "Create multisigs and send tokens on any cosmos based chain";
const defaultOGURL = "";
-const Head = (props) => (
+interface Props {
+ title?: string;
+ description?: string;
+ url?: string;
+}
+
+const Head = (props: Props) => (
{props.title || ""}
diff --git a/components/icons/Gear.js b/components/icons/Gear.tsx
similarity index 97%
rename from components/icons/Gear.js
rename to components/icons/Gear.tsx
index eb2b5ff..98405f7 100644
--- a/components/icons/Gear.js
+++ b/components/icons/Gear.tsx
@@ -1,6 +1,9 @@
import React from "react";
-const Gear = (props) => (
+interface Props {
+ color: string;
+}
+const Gear = (props: Props) => (