Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonator committed Jun 6, 2024
1 parent 5ea2c22 commit 2c73f13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions packages/web/components/swap-tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,10 @@ export const SwapTool: FunctionComponent<SwapToolProps> = observer(
});
}
})
.catch(() => {
console.log("reject sig");
logEvent([EventName.Swap.swapFailed, baseEvent]);
.catch((e) => {
if (e instanceof Error && e.message.includes("Failed to send")) {
logEvent([EventName.Swap.swapFailed, baseEvent]);
}
})
.finally(() => {
setIsSendingTx(false);
Expand Down
18 changes: 12 additions & 6 deletions packages/web/hooks/use-swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,16 @@ export function useSwap(
() =>
new Promise<"multiroute" | "multihop" | "exact-in">(
async (resolve, reject) => {
if (!maxSlippage) return reject(new Error("No max slippage"));
if (!maxSlippage)
return reject(new Error("Max slippage is not defined."));
if (!inAmountInput.amount)
return reject(new Error("No input amount"));
if (!account) return reject(new Error("No account"));
if (!swapAssets.fromAsset) return reject(new Error("No from asset"));
if (!swapAssets.toAsset) return reject(new Error("No to asset"));
return reject(new Error("Input amount is not specified."));
if (!account)
return reject(new Error("Account information is missing."));
if (!swapAssets.fromAsset)
return reject(new Error("From asset is not specified."));
if (!swapAssets.toAsset)
return reject(new Error("To asset is not specified."));

let txParams: ReturnType<typeof getSwapTxParameters>;
try {
Expand All @@ -287,7 +291,9 @@ export function useSwap(
});
} catch (e) {
const error = e as Error;
return reject(error);
return reject(
new Error(`Transaction preparation failed: ${error.message}`)
);
}

const { routes, tokenIn, tokenOutMinAmount } = txParams;
Expand Down

0 comments on commit 2c73f13

Please sign in to comment.