From cd092a7220aae14aaac965720f3cc56db1df88a6 Mon Sep 17 00:00:00 2001 From: jinoosss Date: Sat, 16 Dec 2023 14:44:55 +0900 Subject: [PATCH 1/5] fix: Remove default height in Pool Selection Graph --- .../common/pool-selection-graph/PoolSelectionGraph.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web/src/components/common/pool-selection-graph/PoolSelectionGraph.tsx b/packages/web/src/components/common/pool-selection-graph/PoolSelectionGraph.tsx index 932a6927b..c4d1323a9 100644 --- a/packages/web/src/components/common/pool-selection-graph/PoolSelectionGraph.tsx +++ b/packages/web/src/components/common/pool-selection-graph/PoolSelectionGraph.tsx @@ -257,10 +257,10 @@ const PoolSelectionGraph: React.FC = ({ return resolvedBins().map((bin) => { const x = bin.x + 1; - const y = scaleY(bin.y); + const y = bin.y > 0 ? scaleY(bin.y) : 0; const fill = fillByBin(bin); const width = bin.width - 1; - const height = boundsHeight - y; + const height = bin.y > 0 ? boundsHeight - y : 0; return { x, From af881718f5c7c4334e98907f1241f49beb44abbb Mon Sep 17 00:00:00 2001 From: jinoosss Date: Sat, 16 Dec 2023 15:17:56 +0900 Subject: [PATCH 2/5] fix: Handle when selecting the same wrappedPath token --- .../EarnAddLiquidityContainer.tsx | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/packages/web/src/containers/earn-add-liquidity-container/EarnAddLiquidityContainer.tsx b/packages/web/src/containers/earn-add-liquidity-container/EarnAddLiquidityContainer.tsx index 259e1ca54..f3429aad7 100644 --- a/packages/web/src/containers/earn-add-liquidity-container/EarnAddLiquidityContainer.tsx +++ b/packages/web/src/containers/earn-add-liquidity-container/EarnAddLiquidityContainer.tsx @@ -75,7 +75,7 @@ const EarnAddLiquidityContainer: React.FC = () => { }); setIsEarnAdd(false); }, []); - + const { connected: connectedWallet, account, @@ -200,19 +200,37 @@ const EarnAddLiquidityContainer: React.FC = () => { }, []); const changeTokenA = useCallback((token: TokenModel) => { - setSwapValue((prev) => ({ - tokenA: prev.tokenB?.symbol === token.symbol ? prev.tokenB : token, - tokenB: prev.tokenB?.symbol === token.symbol ? prev.tokenA : prev.tokenB, - type: type, - })); + setSwapValue((prev) => { + if (token.wrappedPath === prev.tokenB?.wrappedPath) { + return { + tokenA: token, + tokenB: null, + type: type, + }; + } + return { + tokenA: prev.tokenB?.symbol === token.symbol ? prev.tokenB : token, + tokenB: prev.tokenB?.symbol === token.symbol ? prev.tokenA : prev.tokenB, + type: type, + }; + }); }, [type]); const changeTokenB = useCallback((token: TokenModel) => { - setSwapValue((prev) => ({ - tokenB: prev.tokenA?.symbol === token.symbol ? prev.tokenA : token, - tokenA: prev.tokenA?.symbol === token.symbol ? prev.tokenB : prev.tokenA, - type: type, - })); + setSwapValue((prev) => { + if (token.wrappedPath === prev.tokenA?.wrappedPath) { + return { + tokenA: null, + tokenB: token, + type: type, + }; + } + return { + tokenB: prev.tokenA?.symbol === token.symbol ? prev.tokenA : token, + tokenA: prev.tokenA?.symbol === token.symbol ? prev.tokenB : prev.tokenA, + type: type, + }; + }); }, [type]); const changeStartingPrice = useCallback((price: string) => { From 493feb6ca0a94caed8b9da22f74b134045c6da8f Mon Sep 17 00:00:00 2001 From: jinoosss Date: Sat, 16 Dec 2023 15:27:03 +0900 Subject: [PATCH 3/5] fix: Fix a Price rate description --- .../SelectPriceRangeCutomController.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web/src/components/common/select-price-range-cutom-controller/SelectPriceRangeCutomController.tsx b/packages/web/src/components/common/select-price-range-cutom-controller/SelectPriceRangeCutomController.tsx index cc64d9a6b..ad3ad080b 100644 --- a/packages/web/src/components/common/select-price-range-cutom-controller/SelectPriceRangeCutomController.tsx +++ b/packages/web/src/components/common/select-price-range-cutom-controller/SelectPriceRangeCutomController.tsx @@ -36,7 +36,7 @@ const SelectPriceRangeCutomController: React.FC { - return `${token0Symbol} per ${token1Symbol}`; + return `${token1Symbol} per ${token0Symbol}`; }, [token0Symbol, token1Symbol]); const disabledController = useMemo(() => { From 264dc196189ae9b0eb0b8ef6e8a14f37c4ac6394 Mon Sep 17 00:00:00 2001 From: jinoosss Date: Sat, 16 Dec 2023 18:00:26 +0900 Subject: [PATCH 4/5] fix: Handle when selecting the same wrappedPath token --- .../earn-add/earn-add-liquidity/EarnAddLiquidity.tsx | 3 --- .../EarnAddLiquidityContainer.tsx | 5 +++++ .../web/src/layouts/earn-add-layout/EarnAddLayout.styles.ts | 2 +- .../web/src/layouts/pool-add-layout/PoolAddLayout.styles.ts | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/web/src/components/earn-add/earn-add-liquidity/EarnAddLiquidity.tsx b/packages/web/src/components/earn-add/earn-add-liquidity/EarnAddLiquidity.tsx index ade21c3bf..bca04fc78 100644 --- a/packages/web/src/components/earn-add/earn-add-liquidity/EarnAddLiquidity.tsx +++ b/packages/web/src/components/earn-add/earn-add-liquidity/EarnAddLiquidity.tsx @@ -77,7 +77,6 @@ const EarnAddLiquidity: React.FC = ({ connected, slippage, changeSlippage, - handleClickOneStaking, openModal, selectPool, changeStartingPrice @@ -164,7 +163,6 @@ const EarnAddLiquidity: React.FC = ({ if (tokenA && tokenA.symbol !== token.symbol) { setOpenedFeeTier(true); setOpenedPriceRange(true); - handleClickOneStaking?.(); } changeTokenB(token); }, [changeTokenB, tokenA, tokenB]); @@ -173,7 +171,6 @@ const EarnAddLiquidity: React.FC = ({ if (tokenB && tokenB.symbol !== token.symbol) { setOpenedFeeTier(true); setOpenedPriceRange(true); - handleClickOneStaking?.(); } changeTokenA(token); }, [changeTokenA, tokenA, tokenB]); diff --git a/packages/web/src/containers/earn-add-liquidity-container/EarnAddLiquidityContainer.tsx b/packages/web/src/containers/earn-add-liquidity-container/EarnAddLiquidityContainer.tsx index f3429aad7..1c2e7b247 100644 --- a/packages/web/src/containers/earn-add-liquidity-container/EarnAddLiquidityContainer.tsx +++ b/packages/web/src/containers/earn-add-liquidity-container/EarnAddLiquidityContainer.tsx @@ -393,6 +393,11 @@ const EarnAddLiquidityContainer: React.FC = () => { } }, [selectPool.feeTier]); + useEffect(() => { + const isEarnAdd = swapValue.tokenA !== null && swapValue.tokenB !== null; + setIsEarnAdd(isEarnAdd); + }, [setIsEarnAdd, swapValue]); + return ( css` padding: 0 40px; ${mixins.flexbox("column", "flex-start", "center")}; } - .wrapper-sub-content { { + .wrapper-sub-content { ${mixins.flexbox("column", "flex-start", "center")}; width: 100%; } diff --git a/packages/web/src/layouts/pool-add-layout/PoolAddLayout.styles.ts b/packages/web/src/layouts/pool-add-layout/PoolAddLayout.styles.ts index b3fa9fe8d..bc6933963 100644 --- a/packages/web/src/layouts/pool-add-layout/PoolAddLayout.styles.ts +++ b/packages/web/src/layouts/pool-add-layout/PoolAddLayout.styles.ts @@ -53,7 +53,7 @@ export const wrapper = (theme: Theme) => css` padding: 0 40px; ${mixins.flexbox("column", "flex-start", "center")}; } - .wrapper-sub-content { { + .wrapper-sub-content { ${mixins.flexbox("column", "flex-start", "center")}; width: 100%; } From 1f42eabf93ec550830747f26c4fa2ca570ca7d63 Mon Sep 17 00:00:00 2001 From: jinoosss Date: Sun, 17 Dec 2023 16:42:53 +0900 Subject: [PATCH 5/5] fix: Change swap parmas and state --- .../containers/swap-container/SwapContainer.tsx | 5 ++++- .../token-swap-container/TokenSwapContainer.tsx | 5 ++++- packages/web/src/hooks/swap/use-swap.tsx | 14 +++++++++++++- .../swap/swap-router-repository-impl.ts | 4 ++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/web/src/containers/swap-container/SwapContainer.tsx b/packages/web/src/containers/swap-container/SwapContainer.tsx index 0f32d55c8..91129a336 100644 --- a/packages/web/src/containers/swap-container/SwapContainer.tsx +++ b/packages/web/src/containers/swap-container/SwapContainer.tsx @@ -50,7 +50,7 @@ const SwapContainer: React.FC = () => { const { openModal } = useConnectWalletModal(); - const { estimatedRoutes, tokenAmountLimit, swap, estimateSwapRoute, unwrapToken } = useSwap({ + const { estimatedRoutes, tokenAmountLimit, swapState, swap, estimateSwapRoute, unwrapToken } = useSwap({ tokenA, tokenB, direction: type, @@ -129,6 +129,9 @@ const SwapContainer: React.FC = () => { ) { return "Amount Too Low"; } + if (swapState === "NO_LIQUIDITY") { + return "Insufficient Liquidity"; + } if (type === "EXACT_IN") { if ( diff --git a/packages/web/src/containers/token-swap-container/TokenSwapContainer.tsx b/packages/web/src/containers/token-swap-container/TokenSwapContainer.tsx index 925b3a5a7..ea8fb6327 100644 --- a/packages/web/src/containers/token-swap-container/TokenSwapContainer.tsx +++ b/packages/web/src/containers/token-swap-container/TokenSwapContainer.tsx @@ -80,7 +80,7 @@ const TokenSwapContainer: React.FC = () => { switchNetwork, } = useWallet(); - const { swap, estimateSwapRoute, estimatedRoutes, tokenAmountLimit } = useSwap({ + const { swap, estimateSwapRoute, swapState, estimatedRoutes, tokenAmountLimit } = useSwap({ tokenA, tokenB, direction: type, @@ -381,6 +381,9 @@ const TokenSwapContainer: React.FC = () => { ) { return "Amount Too Low"; } + if (swapState === "NO_LIQUIDITY") { + return "Insufficient Liquidity"; + } if (type === "EXACT_IN") { if ( diff --git a/packages/web/src/hooks/swap/use-swap.tsx b/packages/web/src/hooks/swap/use-swap.tsx index 40beaeeeb..a6625a700 100644 --- a/packages/web/src/hooks/swap/use-swap.tsx +++ b/packages/web/src/hooks/swap/use-swap.tsx @@ -23,6 +23,7 @@ export const useSwap = ({ const { poolRepository, swapRouterRepository } = useGnoswapContext(); const [estimatedRoutes, setEstimatedRoutes] = useState([]); const [estimatedAmount, setEstimatedAmount] = useState(null); + const [swapState, setSwapState] = useState<"NONE" | "LOADING" | "NO_LIQUIDITY" | "SUCCESS">("NONE"); const { slippage } = useSlippage(); const selectedTokenPair = tokenA !== null && tokenB !== null; @@ -41,12 +42,16 @@ export const useSwap = ({ const estimateSwapRoute = async (amount: string) => { if (!selectedTokenPair) { + setSwapState("NONE"); return null; } if (Number.isNaN(amount)) { + setSwapState("NONE"); return null; } - const pools = await poolRepository.getRPCPools(); + + setSwapState("LOADING"); + const pools = await poolRepository.getRPCPools().catch(() => []); swapRouterRepository.updatePools(pools); return swapRouterRepository.estimateSwapRoute({ @@ -56,6 +61,11 @@ export const useSwap = ({ tokenAmount: Number(amount) }).then(response => { console.log("response", response); + if (response.amount === "0" || response.amount === "") { + setSwapState("NO_LIQUIDITY"); + } else { + setSwapState("SUCCESS"); + } setEstimatedRoutes(response.estimatedRoutes); setEstimatedAmount(response.amount); return response; @@ -63,6 +73,7 @@ export const useSwap = ({ console.error(e); setEstimatedRoutes([]); setEstimatedAmount(null); + setSwapState("NONE"); return null; }); }; @@ -117,6 +128,7 @@ export const useSwap = ({ return { tokenAmountLimit, estimatedRoutes, + swapState, swap, wrapToken, unwrapToken, diff --git a/packages/web/src/repositories/swap/swap-router-repository-impl.ts b/packages/web/src/repositories/swap/swap-router-repository-impl.ts index 05d546de8..bdb7bb64c 100644 --- a/packages/web/src/repositories/swap/swap-router-repository-impl.ts +++ b/packages/web/src/repositories/swap/swap-router-repository-impl.ts @@ -176,8 +176,8 @@ export class SwapRouterRepositoryImpl implements SwapRouterRepository { pkg_path: ROUTER_PACKAGE_PATH, func: "SwapRoute", args: [ - inputToken.path, - outputToken.path, + inputTokenPath, + outputTokenPath, `${tokenAmountRaw || 0}`, exactType, `${routesQuery}`,