From 2cdb07028225e4771bce4aa1b22c0ab9d77c7a74 Mon Sep 17 00:00:00 2001 From: Violet Date: Tue, 3 Jan 2023 19:07:44 +0100 Subject: [PATCH 1/2] fix: Included the fee into the max button --- .../LimitOrderForm/LimitOrderForm.tsx | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/pages/Swap/LimitOrderBox/components/LimitOrderForm/LimitOrderForm.tsx b/src/pages/Swap/LimitOrderBox/components/LimitOrderForm/LimitOrderForm.tsx index 1718d9c2b..e23385c7d 100644 --- a/src/pages/Swap/LimitOrderBox/components/LimitOrderForm/LimitOrderForm.tsx +++ b/src/pages/Swap/LimitOrderBox/components/LimitOrderForm/LimitOrderForm.tsx @@ -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) { + 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({ buy: 0, sell: 0 }) @@ -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} From 7b0ac3b99d66ded5a69fb5ec905129f381c9f690 Mon Sep 17 00:00:00 2001 From: Violet Date: Tue, 3 Jan 2023 19:13:06 +0100 Subject: [PATCH 2/2] fix: Division by zero error --- .../LimitOrderBox/components/LimitOrderForm/LimitOrderForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Swap/LimitOrderBox/components/LimitOrderForm/LimitOrderForm.tsx b/src/pages/Swap/LimitOrderBox/components/LimitOrderForm/LimitOrderForm.tsx index e23385c7d..2e02203cc 100644 --- a/src/pages/Swap/LimitOrderBox/components/LimitOrderForm/LimitOrderForm.tsx +++ b/src/pages/Swap/LimitOrderBox/components/LimitOrderForm/LimitOrderForm.tsx @@ -397,7 +397,7 @@ export function LimitOrderForm({ account, provider, chainId }: LimitOrderFormPro () => { if (!amount) return let amountWithoutFee = amount - if (isSell && limitOrder.feeAmount) { + 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)