feat: rename permit2 variables for clarity (#6728)
* feat: rename permit2 variables for clarity * fix: types
This commit is contained in:
parent
79a72d6fe2
commit
3db9e1b9a4
@ -73,10 +73,10 @@ function useConfirmModalState({
|
||||
// at the bottom of the modal, even after they complete steps 1 and 2.
|
||||
const prepareSwapFlow = useCallback(() => {
|
||||
const steps: PendingConfirmModalState[] = []
|
||||
if (allowance.state === AllowanceState.REQUIRED && allowance.needsPermit2Approval) {
|
||||
if (allowance.state === AllowanceState.REQUIRED && allowance.needsSetupApproval) {
|
||||
steps.push(ConfirmModalState.APPROVING_TOKEN)
|
||||
}
|
||||
if (allowance.state === AllowanceState.REQUIRED && allowance.needsSignature) {
|
||||
if (allowance.state === AllowanceState.REQUIRED && allowance.needsPermitSignature) {
|
||||
steps.push(ConfirmModalState.PERMITTING)
|
||||
}
|
||||
steps.push(ConfirmModalState.PENDING_CONFIRMATION)
|
||||
@ -92,7 +92,7 @@ function useConfirmModalState({
|
||||
if (allowance.state === AllowanceState.REQUIRED) {
|
||||
// Starts the approval process, by triggering either the Token Approval or the Permit signature.
|
||||
try {
|
||||
if (allowance.needsPermit2Approval) {
|
||||
if (allowance.needsSetupApproval) {
|
||||
setConfirmModalState(ConfirmModalState.APPROVING_TOKEN)
|
||||
await allowance.approve()
|
||||
sendAnalyticsEvent(InterfaceEventName.APPROVE_TOKEN_TXN_SUBMITTED, {
|
||||
@ -112,7 +112,7 @@ function useConfirmModalState({
|
||||
}
|
||||
console.error(e)
|
||||
setApprovalError(
|
||||
allowance.needsPermit2Approval ? PendingModalError.TOKEN_APPROVAL_ERROR : PendingModalError.PERMIT_ERROR
|
||||
allowance.needsSetupApproval ? PendingModalError.TOKEN_APPROVAL_ERROR : PendingModalError.PERMIT_ERROR
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@ -122,14 +122,14 @@ function useConfirmModalState({
|
||||
}, [allowance, chainId, maximumAmountIn?.currency.address, maximumAmountIn?.currency.symbol, onSwap, trace])
|
||||
|
||||
const previousPermitNeeded = usePrevious(
|
||||
allowance.state === AllowanceState.REQUIRED ? allowance.needsPermit2Approval : undefined
|
||||
allowance.state === AllowanceState.REQUIRED ? allowance.needsSetupApproval : undefined
|
||||
)
|
||||
useEffect(() => {
|
||||
if (
|
||||
allowance.state === AllowanceState.REQUIRED &&
|
||||
allowance.needsSignature &&
|
||||
allowance.needsPermitSignature &&
|
||||
// If the token approval switched from missing to fulfilled, trigger the next step (permit2 signature).
|
||||
!allowance.needsPermit2Approval &&
|
||||
!allowance.needsSetupApproval &&
|
||||
previousPermitNeeded
|
||||
) {
|
||||
startSwapFlow()
|
||||
|
@ -30,8 +30,8 @@ interface AllowanceRequired {
|
||||
approve: () => Promise<void>
|
||||
permit: () => Promise<void>
|
||||
revoke: () => Promise<void>
|
||||
needsPermit2Approval: boolean
|
||||
needsSignature: boolean
|
||||
needsSetupApproval: boolean
|
||||
needsPermitSignature: boolean
|
||||
allowedAmount: CurrencyAmount<Token>
|
||||
}
|
||||
|
||||
@ -137,8 +137,8 @@ export default function usePermit2Allowance(amount?: CurrencyAmount<Token>, spen
|
||||
approve,
|
||||
permit: updatePermitAllowance,
|
||||
revoke,
|
||||
needsPermit2Approval: !isApproved,
|
||||
needsSignature: shouldRequestSignature,
|
||||
needsSetupApproval: !isApproved,
|
||||
needsPermitSignature: shouldRequestSignature,
|
||||
allowedAmount: tokenAllowance,
|
||||
}
|
||||
} else if (!isApproved) {
|
||||
@ -152,8 +152,8 @@ export default function usePermit2Allowance(amount?: CurrencyAmount<Token>, spen
|
||||
approve,
|
||||
permit: updatePermitAllowance,
|
||||
revoke,
|
||||
needsPermit2Approval: true,
|
||||
needsSignature: shouldRequestSignature,
|
||||
needsSetupApproval: true,
|
||||
needsPermitSignature: shouldRequestSignature,
|
||||
allowedAmount: tokenAllowance,
|
||||
}
|
||||
}
|
||||
|
@ -348,8 +348,8 @@ describe('BagFooter.tsx', () => {
|
||||
approve: () => Promise.resolve(),
|
||||
permit: () => Promise.resolve(),
|
||||
revoke: () => Promise.resolve(),
|
||||
needsPermit2Approval: false,
|
||||
needsSignature: false,
|
||||
needsSetupApproval: false,
|
||||
needsPermitSignature: false,
|
||||
isRevocationPending: false,
|
||||
allowedAmount: CurrencyAmount.fromRawAmount(TEST_TOKEN_1, 0),
|
||||
},
|
||||
@ -376,8 +376,8 @@ describe('BagFooter.tsx', () => {
|
||||
approve: () => Promise.resolve(),
|
||||
permit: () => Promise.resolve(),
|
||||
revoke: () => Promise.resolve(),
|
||||
needsPermit2Approval: false,
|
||||
needsSignature: false,
|
||||
needsSetupApproval: false,
|
||||
needsPermitSignature: false,
|
||||
isRevocationPending: false,
|
||||
allowedAmount: CurrencyAmount.fromRawAmount(TEST_TOKEN_1, 0),
|
||||
},
|
||||
@ -404,8 +404,8 @@ describe('BagFooter.tsx', () => {
|
||||
approve: () => Promise.resolve(),
|
||||
permit: () => Promise.resolve(),
|
||||
revoke: () => Promise.resolve(),
|
||||
needsPermit2Approval: false,
|
||||
needsSignature: false,
|
||||
needsSetupApproval: false,
|
||||
needsPermitSignature: false,
|
||||
isRevocationPending: false,
|
||||
allowedAmount: CurrencyAmount.fromRawAmount(TEST_TOKEN_1, 0),
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user