From 53e86026435194d62d14efd719277b59222b906f Mon Sep 17 00:00:00 2001 From: yjin Date: Tue, 7 Jan 2025 17:45:03 +0900 Subject: [PATCH] fix: [GSW-2048] UI when in NO_LIQUIDITY state --- packages/web/src/hooks/swap/data/use-swap.tsx | 2 +- .../src/react-query/router/use-get-routes.ts | 20 ++++++++++++++----- .../swap/response/get-routes-response.ts | 1 + .../swap/swap-router-repository-mock.ts | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/web/src/hooks/swap/data/use-swap.tsx b/packages/web/src/hooks/swap/data/use-swap.tsx index c40b4cc0e..31e248505 100644 --- a/packages/web/src/hooks/swap/data/use-swap.tsx +++ b/packages/web/src/hooks/swap/data/use-swap.tsx @@ -108,7 +108,7 @@ export const useSwap = ({ tokenA, tokenB, direction, slippage, swapFee = 15 }: U return "LOADING"; } - if (!!error || !estimatedSwapResult?.amount) { + if (estimatedSwapResult?.status === "NO_LIQUIDITY" || estimatedSwapResult?.status === "INVALID_PARAMS") { return "NO_LIQUIDITY"; } diff --git a/packages/web/src/react-query/router/use-get-routes.ts b/packages/web/src/react-query/router/use-get-routes.ts index 9deeb6d43..d09402715 100644 --- a/packages/web/src/react-query/router/use-get-routes.ts +++ b/packages/web/src/react-query/router/use-get-routes.ts @@ -8,8 +8,8 @@ import { GetRoutesResponse } from "@repositories/swap/response/get-routes-respon import { QUERY_KEY } from "../query-keys"; import { useGetAllTokenPrices } from "@query/token"; -const REFETCH_INTERVAL = 10_000; -const STALE_TIME = 10_000; +const REFETCH_INTERVAL = 5_000; +const STALE_TIME = 0; export const useGetRoutes = ( request: { @@ -53,7 +53,11 @@ export const useGetRoutes = ( }); if (!result) { - throw new SwapError("NOT_FOUND_SWAP_POOL"); + return { + estimatedRoutes: [], + amount: "0", + status: "NO_LIQUIDITY", + }; } // Updating Swap Route Data while also updating token price information @@ -62,10 +66,16 @@ export const useGetRoutes = ( const availRoute = result.estimatedRoutes.reduce((accumulated, current) => accumulated + current.quote, 0); if (availRoute < 100) { - throw new SwapError("NOT_FOUND_SWAP_POOL"); + return { + ...result, + status: "NO_LIQUIDITY", + }; } - return result; + return { + ...result, + status: "SUCCESS", + }; }, retry: 1, refetchInterval: REFETCH_INTERVAL, diff --git a/packages/web/src/repositories/swap/response/get-routes-response.ts b/packages/web/src/repositories/swap/response/get-routes-response.ts index 53dfc8436..f1b2fc781 100644 --- a/packages/web/src/repositories/swap/response/get-routes-response.ts +++ b/packages/web/src/repositories/swap/response/get-routes-response.ts @@ -3,4 +3,5 @@ import { EstimatedRoute } from "@models/swap/swap-route-info"; export interface GetRoutesResponse { estimatedRoutes: EstimatedRoute[]; amount: string; + status: "SUCCESS" | "NO_LIQUIDITY" | "INVALID_PARAMS"; } diff --git a/packages/web/src/repositories/swap/swap-router-repository-mock.ts b/packages/web/src/repositories/swap/swap-router-repository-mock.ts index 2f531a9ff..52add7402 100644 --- a/packages/web/src/repositories/swap/swap-router-repository-mock.ts +++ b/packages/web/src/repositories/swap/swap-router-repository-mock.ts @@ -12,6 +12,7 @@ export class SwapRouterRepositoryMock implements SwapRouterRepository { return { estimatedRoutes: [], amount: "0", + status: "NO_LIQUIDITY", }; };