feat: rename permit2 variables for clarity (#6728)

* feat: rename permit2 variables for clarity

* fix: types
This commit is contained in:
eddie 2023-06-14 11:13:54 -07:00 committed by GitHub
parent 79a72d6fe2
commit 3db9e1b9a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 19 deletions

@ -73,10 +73,10 @@ function useConfirmModalState({
// at the bottom of the modal, even after they complete steps 1 and 2. // at the bottom of the modal, even after they complete steps 1 and 2.
const prepareSwapFlow = useCallback(() => { const prepareSwapFlow = useCallback(() => {
const steps: PendingConfirmModalState[] = [] const steps: PendingConfirmModalState[] = []
if (allowance.state === AllowanceState.REQUIRED && allowance.needsPermit2Approval) { if (allowance.state === AllowanceState.REQUIRED && allowance.needsSetupApproval) {
steps.push(ConfirmModalState.APPROVING_TOKEN) 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.PERMITTING)
} }
steps.push(ConfirmModalState.PENDING_CONFIRMATION) steps.push(ConfirmModalState.PENDING_CONFIRMATION)
@ -92,7 +92,7 @@ function useConfirmModalState({
if (allowance.state === AllowanceState.REQUIRED) { if (allowance.state === AllowanceState.REQUIRED) {
// Starts the approval process, by triggering either the Token Approval or the Permit signature. // Starts the approval process, by triggering either the Token Approval or the Permit signature.
try { try {
if (allowance.needsPermit2Approval) { if (allowance.needsSetupApproval) {
setConfirmModalState(ConfirmModalState.APPROVING_TOKEN) setConfirmModalState(ConfirmModalState.APPROVING_TOKEN)
await allowance.approve() await allowance.approve()
sendAnalyticsEvent(InterfaceEventName.APPROVE_TOKEN_TXN_SUBMITTED, { sendAnalyticsEvent(InterfaceEventName.APPROVE_TOKEN_TXN_SUBMITTED, {
@ -112,7 +112,7 @@ function useConfirmModalState({
} }
console.error(e) console.error(e)
setApprovalError( setApprovalError(
allowance.needsPermit2Approval ? PendingModalError.TOKEN_APPROVAL_ERROR : PendingModalError.PERMIT_ERROR allowance.needsSetupApproval ? PendingModalError.TOKEN_APPROVAL_ERROR : PendingModalError.PERMIT_ERROR
) )
} }
} else { } else {
@ -122,14 +122,14 @@ function useConfirmModalState({
}, [allowance, chainId, maximumAmountIn?.currency.address, maximumAmountIn?.currency.symbol, onSwap, trace]) }, [allowance, chainId, maximumAmountIn?.currency.address, maximumAmountIn?.currency.symbol, onSwap, trace])
const previousPermitNeeded = usePrevious( const previousPermitNeeded = usePrevious(
allowance.state === AllowanceState.REQUIRED ? allowance.needsPermit2Approval : undefined allowance.state === AllowanceState.REQUIRED ? allowance.needsSetupApproval : undefined
) )
useEffect(() => { useEffect(() => {
if ( if (
allowance.state === AllowanceState.REQUIRED && allowance.state === AllowanceState.REQUIRED &&
allowance.needsSignature && allowance.needsPermitSignature &&
// If the token approval switched from missing to fulfilled, trigger the next step (permit2 signature). // If the token approval switched from missing to fulfilled, trigger the next step (permit2 signature).
!allowance.needsPermit2Approval && !allowance.needsSetupApproval &&
previousPermitNeeded previousPermitNeeded
) { ) {
startSwapFlow() startSwapFlow()

@ -30,8 +30,8 @@ interface AllowanceRequired {
approve: () => Promise<void> approve: () => Promise<void>
permit: () => Promise<void> permit: () => Promise<void>
revoke: () => Promise<void> revoke: () => Promise<void>
needsPermit2Approval: boolean needsSetupApproval: boolean
needsSignature: boolean needsPermitSignature: boolean
allowedAmount: CurrencyAmount<Token> allowedAmount: CurrencyAmount<Token>
} }
@ -137,8 +137,8 @@ export default function usePermit2Allowance(amount?: CurrencyAmount<Token>, spen
approve, approve,
permit: updatePermitAllowance, permit: updatePermitAllowance,
revoke, revoke,
needsPermit2Approval: !isApproved, needsSetupApproval: !isApproved,
needsSignature: shouldRequestSignature, needsPermitSignature: shouldRequestSignature,
allowedAmount: tokenAllowance, allowedAmount: tokenAllowance,
} }
} else if (!isApproved) { } else if (!isApproved) {
@ -152,8 +152,8 @@ export default function usePermit2Allowance(amount?: CurrencyAmount<Token>, spen
approve, approve,
permit: updatePermitAllowance, permit: updatePermitAllowance,
revoke, revoke,
needsPermit2Approval: true, needsSetupApproval: true,
needsSignature: shouldRequestSignature, needsPermitSignature: shouldRequestSignature,
allowedAmount: tokenAllowance, allowedAmount: tokenAllowance,
} }
} }

@ -348,8 +348,8 @@ describe('BagFooter.tsx', () => {
approve: () => Promise.resolve(), approve: () => Promise.resolve(),
permit: () => Promise.resolve(), permit: () => Promise.resolve(),
revoke: () => Promise.resolve(), revoke: () => Promise.resolve(),
needsPermit2Approval: false, needsSetupApproval: false,
needsSignature: false, needsPermitSignature: false,
isRevocationPending: false, isRevocationPending: false,
allowedAmount: CurrencyAmount.fromRawAmount(TEST_TOKEN_1, 0), allowedAmount: CurrencyAmount.fromRawAmount(TEST_TOKEN_1, 0),
}, },
@ -376,8 +376,8 @@ describe('BagFooter.tsx', () => {
approve: () => Promise.resolve(), approve: () => Promise.resolve(),
permit: () => Promise.resolve(), permit: () => Promise.resolve(),
revoke: () => Promise.resolve(), revoke: () => Promise.resolve(),
needsPermit2Approval: false, needsSetupApproval: false,
needsSignature: false, needsPermitSignature: false,
isRevocationPending: false, isRevocationPending: false,
allowedAmount: CurrencyAmount.fromRawAmount(TEST_TOKEN_1, 0), allowedAmount: CurrencyAmount.fromRawAmount(TEST_TOKEN_1, 0),
}, },
@ -404,8 +404,8 @@ describe('BagFooter.tsx', () => {
approve: () => Promise.resolve(), approve: () => Promise.resolve(),
permit: () => Promise.resolve(), permit: () => Promise.resolve(),
revoke: () => Promise.resolve(), revoke: () => Promise.resolve(),
needsPermit2Approval: false, needsSetupApproval: false,
needsSignature: false, needsPermitSignature: false,
isRevocationPending: false, isRevocationPending: false,
allowedAmount: CurrencyAmount.fromRawAmount(TEST_TOKEN_1, 0), allowedAmount: CurrencyAmount.fromRawAmount(TEST_TOKEN_1, 0),
}, },