diff --git a/projects/dex-ui/src/components/Liquidity/AddLiquidity.tsx b/projects/dex-ui/src/components/Liquidity/AddLiquidity.tsx index 13a0d4043b..8b66a16099 100644 --- a/projects/dex-ui/src/components/Liquidity/AddLiquidity.tsx +++ b/projects/dex-ui/src/components/Liquidity/AddLiquidity.tsx @@ -294,8 +294,8 @@ const AddLiquidityContent = ({ toast.error(error); setIsSubmitting(false); } - invalidate(queryKeys.tokenBalance(token1.symbol)); - invalidate(queryKeys.tokenBalance(token2.symbol)); + invalidate(queryKeys.tokenBalance(token1.address)); + invalidate(queryKeys.tokenBalance(token2.address)); invalidate(queryKeys.lpSummaryAll); } diff --git a/projects/dex-ui/src/components/Swap/TokenInput.tsx b/projects/dex-ui/src/components/Swap/TokenInput.tsx index 4f407c929c..aff4629526 100644 --- a/projects/dex-ui/src/components/Swap/TokenInput.tsx +++ b/projects/dex-ui/src/components/Swap/TokenInput.tsx @@ -87,9 +87,9 @@ export const TokenInput: FC = ({ }, []); const handleClickMax = useCallback(() => { - const val = balance?.[token.symbol].toHuman() ?? ""; + const val = balance?.[token.address]?.toHuman() ?? ""; handleAmountChange(val); - }, [balance, handleAmountChange, token.symbol]); + }, [balance, handleAmountChange, token.address]); if (loading) return ; @@ -110,7 +110,7 @@ export const TokenInput: FC = ({ inputRef={inputRef} allowNegative={allowNegative} canChangeValue={!!canChangeValue} - max={clamp ? balance?.[token.symbol] : undefined} + max={clamp ? balance?.[token.address] : undefined} /> = ({ {balanceLabel}:{" "} - {isBalanceLoading ? : balance?.[token.symbol].toHuman("short")} + {isBalanceLoading ? : balance?.[token.address]?.toHuman("short")} )} diff --git a/projects/dex-ui/src/tokens/useLPPositionSummary.tsx b/projects/dex-ui/src/tokens/useLPPositionSummary.tsx index 535b0dd2af..660866f1cc 100644 --- a/projects/dex-ui/src/tokens/useLPPositionSummary.tsx +++ b/projects/dex-ui/src/tokens/useLPPositionSummary.tsx @@ -103,7 +103,7 @@ export const useLPPositionSummary = () => { const lpTokenIndex = Math.floor(i / CALLS_PER_TOKEN); const lpToken = lpTokens[lpTokenIndex]; - let balance = balances?.[lpToken.symbol] || { + let balance = balances?.[lpToken.address] || { external: TokenValue.ZERO, internal: TokenValue.ZERO }; @@ -113,30 +113,31 @@ export const useLPPositionSummary = () => { if (lpTokens[lpTokenIndex]) { balance.external = lpTokens[lpTokenIndex].fromBlockchain(res[i]) || TokenValue.ZERO; } - setQueryData(queryKeys.tokenBalance(lpToken.symbol), (oldData: TokenBalanceCache) => { - if (!oldData) return { [lpToken.symbol]: balance.external }; - return { ...oldData, [lpToken.symbol]: balance.external }; + setQueryData(queryKeys.tokenBalance(lpToken.address), (oldData: TokenBalanceCache) => { + if (!oldData) return { [lpToken.address]: balance.external }; + return { ...oldData, [lpToken.address]: balance.external }; }) setQueryData(queryKeys.tokenBalancesAll, (oldData: TokenBalanceCache) => { - if (!oldData) return { [lpToken.symbol]: balance.external }; - return { ...oldData, [lpToken.symbol]: balance.external }; + if (!oldData) return { [lpToken.address]: balance.external }; + return { ...oldData, [lpToken.address]: balance.external }; }) } else { if (lpTokens[lpTokenIndex]) { balance.internal = lpTokens[lpTokenIndex].fromBlockchain(res[i]); - setQueryData(queryKeys.tokenBalanceInternal(lpToken.symbol), (oldData: TokenBalanceCache) => { - if (!oldData) return { [lpToken.symbol]: balance.internal }; - return { ...oldData, [lpToken.symbol]: balance.internal }; + setQueryData(queryKeys.tokenBalanceInternal(lpToken.address), (oldData: TokenBalanceCache) => { + if (!oldData) return { [lpToken.address]: balance.internal }; + return { ...oldData, [lpToken.address]: balance.internal }; }) } } - balances[lpToken.symbol] = balance; + balances[lpToken.address] = balance; } return balances; }, + enabled: !!address && !!lpTokens.length, /** * Token balances are cached for 30 seconds, refetch value every 30 seconds, @@ -152,21 +153,18 @@ export const useLPPositionSummary = () => { // Combine silo, internal & external balances & update state useEffect(() => { - console.log("balanceData: ", balanceData); + // console.log("balanceData: ", balanceData); + // console.log("lpTokens: ", lpTokens); if (!lpTokens.length || !balanceData || !siloBalances) return; - console.log("siloBalances: ", siloBalances); - - // console.log("lptokens: ", lpTokens); - const map = lpTokens.reduce>((memo, curr) => { - const siloBalance = siloBalances[curr.symbol] || TokenValue.ZERO; - const internalExternal = balanceData?.[curr.symbol] || { + const siloBalance = siloBalances[curr.address] || TokenValue.ZERO; + const internalExternal = balanceData?.[curr.address] || { external: TokenValue.ZERO, internal: TokenValue.ZERO }; - memo[curr.symbol] = { + memo[curr.address] = { silo: siloBalance, internal: internalExternal.internal, external: internalExternal.external, @@ -191,8 +189,8 @@ export const useLPPositionSummary = () => { */ const getPositionWithWell = useCallback( (well: Well | undefined) => { - if (!well?.lpToken?.symbol) return undefined; - return positions?.[well.lpToken.symbol]; + if (!well?.lpToken?.address) return undefined; + return positions?.[well.lpToken.address]; }, [positions] );