Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yuli-ferna committed Apr 11, 2024
1 parent 28fccba commit 5f3deb8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/components/Attest/Target.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -58,7 +58,7 @@ function Target() {
/>
<KeyAndBalance chainId={targetChain} />
{/* In the case of cosmos chain target no fees are required */}
{!isCosmosChain(targetChain) && (
{!isGatewayCosmosChain(targetChain) && (
<Alert severity="info" variant="outlined" className={classes.alert}>
<Typography>
You will have to pay transaction fees on{" "}
Expand Down
42 changes: 32 additions & 10 deletions src/hooks/useHandleCreateWrapped.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -716,8 +736,8 @@ async function cosmos(
content: <Alert severity="success">Transaction confirmed</Alert>,
});
}
} else {
clearInterval(interval);
resetTimer();
} else {
dispatch(setIsCreating(false));
}
} catch (e) {
Expand All @@ -726,8 +746,10 @@ async function cosmos(
content: <Alert severity="error">{parseError(e)}</Alert>,
});
dispatch(setIsCreating(false));
resetTimer();
}
}, 3500);
};
await query();
}

export function useHandleCreateWrapped(
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useIsWalletReady.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -132,7 +132,7 @@ function useIsWalletReady(
);
}
}
if (isCosmosChain(chainId)) {
if (isGatewayCosmosChain(chainId)) {
return createWalletStatus(true, undefined);
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,15 @@ export const WORMCHAIN_CONTRACTS_MAINNET = {
core: "wormhole1ufs3tlq4umljk0qfe8k5ya0x6hpavn897u2cnf9k0en9jr7qarqqaqfk2j",
token_bridge:
"wormhole1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjq4lyjmh",
ibcShimContract:
ibc_shim_contract:
"wormhole14ejqjyq8um4p3xfqj74yld5waqljf88fz25yxnma0cngspxe3les00fpjx",
};

export const WORMCHAIN_CONTRACTS_TESTNET = {
core: "wormhole16jzpxp0e8550c9aht6q9svcux30vtyyyyxv5w2l2djjra46580wsazcjwp",
token_bridge:
"wormhole1aaf9r6s7nxhysuegqrxv0wpm27ypyv4886medd3mrkrw6t4yfcnst3qpex",
ibcShimContract:
ibc_shim_contract:
"wormhole1ctnjk7an90lz5wjfvr3cf6x984a8cjnv8dpmztmlpcq4xteaa2xs9pwmzk",
};

Expand Down
5 changes: 2 additions & 3 deletions src/utils/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export async function getCosmWasmClient(): Promise<CosmWasmClient> {
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}` },
Expand All @@ -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 ||
Expand Down

0 comments on commit 5f3deb8

Please sign in to comment.