Skip to content

Commit

Permalink
fix CL amount input
Browse files Browse the repository at this point in the history
  • Loading branch information
jonator committed Jun 6, 2024
1 parent 340c24a commit 47a4ee7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
30 changes: 28 additions & 2 deletions packages/trpc/src/balances.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { queryBalances } from "@osmosis-labs/server";
import { CoinPretty } from "@keplr-wallet/unit";
import {
getAsset,
getShareDenomPoolId,
makeGammShareCurrency,
queryBalances,
} from "@osmosis-labs/server";
import z from "zod";

import { createTRPCRouter, publicProcedure } from "./api";
Expand All @@ -12,6 +18,26 @@ export const balancesRouter = createTRPCRouter({
queryBalances({
...input,
...ctx,
})
}).then((res) =>
res.balances.map(({ denom, amount }) =>
denom.startsWith("gamm")
? {
denom,
amount,
coin: new CoinPretty(
makeGammShareCurrency(getShareDenomPoolId(denom)),
amount
),
}
: {
denom,
amount,
coin: new CoinPretty(
getAsset({ ...ctx, anyDenom: denom }),
amount
),
}
)
)
),
});
33 changes: 14 additions & 19 deletions packages/web/components/cl-deposit-input-group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { CoinPretty, Dec, DecUtils, RatePretty } from "@keplr-wallet/unit";
import classNames from "classnames";
import { observer } from "mobx-react-lite";
import Image from "next/image";
import React, { FunctionComponent, useCallback, useMemo } from "react";
import React, { FunctionComponent, useMemo } from "react";

import { InputBox } from "~/components/input";
import { useTranslation } from "~/hooks";
import { useCoinFiatValue } from "~/hooks/queries/assets/use-coin-fiat-value";
import { useStore } from "~/stores";
import { api } from "~/utils/trpc";

export const DepositAmountGroup: FunctionComponent<{
currency?: Currency;
onUpdate: (amount: number) => void;
onUpdate: (amount: string) => void;
onMax: () => void;
currentValue: string;
percentage: RatePretty;
Expand All @@ -32,10 +33,9 @@ export const DepositAmountGroup: FunctionComponent<{
priceInputClass,
outOfRangeClassName,
}) => {
const { chainStore, queriesStore, accountStore } = useStore();
const { accountStore } = useStore();
const { t } = useTranslation();
const { chainId } = chainStore.osmosis;
const account = accountStore.getWallet(chainId);
const account = accountStore.getWallet(accountStore.osmosisChainId);
const address = account?.address ?? "";

const { fiatValue: currentValuePrice } = useCoinFiatValue(
Expand All @@ -53,19 +53,14 @@ export const DepositAmountGroup: FunctionComponent<{
)
);

const walletBalance = currency
? queriesStore
.get(chainId)
.queryBalances.getQueryBech32Address(address)
.getBalanceFromCurrency(currency)
: null;

const updateValue = useCallback(
(val: string) => {
const newVal = Number(val);
onUpdate(newVal);
},
[onUpdate]
const { data: walletBalance } = api.local.balances.getUserBalances.useQuery(
{ bech32Address: address },
{
enabled: !!account?.address,
select: (balances) =>
balances.find(({ denom }) => denom === currency?.coinMinimalDenom)
?.coin,
}
);

if (outOfRange) {
Expand Down Expand Up @@ -139,7 +134,7 @@ export const DepositAmountGroup: FunctionComponent<{
inputClassName="!leading-4"
type="number"
currentValue={currentValue}
onInput={updateValue}
onInput={onUpdate}
rightEntry
/>
<div className="caption pr-3 text-osmoverse-400">
Expand Down
4 changes: 2 additions & 2 deletions packages/web/components/complex/add-conc-liquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ const AddConcLiqView: FunctionComponent<
onUpdate={useCallback(
(amount) => {
setAnchorAsset("base");
baseDepositAmountIn.setAmount(amount.toString());
baseDepositAmountIn.setAmount(amount);
},
[baseDepositAmountIn, setAnchorAsset]
)}
Expand All @@ -601,7 +601,7 @@ const AddConcLiqView: FunctionComponent<
onUpdate={useCallback(
(amount) => {
setAnchorAsset("quote");
quoteDepositAmountIn.setAmount(amount.toString());
quoteDepositAmountIn.setAmount(amount);
},
[quoteDepositAmountIn, setAnchorAsset]
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/hooks/input/use-amount-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function useAmountInput({
},
{ enabled: Boolean(account?.address) }
);
const rawCurrencyBalance = balances?.balances.find(
const rawCurrencyBalance = balances?.find(
(bal) => bal.denom === currency?.coinMinimalDenom
)?.amount;
// manage amounts, with ability to set fraction of the amount
Expand Down
4 changes: 2 additions & 2 deletions packages/web/modals/increase-concentrated-liquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export const IncreaseConcentratedLiquidityModal: FunctionComponent<
onUpdate={useCallback(
(amount) => {
config.setAnchorAsset("base");
config.baseDepositAmountIn.setAmount(amount.toString());
config.baseDepositAmountIn.setAmount(amount);
},
[config]
)}
Expand All @@ -256,7 +256,7 @@ export const IncreaseConcentratedLiquidityModal: FunctionComponent<
onUpdate={useCallback(
(amount) => {
config.setAnchorAsset("quote");
config.quoteDepositAmountIn.setAmount(amount.toString());
config.quoteDepositAmountIn.setAmount(amount);
},
[config]
)}
Expand Down

0 comments on commit 47a4ee7

Please sign in to comment.