diff --git a/src/components/Attest/Target.tsx b/src/components/Attest/Target.tsx index 093e6daf2..f8574e073 100644 --- a/src/components/Attest/Target.tsx +++ b/src/components/Attest/Target.tsx @@ -16,7 +16,7 @@ import ButtonWithLoader from "../ButtonWithLoader"; import ChainSelect from "../ChainSelect"; import KeyAndBalance from "../KeyAndBalance"; import LowBalanceWarning from "../LowBalanceWarning"; -import { isCosmosChain } from "../../utils/cosmos"; +import { isGatewayCosmosChain } from "../../utils/cosmos"; const useStyles = makeStyles((theme) => ({ alert: { @@ -58,7 +58,7 @@ function Target() { /> {/* In the case of cosmos chain target no fees are required */} - {!isCosmosChain(targetChain) && ( + {!isGatewayCosmosChain(targetChain) && ( You will have to pay transaction fees on{" "} diff --git a/src/hooks/useHandleCreateWrapped.tsx b/src/hooks/useHandleCreateWrapped.tsx index ba8b11cc4..3e6b1862b 100644 --- a/src/hooks/useHandleCreateWrapped.tsx +++ b/src/hooks/useHandleCreateWrapped.tsx @@ -113,7 +113,7 @@ import { } from "../utils/sei"; import { useSeiWallet } from "../contexts/SeiWalletContext"; import { SeiWallet } from "@xlabs-libs/wallet-aggregator-sei"; -import { queryWormchain, isCosmosChain } from "../utils/cosmos"; +import { queryWormchain, isGatewayCosmosChain } from "../utils/cosmos"; // TODO: replace with SDK method - export async function updateWrappedOnSui( @@ -691,19 +691,39 @@ async function cosmos( ) { dispatch(setIsCreating(true)); let tries = 0; + const nTries = 5; let messageShow = false; - const interval = setInterval(async () => { + let timer = 3500; + function changeTimer() { + timer = timer * 1.2; + } + let interval: NodeJS.Timeout | undefined; + const resetTimer = () => { + clearTimeout(interval); + changeTimer(); + interval = setTimeout(query, timer); + } + const query = async () => { try { - if (tries <= 5) { + if (tries <= nTries) { tries++; const txs = await queryWormchain(sourceChainAddress, sourceChain); + if (txs.length === 0) { - return null; + resetTimer(); + if (tries > nTries) { + throw new Error("Transaction not found"); + } + return; } if (txs.length > 1) { - throw new Error("Multiple transactions found"); + resetTimer(); + if (tries > nTries) { + throw new Error("Multiple transactions found"); + } + return; } - clearInterval(interval); + clearTimeout(interval); dispatch( setCreateTx({ id: txs[0].hash, @@ -716,8 +736,8 @@ async function cosmos( content: Transaction confirmed, }); } - } else { - clearInterval(interval); + resetTimer(); + } else { dispatch(setIsCreating(false)); } } catch (e) { @@ -726,8 +746,10 @@ async function cosmos( content: {parseError(e)}, }); dispatch(setIsCreating(false)); + resetTimer(); } - }, 3500); + }; + await query(); } export function useHandleCreateWrapped( @@ -849,7 +871,7 @@ export function useHandleCreateWrapped( !!signedVAA ) { sui(dispatch, enqueueSnackbar, suiWallet, signedVAA, foreignAddress); - } else if (isCosmosChain(targetChain as any) && !!signedVAA) { + } else if (isGatewayCosmosChain(targetChain as any) && !!signedVAA) { cosmos( dispatch, enqueueSnackbar, diff --git a/src/hooks/useIsWalletReady.ts b/src/hooks/useIsWalletReady.ts index ac2cdf8b3..ca5e99a82 100644 --- a/src/hooks/useIsWalletReady.ts +++ b/src/hooks/useIsWalletReady.ts @@ -23,7 +23,7 @@ import { useInjectiveContext } from "../contexts/InjectiveWalletContext"; import { useTerraWallet } from "../contexts/TerraWalletContext"; import { useSuiWallet } from "../contexts/SuiWalletContext"; import { useSeiWallet } from "../contexts/SeiWalletContext"; -import { isCosmosChain } from "../utils/cosmos"; +import { isGatewayCosmosChain } from "../utils/cosmos"; const createWalletStatus = ( isReady: boolean, @@ -132,7 +132,7 @@ function useIsWalletReady( ); } } - if (isCosmosChain(chainId)) { + if (isGatewayCosmosChain(chainId)) { return createWalletStatus(true, undefined); } diff --git a/src/utils/consts.ts b/src/utils/consts.ts index 20335cbed..9124a5ee9 100644 --- a/src/utils/consts.ts +++ b/src/utils/consts.ts @@ -573,7 +573,7 @@ export const WORMCHAIN_CONTRACTS_MAINNET = { core: "wormhole1ufs3tlq4umljk0qfe8k5ya0x6hpavn897u2cnf9k0en9jr7qarqqaqfk2j", token_bridge: "wormhole1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjq4lyjmh", - ibcShimContract: + ibc_shim_contract: "wormhole14ejqjyq8um4p3xfqj74yld5waqljf88fz25yxnma0cngspxe3les00fpjx", }; @@ -581,7 +581,7 @@ export const WORMCHAIN_CONTRACTS_TESTNET = { core: "wormhole16jzpxp0e8550c9aht6q9svcux30vtyyyyxv5w2l2djjra46580wsazcjwp", token_bridge: "wormhole1aaf9r6s7nxhysuegqrxv0wpm27ypyv4886medd3mrkrw6t4yfcnst3qpex", - ibcShimContract: + ibc_shim_contract: "wormhole1ctnjk7an90lz5wjfvr3cf6x984a8cjnv8dpmztmlpcq4xteaa2xs9pwmzk", }; diff --git a/src/utils/cosmos.ts b/src/utils/cosmos.ts index 6bc180386..036e87c10 100644 --- a/src/utils/cosmos.ts +++ b/src/utils/cosmos.ts @@ -44,8 +44,7 @@ export async function getCosmWasmClient(): Promise { export async function queryWormchain(token: string, chainId: ChainId) { const client = await getCosmWasmClient(); const bytes = Array.from(tryNativeToUint8Array(token, chainId)); - console.log(bytes); - console.log(`ExternalTokenId { bytes: [${bytes.join(", ")}] }`); + const res = await client.searchTx([ { key: "wasm.action", value: "register_asset" }, { key: "wasm.token_chain", value: `${chainId}` }, @@ -58,7 +57,7 @@ export async function queryWormchain(token: string, chainId: ChainId) { return res; } -export const isCosmosChain = (chain: ChainId) => { +export const isGatewayCosmosChain = (chain: ChainId) => { return ( chain === CHAIN_ID_KUJIRA || chain === CHAIN_ID_OSMOSIS ||