From 3389d01213ec8f7138d655bccdacd9c478361f15 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 18 Jan 2023 16:04:28 -0800 Subject: [PATCH] fix: fetch allowances without debouncing (#5853) --- src/pages/Swap/index.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pages/Swap/index.tsx b/src/pages/Swap/index.tsx index 7deec78400..d96a1b62ed 100644 --- a/src/pages/Swap/index.tsx +++ b/src/pages/Swap/index.tsx @@ -303,7 +303,12 @@ export default function Swap({ className }: { className?: string }) { return maximumAmountIn?.currency.isToken ? (maximumAmountIn as CurrencyAmount) : undefined }, [allowedSlippage, trade]) const allowance = usePermit2Allowance( - permit2Enabled ? maximumAmountIn : undefined, + permit2Enabled + ? maximumAmountIn ?? + (parsedAmounts[Field.INPUT]?.currency.isToken + ? (parsedAmounts[Field.INPUT] as CurrencyAmount) + : undefined) + : undefined, permit2Enabled && chainId ? UNIVERSAL_ROUTER_ADDRESS(chainId) : undefined ) const isApprovalLoading = allowance.state === AllowanceState.REQUIRED && allowance.isApprovalLoading @@ -847,7 +852,11 @@ export default function Swap({ className }: { className?: string }) { priceImpactTooHigh || (permit2Enabled ? allowance.state !== AllowanceState.ALLOWED : Boolean(swapCallbackError)) } - error={isValid && priceImpactSeverity > 2 && (permit2Enabled || !swapCallbackError)} + error={ + isValid && + priceImpactSeverity > 2 && + (permit2Enabled ? allowance.state === AllowanceState.ALLOWED : !swapCallbackError) + } > {swapInputError ? (