Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: decimals on withdraw tab #581

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading