From d224f29b4a95dfc2406d605533ccd3cef5f0b8b8 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 04:21:45 +0700 Subject: [PATCH 01/15] only show priceImpact when usd price available --- chain-registry | 2 +- src/components/SwapWidget/SwapDetails.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chain-registry b/chain-registry index 45a57c3c..8ba1a298 160000 --- a/chain-registry +++ b/chain-registry @@ -1 +1 @@ -Subproject commit 45a57c3cd4e45f327e0750934960b9f30e69d7b0 +Subproject commit 8ba1a2989ecc0d16d7628103898a77b266e4e9c8 diff --git a/src/components/SwapWidget/SwapDetails.tsx b/src/components/SwapWidget/SwapDetails.tsx index 1047a680..8b453aac 100644 --- a/src/components/SwapWidget/SwapDetails.tsx +++ b/src/components/SwapWidget/SwapDetails.tsx @@ -176,7 +176,7 @@ export const SwapDetails = ({ "[&_dd]:text-end [&_dd]:tabular-nums", )} > - {priceImpactPercent ? ( + {priceImpactPercent && route.usdAmountIn && route.usdAmountOut ? ( <>
Price Impact
{formatPercent(priceImpactPercent)}
From 10c79f48b2b2d9211b243b8b0d8913a4d8363e61 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 04:30:23 +0700 Subject: [PATCH 02/15] remove retry on error --- src/solve/queries.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solve/queries.ts b/src/solve/queries.ts index 0b57a138..5b953547 100644 --- a/src/solve/queries.ts +++ b/src/solve/queries.ts @@ -155,7 +155,7 @@ export function useRoute({ return route; }, refetchInterval: refetchCount < 10 ? 1000 * 10 : false, - retry: 1, + retry: false, enabled: enabled && !!sourceAsset && From 39f5bdc6284069370ecebbb0675d148269dd9c9f Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 05:11:42 +0700 Subject: [PATCH 03/15] native asset select on chain select or usdc --- src/components/SwapWidget/useSwapWidget.ts | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/components/SwapWidget/useSwapWidget.ts b/src/components/SwapWidget/useSwapWidget.ts index 4ab9c97e..432d68c3 100644 --- a/src/components/SwapWidget/useSwapWidget.ts +++ b/src/components/SwapWidget/useSwapWidget.ts @@ -252,7 +252,12 @@ export function useSwapWidget() { if (!asset) { const assets = assetsByChainID(chain.chainID); if (chain.chainType === "evm") { - asset = assets.find((asset) => asset.denom.endsWith("-native")); + asset = assets.find( + (asset) => + asset.denom.endsWith("-native") || + asset.name?.toLowerCase() === chain.chainName.toLowerCase() || + asset.symbol?.toLowerCase().includes("usdc"), + ); } asset ??= assets[0]; } @@ -297,9 +302,23 @@ export function useSwapWidget() { const { destinationAsset: currentDstAsset } = useSwapWidgetStore.getState(); const assets = assetsByChainID(chain.chainID); - let asset = await getFeeAsset(chain.chainID); + let feeAsset: Asset | undefined = undefined; + if (chain.chainType === "cosmos") { + feeAsset = await getFeeAsset(chain.chainID); + } + + let asset = feeAsset; if (!asset) { - [asset] = assets; + const assets = assetsByChainID(chain.chainID); + if (chain.chainType === "evm") { + asset = assets.find( + (asset) => + asset.denom.endsWith("-native") || + asset.name?.toLowerCase() === chain.chainName.toLowerCase() || + asset.symbol?.toLowerCase().includes("usdc"), + ); + } + asset ??= assets[0]; } if (currentDstAsset && userTouchedDstAsset) { const equivalentAsset = findEquivalentAsset(currentDstAsset, assets); From 4ee73f86aa8b324e9a319c96dc54c255d4aab9fc Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 09:49:37 +0700 Subject: [PATCH 04/15] hide diff percentage when usd 0 --- src/components/AssetInput.tsx | 6 ++++-- src/components/SwapWidget/SwapWidget.tsx | 6 +----- src/components/SwapWidget/useSwapWidget.ts | 9 +++++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/AssetInput.tsx b/src/components/AssetInput.tsx index fbf1c089..7097f8e0 100644 --- a/src/components/AssetInput.tsx +++ b/src/components/AssetInput.tsx @@ -178,8 +178,10 @@ function AssetInput({ }} />
-

{amountUSD ? formatUSD(amountUSD) : null}

- {amountUSD !== undefined && diffPercentage !== 0 && context === "destination" ? ( +

+ {amountUSD && Number(amountUSD) > 0 ? formatUSD(amountUSD) : null} +

+ {amountUSD !== undefined && Number(amountUSD) > 0 && diffPercentage !== 0 && context === "destination" ? (

= 0 ? "text-green-500" : "text-red-500")}> ({formatPercent(diffPercentage)})

diff --git a/src/components/SwapWidget/SwapWidget.tsx b/src/components/SwapWidget/SwapWidget.tsx index 14f69219..57c45c45 100644 --- a/src/components/SwapWidget/SwapWidget.tsx +++ b/src/components/SwapWidget/SwapWidget.tsx @@ -62,13 +62,9 @@ export function SwapWidget() { sourceFeeAmount, sourceFeeAsset, swapPriceImpactPercent, + usdDiffPercent, } = useSwapWidget(); - let usdDiffPercent = 0.0; - if (route?.usdAmountIn && route?.usdAmountOut) { - usdDiffPercent = (parseFloat(route.usdAmountOut) - parseFloat(route.usdAmountIn)) / parseFloat(route.usdAmountIn); - } - const srcAccount = useAccount("source"); const destAccount = useAccount("destination"); diff --git a/src/components/SwapWidget/useSwapWidget.ts b/src/components/SwapWidget/useSwapWidget.ts index 4ab9c97e..527624e9 100644 --- a/src/components/SwapWidget/useSwapWidget.ts +++ b/src/components/SwapWidget/useSwapWidget.ts @@ -183,8 +183,12 @@ export function useSwapWidget() { if (!route) { return undefined; } - - if (!route.usdAmountIn || !route.usdAmountOut) { + if ( + !route.usdAmountIn || + !route.usdAmountOut || + Number(route.usdAmountIn) === 0 || + Number(route.usdAmountOut) === 0 + ) { return undefined; } @@ -831,6 +835,7 @@ export function useSwapWidget() { sourceFeeAmount: gasRequired, sourceFeeAsset: srcFeeAsset, swapPriceImpactPercent, + usdDiffPercent, }; } From 9857272c6dbf726244bda5426c5b24b4b2d32197 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 09:53:53 +0700 Subject: [PATCH 05/15] show price impact --- src/components/SwapWidget/SwapDetails.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SwapWidget/SwapDetails.tsx b/src/components/SwapWidget/SwapDetails.tsx index 8b453aac..1047a680 100644 --- a/src/components/SwapWidget/SwapDetails.tsx +++ b/src/components/SwapWidget/SwapDetails.tsx @@ -176,7 +176,7 @@ export const SwapDetails = ({ "[&_dd]:text-end [&_dd]:tabular-nums", )} > - {priceImpactPercent && route.usdAmountIn && route.usdAmountOut ? ( + {priceImpactPercent ? ( <>
Price Impact
{formatPercent(priceImpactPercent)}
From 614a0b7718cd6fca0347701c7d070b91ea63d25a Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 04:17:54 +0700 Subject: [PATCH 06/15] remove client side warning logic, use from api --- src/components/SwapWidget/useSwapWidget.ts | 29 +++++----------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/components/SwapWidget/useSwapWidget.ts b/src/components/SwapWidget/useSwapWidget.ts index 95163145..b910bc27 100644 --- a/src/components/SwapWidget/useSwapWidget.ts +++ b/src/components/SwapWidget/useSwapWidget.ts @@ -25,7 +25,6 @@ import { useBalancesByChain } from "@/hooks/useBalancesByChain"; import { Chain, useChains } from "@/hooks/useChains"; import { useRoute, useSkipClient } from "@/solve"; import { getChainFeeAssets, getChainGasPrice } from "@/utils/chain.client"; -import { formatPercent, formatUSD } from "@/utils/intl"; import { getAmountWei, parseAmountWei } from "@/utils/number"; import { gracefullyConnect } from "@/utils/wallet"; @@ -199,36 +198,20 @@ export function useSwapWidget() { }, [route]); const [routeWarningTitle, routeWarningMessage] = useMemo(() => { - if (!route) { + if (!route?.warning) { return [undefined, undefined]; } - if (!route.swapPriceImpactPercent && (!route.usdAmountIn || !route.usdAmountOut)) { - return ["Low Information Trade", "We were unable to calculate the price impact of this route."]; - } - - if (usdDiffPercent && Math.abs(usdDiffPercent) > PRICE_IMPACT_THRESHOLD) { - const amountInUSD = formatUSD(parseFloat(route.usdAmountIn ?? "0")); - - const amountOutUSD = formatUSD(parseFloat(route.usdAmountOut ?? "0")); - - const formattedUsdDiffPercent = formatPercent(Math.abs(usdDiffPercent)); - return [ - "Bad Trade Warning", - `Your estimated output value (${amountOutUSD}) is ${formattedUsdDiffPercent} lower than your estimated input value (${amountInUSD}).`, - ]; + if (route.warning.type === "BAD_PRICE_WARNING") { + return ["Bad Price Warning", route.warning.message]; } - if (swapPriceImpactPercent && swapPriceImpactPercent > PRICE_IMPACT_THRESHOLD) { - const formattedPriceImpact = formatPercent(swapPriceImpactPercent); - return [ - "Bad Trade Warning", - `Your swap is expected to execute at a ${formattedPriceImpact} worse price than the current estimated on-chain price. It's likely there's not much liquidity available for this swap.`, - ]; + if (route.warning.type === "LOW_INFO_WARNING") { + return ["Low Information Warning", route.warning.message]; } return [undefined, undefined]; - }, [route, swapPriceImpactPercent, usdDiffPercent]); + }, [route]); // #endregion From b8b617e3d8645224ee1b06ef67703a8a1e27b5ae Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 05:17:54 +0700 Subject: [PATCH 07/15] remove low info trade --- src/components/SwapWidget/useSwapWidget.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/SwapWidget/useSwapWidget.ts b/src/components/SwapWidget/useSwapWidget.ts index b910bc27..33e09c29 100644 --- a/src/components/SwapWidget/useSwapWidget.ts +++ b/src/components/SwapWidget/useSwapWidget.ts @@ -206,10 +206,6 @@ export function useSwapWidget() { return ["Bad Price Warning", route.warning.message]; } - if (route.warning.type === "LOW_INFO_WARNING") { - return ["Low Information Warning", route.warning.message]; - } - return [undefined, undefined]; }, [route]); From 0600cb9daf7ee032be77f45fc66a970cbeb7757b Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 11:58:17 +0700 Subject: [PATCH 08/15] feat: don't refetch if it's a known error --- src/solve/queries.ts | 78 +++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/src/solve/queries.ts b/src/solve/queries.ts index 5b953547..6f9f7468 100644 --- a/src/solve/queries.ts +++ b/src/solve/queries.ts @@ -73,7 +73,7 @@ export function useRoute({ const skipClient = useSkipClient(); const [refetchCount, setRefetchCount] = useState(0); - + const [isError, setIsError] = useState(false); const { data: experimentalFeatures } = useExperimentalFeatures(); const queryKey = useMemo( @@ -119,42 +119,53 @@ export function useRoute({ if (!sourceAsset || !sourceAssetChainID || !destinationAsset || !destinationAssetChainID) { return; } + try { + const route = await skipClient.route( + direction === "swap-in" + ? { + amountIn: amount, + sourceAssetDenom: sourceAsset, + sourceAssetChainID: sourceAssetChainID, + destAssetDenom: destinationAsset, + destAssetChainID: destinationAssetChainID, + swapVenue, + allowMultiTx: true, + allowUnsafe: true, + experimentalFeatures, + smartRelay: true, + } + : { + amountOut: amount, + sourceAssetDenom: sourceAsset, + sourceAssetChainID: sourceAssetChainID, + destAssetDenom: destinationAsset, + destAssetChainID: destinationAssetChainID, + swapVenue, + allowMultiTx: true, + allowUnsafe: true, + experimentalFeatures, + smartRelay: true, + }, + ); - const route = await skipClient.route( - direction === "swap-in" - ? { - amountIn: amount, - sourceAssetDenom: sourceAsset, - sourceAssetChainID: sourceAssetChainID, - destAssetDenom: destinationAsset, - destAssetChainID: destinationAssetChainID, - swapVenue, - allowMultiTx: true, - allowUnsafe: true, - experimentalFeatures, - smartRelay: true, - } - : { - amountOut: amount, - sourceAssetDenom: sourceAsset, - sourceAssetChainID: sourceAssetChainID, - destAssetDenom: destinationAsset, - destAssetChainID: destinationAssetChainID, - swapVenue, - allowMultiTx: true, - allowUnsafe: true, - experimentalFeatures, - smartRelay: true, - }, - ); + if (!route.operations) { + throw new Error("No route found"); + } - if (!route.operations) { - throw new Error("No route found"); + return route; + } catch (error) { + if ( + // @ts-expect-error - error + String(error?.message).toLowerCase().includes("no routes found") || + // @ts-expect-error - error + String(error?.message).toLowerCase().includes("smart relay") + ) { + setIsError(true); + } + throw error; } - - return route; }, - refetchInterval: refetchCount < 10 ? 1000 * 10 : false, + refetchInterval: isError ? false : refetchCount < 10 ? 1000 * 1 : false, retry: false, enabled: enabled && @@ -172,6 +183,7 @@ export function useRoute({ }, [query.isRefetching]); useEffect(() => { + setIsError(false); setRefetchCount(0); }, [queryKey]); From 0bfb7281af0a89d1cdc753760367b62bc21c1dd3 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 11:59:23 +0700 Subject: [PATCH 09/15] update error message --- src/solve/queries.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solve/queries.ts b/src/solve/queries.ts index 6f9f7468..f5691133 100644 --- a/src/solve/queries.ts +++ b/src/solve/queries.ts @@ -149,7 +149,7 @@ export function useRoute({ ); if (!route.operations) { - throw new Error("No route found"); + throw new Error("no routes found"); } return route; From 0727cba65936ef1d33bf9338dd54667eca296276 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 11:59:52 +0700 Subject: [PATCH 10/15] Update src/solve/queries.ts Co-authored-by: Not Jeremy Liu <31809888+NotJeremyLiu@users.noreply.github.com> --- src/solve/queries.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solve/queries.ts b/src/solve/queries.ts index f5691133..ef9a28b3 100644 --- a/src/solve/queries.ts +++ b/src/solve/queries.ts @@ -158,7 +158,7 @@ export function useRoute({ // @ts-expect-error - error String(error?.message).toLowerCase().includes("no routes found") || // @ts-expect-error - error - String(error?.message).toLowerCase().includes("smart relay") + String(error?.message).toLowerCase().includes("relay") ) { setIsError(true); } From 80eb63f66f7e4654b946016fdedb51618da67e1f Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 12:04:40 +0700 Subject: [PATCH 11/15] refetch duration 10s --- src/solve/queries.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solve/queries.ts b/src/solve/queries.ts index ef9a28b3..dced9076 100644 --- a/src/solve/queries.ts +++ b/src/solve/queries.ts @@ -165,7 +165,7 @@ export function useRoute({ throw error; } }, - refetchInterval: isError ? false : refetchCount < 10 ? 1000 * 1 : false, + refetchInterval: isError ? false : refetchCount < 10 ? 1000 * 10 : false, retry: false, enabled: enabled && From d24bc4c3a337521fafc8e4b74cb21f5727246f95 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Tue, 16 Apr 2024 12:17:48 +0700 Subject: [PATCH 12/15] no warning when no usd amount --- src/components/SwapWidget/useSwapWidget.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/SwapWidget/useSwapWidget.ts b/src/components/SwapWidget/useSwapWidget.ts index 33e09c29..f7f4610f 100644 --- a/src/components/SwapWidget/useSwapWidget.ts +++ b/src/components/SwapWidget/useSwapWidget.ts @@ -202,6 +202,10 @@ export function useSwapWidget() { return [undefined, undefined]; } + if (Number(route.usdAmountIn) === 0 || Number(route.usdAmountOut) === 0) { + return [undefined, undefined]; + } + if (route.warning.type === "BAD_PRICE_WARNING") { return ["Bad Price Warning", route.warning.message]; } From 96ba77be3c6f2c8a7d904b5ab759efee5bde5777 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Wed, 17 Apr 2024 03:36:29 +0700 Subject: [PATCH 13/15] fix: staging not using the right app url --- src/constants/api.ts | 2 +- vercel.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/constants/api.ts b/src/constants/api.ts index 7b486736..8ba75bf3 100644 --- a/src/constants/api.ts +++ b/src/constants/api.ts @@ -3,7 +3,7 @@ export const API_URL = process.env.NEXT_PUBLIC_API_URL || "https://api.skip.mone export const APP_URL = process.env.APP_URL; export const appUrl = - process.env.NEXT_PUBLIC_VERCEL_ENV === "preview" + process.env.NEXT_PUBLIC_VERCEL_ENV === "preview" || process.env.NEXT_PUBLIC_VERCEL_ENV === "staging" ? typeof window !== "undefined" ? `https://${window.location.hostname}` : process.env.NEXT_PUBLIC_VERCEL_URL diff --git a/vercel.d.ts b/vercel.d.ts index a726c39a..812eb1e1 100644 --- a/vercel.d.ts +++ b/vercel.d.ts @@ -43,7 +43,7 @@ declare namespace NodeJS { readonly VERCEL_GIT_PREVIOUS_SHA?: string; readonly VERCEL_GIT_PULL_REQUEST_ID?: string; - readonly NEXT_PUBLIC_VERCEL_ENV?: "production" | "preview" | "development"; + readonly NEXT_PUBLIC_VERCEL_ENV?: "production" | "preview" | "development" | "staging"; readonly NEXT_PUBLIC_VERCEL_URL?: string; readonly NEXT_PUBLIC_VERCEL_BRANCH_URL?: string; readonly NEXT_PUBLIC_VERCEL_AUTOMATION_BYPASS_SECRET?: string; From 653ae0c54b6b693b35b8dd861d157d80ba0c3397 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Wed, 17 Apr 2024 03:40:10 +0700 Subject: [PATCH 14/15] update testnet-dev workflow file --- .github/workflows/deploy-testnet-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-testnet-dev.yml b/.github/workflows/deploy-testnet-dev.yml index 3125956b..52211a9f 100644 --- a/.github/workflows/deploy-testnet-dev.yml +++ b/.github/workflows/deploy-testnet-dev.yml @@ -17,7 +17,7 @@ jobs: name: Checkout uses: actions/checkout@v3 with: - ref: testnet + ref: testnet-dev - id: pull-staging name: Pull latest 'staging' From 42366a48ccba46f9c106c282a388ab1e98389158 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Wed, 17 Apr 2024 03:49:10 +0700 Subject: [PATCH 15/15] fix: testnet push workflow --- .github/workflows/deploy-testnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-testnet.yml b/.github/workflows/deploy-testnet.yml index d9d6ef79..4ceed1aa 100644 --- a/.github/workflows/deploy-testnet.yml +++ b/.github/workflows/deploy-testnet.yml @@ -21,7 +21,7 @@ jobs: - id: pull-staging name: Pull latest 'staging' - run: git pull origin staging + run: git pull --ff-only origin staging - id: diff-check name: Check if 'testnet' is behind 'staging'