Don't have a multisig?
diff --git a/lib/multisigHelpers.ts b/lib/multisigHelpers.ts index 3fb5ee0..4edb9a8 100644 --- a/lib/multisigHelpers.ts +++ b/lib/multisigHelpers.ts @@ -1,13 +1,13 @@ -import axios from "axios"; import { createMultisigThresholdPubkey, isMultisigThresholdPubkey, MultisigThresholdPubkey, pubkeyToAddress, } from "@cosmjs/amino"; -import { Account } from "@cosmjs/stargate"; -import { StargateClient } from "@cosmjs/stargate"; +import { Account, StargateClient } from "@cosmjs/stargate"; import { assert } from "@cosmjs/utils"; +import axios from "axios"; +import { checkAddress } from "./displayHelpers"; /** * Turns array of compressed Secp256k1 pubkeys @@ -56,12 +56,18 @@ const createMultisigFromCompressedSecp256k1Pubkeys = async ( */ const getMultisigAccount = async ( address: string, + addressPrefix: string, client: StargateClient, ): Promise<[MultisigThresholdPubkey, Account | null]> => { // we need the multisig pubkeys to create transactions, if the multisig // is new, and has never submitted a transaction its pubkeys will not be // available from a node. If the multisig was created with this instance // of this tool its pubkey will be available in the fauna datastore + const addressError = checkAddress(address, addressPrefix); + if (addressError) { + throw new Error(addressError); + } + const accountOnChain = await client.getAccount(address); const chainId = await client.getChainId(); diff --git a/pages/multi/[address]/index.tsx b/pages/multi/[address]/index.tsx index 6e4484c..6fb70a9 100644 --- a/pages/multi/[address]/index.tsx +++ b/pages/multi/[address]/index.tsx @@ -49,16 +49,21 @@ const Multipage = () => { assert(state.chain.denom, "denom missing"); const tempHoldings = await client.getAllBalances(address); setHoldings(tempHoldings); - const result = await getMultisigAccount(address, client); - setPubkey(result[0]); - setAccountOnChain(result[1]); + assert(state.chain.addressPrefix, "addressPrefix missing"); + const [newPubkey, newAccountOnChain] = await getMultisigAccount( + address, + state.chain.addressPrefix, + client, + ); + setPubkey(newPubkey); + setAccountOnChain(newAccountOnChain); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { setAccountError(error.message); console.log("Account error:", error); } }, - [state.chain.denom, state.chain.nodeAddress], + [state.chain.addressPrefix, state.chain.denom, state.chain.nodeAddress], ); useEffect(() => { diff --git a/pages/multi/[address]/transaction/[transactionID].tsx b/pages/multi/[address]/transaction/[transactionID].tsx index 3d9cbab..d67c41e 100644 --- a/pages/multi/[address]/transaction/[transactionID].tsx +++ b/pages/multi/[address]/transaction/[transactionID].tsx @@ -87,7 +87,8 @@ const TransactionPage = ({ try { assert(state.chain.nodeAddress, "Node address missing"); const client = await StargateClient.connect(state.chain.nodeAddress); - const result = await getMultisigAccount(address, client); + assert(state.chain.addressPrefix, "addressPrefix missing"); + const result = await getMultisigAccount(address, state.chain.addressPrefix, client); setPubkey(result[0]); setAccountOnChain(result[1]); // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -96,7 +97,7 @@ const TransactionPage = ({ console.log("Account error:", error); } }, - [state.chain.nodeAddress], + [state.chain.addressPrefix, state.chain.nodeAddress], ); useEffect(() => {