Skip to content

Commit

Permalink
fix: decimals on withdraw tab (#581)
Browse files Browse the repository at this point in the history
+ disable ledger on inj for now
  • Loading branch information
nick134-bit authored Aug 6, 2024
1 parent c8f5e34 commit 6b8c2c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 14 additions & 10 deletions components/Pages/Trade/Liquidity/WithdrawForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,31 @@ 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',
defaultValues: {
token1: {
tokenSymbol: tokenSymbolA,
amount: 0,
decimals: getDecimals(tokenSymbolA, tokenList),
decimals: tokenADecimal,
},
token2: {
tokenSymbol: tokenSymbolB,
amount: 0,
decimals: getDecimals(tokenSymbolB, tokenList),
decimals: tokenBDecimal,
},
},
})
Expand All @@ -68,21 +72,21 @@ 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,
})

useEffect(() => {
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])
Expand Down
4 changes: 2 additions & 2 deletions hooks/useClients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit 6b8c2c9

Please sign in to comment.