Skip to content

Commit

Permalink
fix(ui): Fix basic Wormhole form bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
wormat committed Oct 21, 2022
1 parent dfdb38e commit eec9295
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions apps/ui/src/components/WormholeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import type { ReadonlyRecord } from "@swim-io/utils";
import { findOrThrow } from "@swim-io/utils";
import Decimal from "decimal.js";
import { utils as ethersUtils } from "ethers";
import type { ReactElement } from "react";
import type { FormEvent, ReactElement } from "react";
import { useEffect, useMemo, useState } from "react";
import type { UseQueryResult } from "react-query";
import { useQuery } from "react-query";
Expand Down Expand Up @@ -73,11 +73,10 @@ const EVM_NETWORKS: ReadonlyRecord<EVMChainId, number> = {
const getDetailsByChainId = (
token: WormholeToken,
chainId: ChainId,
): WormholeTokenDetails =>
findOrThrow(
[token.nativeDetails, ...token.wrappedDetails],
): WormholeTokenDetails | null =>
[token.nativeDetails, ...token.wrappedDetails].find(
(details) => details.chainId === chainId,
);
) ?? null;

const useErc20BalanceQuery = ({
chainId,
Expand Down Expand Up @@ -160,6 +159,9 @@ export const WormholeForm = (): ReactElement => {
const { mutateAsync: transfer, isLoading } = useWormholeTransfer();

const sourceDetails = getDetailsByChainId(currentToken, sourceChainId);
if (sourceDetails === null) {
throw new Error("Missing source details");
}
const targetDetails = getDetailsByChainId(currentToken, targetChainId);
const splBalance = useUserSolanaTokenBalance(
sourceChainId === CHAIN_ID_SOLANA ? sourceDetails : null,
Expand All @@ -171,8 +173,13 @@ export const WormholeForm = (): ReactElement => {
setTxResults((previousResults) => [...previousResults, txResult]);
};

const handleSubmit = () => {
const handleSubmit = (event: FormEvent) => {
event.preventDefault();
(async (): Promise<void> => {
console.log(sourceDetails, targetDetails);
if (targetDetails === null) {
throw new Error("Missing target details");
}
setTxResults([]);
await transfer({
interactionId: generateId(),
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/hooks/wormhole/useTransferEvmToSolanaMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ export const useTransferEvmToSolanaMutation = () => {
undefined,
retries,
);
const splTxGenerator = solanaClient.generateCompletePortalTransferTxs({
const solanaTxGenerator = solanaClient.generateCompletePortalTransferTxs({
interactionId,
vaa,
wallet: solanaWallet,
auxiliarySigner,
});

for await (const result of splTxGenerator) {
for await (const result of solanaTxGenerator) {
onTxResult({
chainId: targetDetails.chainId,
txId: result.tx.id,
Expand Down

0 comments on commit eec9295

Please sign in to comment.