From 631b727ef35212f83ae75cef678addf256249eba Mon Sep 17 00:00:00 2001 From: nick134 <76399455+nick134-bit@users.noreply.github.com> Date: Tue, 6 Aug 2024 16:18:32 +0200 Subject: [PATCH] fix: decimals on withdraw tab + disable ledger on inj for now --- .../Pages/Trade/Liquidity/WithdrawForm.tsx | 24 +++++++++++-------- hooks/useClients.ts | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/components/Pages/Trade/Liquidity/WithdrawForm.tsx b/components/Pages/Trade/Liquidity/WithdrawForm.tsx index 9d49f076..c2cb954e 100644 --- a/components/Pages/Trade/Liquidity/WithdrawForm.tsx +++ b/components/Pages/Trade/Liquidity/WithdrawForm.tsx @@ -36,14 +36,18 @@ const WithdrawForm = ({ poolId, isWalletConnected, clearForm, mobile, openView } const [tokenSymbolA, tokenSymbolB] = poolId?.split('-') || [] const lpBalance = liquidity?.available?.provided?.tokenAmount || 0 const [tokenList] = useTokenList() - const { tokenABalance, tokenBBalance } = useMemo(() => { + const { tokenABalance, tokenBBalance, tokenADecimal,tokenBDecimal } = useMemo(() => { const [reserveA, reserveB] = liquidity?.reserves?.myNotLocked || [] + const tokenADecimal = getDecimals(tokenSymbolA, tokenList) + const tokenBDecimal = getDecimals(tokenSymbolB, tokenList) return { - tokenABalance: fromChainAmount(reserveA, getDecimals(tokenSymbolA, tokenList)), - tokenBBalance: fromChainAmount(reserveB, getDecimals(tokenSymbolB, tokenList)), + tokenABalance: fromChainAmount(reserveA, tokenADecimal), + tokenBBalance: fromChainAmount(reserveB, tokenBDecimal), + tokenADecimal, + tokenBDecimal, } - }, [liquidity]) + }, [liquidity, tokenList?.tokens]) const { control, handleSubmit, setValue, watch } = useForm({ mode: 'onChange', @@ -51,12 +55,12 @@ const WithdrawForm = ({ poolId, isWalletConnected, clearForm, mobile, openView } token1: { tokenSymbol: tokenSymbolA, amount: 0, - decimals: getDecimals(tokenSymbolA, tokenList), + decimals: tokenADecimal, }, token2: { tokenSymbol: tokenSymbolB, amount: 0, - decimals: getDecimals(tokenSymbolB, tokenList), + decimals: tokenBDecimal, }, }, }) @@ -68,8 +72,8 @@ const WithdrawForm = ({ poolId, isWalletConnected, clearForm, mobile, openView } tokenA: liquidity?.reserves?.myNotLocked?.[0], tokenB: liquidity?.reserves?.myNotLocked?.[1], amount: reverse - ? toChainAmount(tokenB.amount, getDecimals(tokenSymbolB, tokenList)) - : toChainAmount(tokenA.amount, getDecimals(tokenSymbolA, tokenList)), + ? toChainAmount(tokenB.amount, tokenBDecimal) + : toChainAmount(tokenA.amount, tokenADecimal), reverse, }) @@ -77,12 +81,12 @@ const WithdrawForm = ({ poolId, isWalletConnected, clearForm, mobile, openView } if (reverse) { setValue('token1', { ...tokenA, - amount: num(fromChainAmount(simulated, tokenA.decimals)).toNumber(), + amount: num(fromChainAmount(simulated, tokenADecimal)).toNumber(), }) } else { setValue('token2', { ...tokenB, - amount: num(fromChainAmount(simulated, tokenB.decimals)).toNumber(), + amount: num(fromChainAmount(simulated, tokenBDecimal)).toNumber(), }) } }, [simulated]) diff --git a/hooks/useClients.ts b/hooks/useClients.ts index 14963cf4..445c0378 100644 --- a/hooks/useClients.ts +++ b/hooks/useClients.ts @@ -18,7 +18,7 @@ export const useClients = (walletChainName: string) => { isWalletConnected, setDefaultSignOptions, getStargateClient, - wallet, getRpcEndpoint, getOfflineSigner } = useChain(walletChainName) + wallet, getRpcEndpoint, getOfflineSignerDirect } = useChain(walletChainName) if (isWalletConnected && !wallet?.name.includes('station')) { try { @@ -44,7 +44,7 @@ export const useClients = (walletChainName: string) => { queryKey: ['injectiveSigningClient'], queryFn: async () => { try { - const offlineSigner: any = await getOfflineSigner() + const offlineSigner: any = await getOfflineSignerDirect() const protoRegistry: ReadonlyArray<[string, GeneratedType]> = [ ...cosmosProtoRegistry, ...cosmwasmProtoRegistry,