Skip to content

Commit

Permalink
fix: [GSW-2048] UI when in NO_LIQUIDITY state
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrg committed Jan 7, 2025
1 parent 37e6200 commit 53e8602
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/web/src/hooks/swap/data/use-swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
20 changes: 15 additions & 5 deletions packages/web/src/react-query/router/use-get-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class SwapRouterRepositoryMock implements SwapRouterRepository {
return {
estimatedRoutes: [],
amount: "0",
status: "NO_LIQUIDITY",
};
};

Expand Down

0 comments on commit 53e8602

Please sign in to comment.