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

WIP:: Max button fix #1659

Draft
wants to merge 2 commits into
base: fix/remove-market-price-bug
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,22 @@ export function LimitOrderForm({ account, provider, chainId }: LimitOrderFormPro
handleCurrencyAmountChange({ currency, amountWei, amountFormatted })
}

const handleOnMax = (amount: CurrencyAmount | undefined, hanldeCurrencyAmountChange: Function) => () => {
if (!amount) return
hanldeCurrencyAmountChange({
currency: amount?.currency as Token,
amountWei: amount?.raw.toString(),
amountFormatted: amount.toSignificant(6),
})
}
const handleOnMax =
(amount: CurrencyAmount | undefined, hanldeCurrencyAmountChange: Function, isSell = false) =>
() => {
if (!amount) return
let amountWithoutFee = amount
if (isSell && limitOrder.feeAmount !== '0' && amountWithoutFee.raw.toString() !== '0') {
const feeAmount = new TokenAmount(amount.currency as Token, limitOrder.feeAmount)
const tokenAMount = new TokenAmount(amount.currency as Token, amount.raw.toString())
amountWithoutFee = tokenAMount.subtract(feeAmount)
}
hanldeCurrencyAmountChange({
currency: amountWithoutFee?.currency as Token,
amountWei: amountWithoutFee?.raw.toString(),
amountFormatted: amountWithoutFee.toSignificant(6),
})
}

const [marketPrices, setMarketPrices] = useState<MarketPrices>({ buy: 0, sell: 0 })

Expand Down Expand Up @@ -495,7 +503,7 @@ export function LimitOrderForm({ account, provider, chainId }: LimitOrderFormPro
)}
value={formattedSellAmount}
onUserInput={handleInputOnChange(sellTokenAmount.currency as Token, handleSellCurrencyAmountChange)}
onMax={handleOnMax(sellCurrencyMaxAmount, handleSellCurrencyAmountChange)}
onMax={handleOnMax(sellCurrencyMaxAmount, handleSellCurrencyAmountChange, true)}
maxAmount={sellCurrencyMaxAmount}
fiatValue={fiatValueInput}
isFallbackFiatValue={isFallbackFiatValueInput}
Expand Down