Skip to content

Commit

Permalink
fix: allow quote value change
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveVodrazka committed Sep 18, 2024
1 parent 789c672 commit ac8d09a
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/components/ImpermanentLoss/ImpermanentLossWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const ImpermanentLossWidget = () => {
const [loading, setLoading] = useState<boolean>(false);
const [amount, setAmount] = useState<number>(1);
const [amountText, setAmountText] = useState<string>("1");
const [quoteAmount, setQuoteAmount] = useState<number>(1);
const [quoteAmountText, setQuoteAmountText] = useState<string>("1");
const [price, setPrice] = useState<ILPrice | undefined>();
const [txStatus, setTxStatus] = useState<TransactionState>(
TransactionState.Initial
Expand Down Expand Up @@ -109,6 +111,24 @@ export const ImpermanentLossWidget = () => {
const handleInputChange = handleNumericChangeFactory(
setAmountText,
setAmount,
(n) => {
if (baseTokenPrice && quoteTokenPrice) {
const newQuoteText = formatNumber(
(n * baseTokenPrice) / quoteTokenPrice,
2
);
const newQuote = parseInt(newQuoteText);

setQuoteAmount(newQuote);
setQuoteAmountText(newQuoteText);
}
return n;
}
);

const handleQuoteInputChange = handleNumericChangeFactory(
setQuoteAmountText,
setQuoteAmount,
(n) => {
return n;
}
Expand Down Expand Up @@ -187,7 +207,7 @@ export const ImpermanentLossWidget = () => {
<input
onChange={handleInputChange}
type="text"
placeholder="base size"
placeholder="base"
value={amountText}
className="white-col"
/>
Expand All @@ -208,18 +228,15 @@ export const ImpermanentLossWidget = () => {
<div className={styles.tokeninput}>
<div>
<input
onChange={handleQuoteInputChange}
type="text"
placeholder="quote size"
value={
amount && baseTokenPrice && quoteTokenPrice
? formatNumber((amount * baseTokenPrice) / quoteTokenPrice)
: ""
}
disabled
placeholder="quote"
value={quoteAmountText}
className="white-col"
/>
<p className="p4 secondary-col">
{baseTokenPrice ? (
"$" + formatNumber(amount * baseTokenPrice)
{quoteTokenPrice && quoteAmount ? (
"$" + formatNumber(quoteAmount * quoteTokenPrice)
) : (
<LoadingAnimation size={20} />
)}
Expand Down

0 comments on commit ac8d09a

Please sign in to comment.