diff --git a/packages/web/src/containers/swap-container/SwapContainer.tsx b/packages/web/src/containers/swap-container/SwapContainer.tsx index a08cfc5cb..9bcf64eb2 100644 --- a/packages/web/src/containers/swap-container/SwapContainer.tsx +++ b/packages/web/src/containers/swap-container/SwapContainer.tsx @@ -410,7 +410,7 @@ const SwapContainer: React.FC = () => { }); }, 2000); return () => clearTimeout(timeout); - }, [type, tokenA, tokenAAmount, tokenB, tokenBAmount]); + }, [type, tokenA, tokenAAmount, tokenB, tokenBAmount, estimateSwapRoute, checkBalance]); useEffect(() => { const queryValues = []; diff --git a/packages/web/src/hooks/swap/use-swap.tsx b/packages/web/src/hooks/swap/use-swap.tsx index 6def72a6b..84f7fe7d7 100644 --- a/packages/web/src/hooks/swap/use-swap.tsx +++ b/packages/web/src/hooks/swap/use-swap.tsx @@ -47,6 +47,7 @@ export const useSwap = ({ return null; } const pools = await poolRepository.getRPCPools(); + console.log("pools", pools); swapRouterRepository.updatePools(pools); return swapRouterRepository.estimateSwapRoute({ @@ -59,7 +60,9 @@ export const useSwap = ({ setEstimatedRoutes(response.estimatedRoutes); setEstimatedAmount(response.amount); return response; - }).catch(() => { + }).catch(e => { + + console.log(e); setEstimatedRoutes([]); setEstimatedAmount(null); return null; diff --git a/packages/web/src/hooks/token/use-token-data.tsx b/packages/web/src/hooks/token/use-token-data.tsx index bd5c27d89..6738869d6 100644 --- a/packages/web/src/hooks/token/use-token-data.tsx +++ b/packages/web/src/hooks/token/use-token-data.tsx @@ -61,7 +61,7 @@ export const useTokenData = () => { }, [tokenPrices, tokens]); const getTokenUSDPrice = useCallback((tokenAId: string, amount: bigint | string | number) => { - const tokenUSDPrice = tokenPrices[tokenAId].usd; + const tokenUSDPrice = tokenPrices[tokenAId]?.usd || "0"; if (!tokenUSDPrice || Number.isNaN(amount)) { return null; } @@ -69,8 +69,8 @@ export const useTokenData = () => { }, [tokenPrices]); const getTokenPriceRate = useCallback((tokenAId: string, tokenBId: string) => { - const tokenAUSDPrice = tokenPrices[tokenAId].usd; - const tokenBUSDPrice = tokenPrices[tokenBId].usd; + const tokenAUSDPrice = tokenPrices[tokenAId]?.usd; + const tokenBUSDPrice = tokenPrices[tokenBId]?.usd; if (!tokenAUSDPrice || !tokenBUSDPrice) { return null; } diff --git a/packages/web/src/providers/gnoswap-service-provider/GnoswapServiceProvider.tsx b/packages/web/src/providers/gnoswap-service-provider/GnoswapServiceProvider.tsx index 53bd09050..e91fbb17e 100644 --- a/packages/web/src/providers/gnoswap-service-provider/GnoswapServiceProvider.tsx +++ b/packages/web/src/providers/gnoswap-service-provider/GnoswapServiceProvider.tsx @@ -11,7 +11,7 @@ import { TokenRepositoryImpl } from "@repositories/token/token-repository-impl"; import { createContext, useEffect, useMemo, useState } from "react"; import { useAtom } from "jotai"; import { CommonState, WalletState } from "@states/index"; -import { GnoProvider, GnoWSProvider } from "@gnolang/gno-js-client"; +import { GnoJSONRPCProvider, GnoProvider } from "@gnolang/gno-js-client"; import { SwapRepositoryImpl } from "@repositories/swap/swap-repository-impl"; import ChainNetworkInfos from "@resources/chains.json"; import { SwapRouterRepository } from "@repositories/swap/swap-router-repository"; @@ -58,8 +58,8 @@ const GnoswapServiceProvider: React.FC = ({ const defaultChainId = process.env.NEXT_PUBLIC_DEFAULT_CHAIN_ID || ""; const currentNetwork = network || ChainNetworkInfos.find(info => info.chainId === defaultChainId); if (currentNetwork) { - const provider = new GnoWSProvider(currentNetwork.wsUrl, 5 * 1000); - provider.waitForOpenConnection().then(() => setRPCProvider(provider)); + const provider = new GnoJSONRPCProvider(currentNetwork.rpcUrl); + setRPCProvider(provider); } }, [network]);