fix: fetch allowances without debouncing (#5853)

This commit is contained in:
Zach Pomerantz 2023-01-18 16:04:28 -08:00 committed by GitHub
parent d9a0aa3ff0
commit 3389d01213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -303,7 +303,12 @@ export default function Swap({ className }: { className?: string }) {
return maximumAmountIn?.currency.isToken ? (maximumAmountIn as CurrencyAmount<Token>) : undefined
}, [allowedSlippage, trade])
const allowance = usePermit2Allowance(
permit2Enabled ? maximumAmountIn : undefined,
permit2Enabled
? maximumAmountIn ??
(parsedAmounts[Field.INPUT]?.currency.isToken
? (parsedAmounts[Field.INPUT] as CurrencyAmount<Token>)
: 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)
}
>
<Text fontSize={20} fontWeight={600}>
{swapInputError ? (