diff --git a/cypress/e2e/permit2.test.ts b/cypress/e2e/permit2.test.ts index 9ad65c2f9f..d960ce9fd0 100644 --- a/cypress/e2e/permit2.test.ts +++ b/cypress/e2e/permit2.test.ts @@ -146,6 +146,26 @@ describe('Permit2', () => { cy.contains('Swap success!') cy.get(getTestSelector('popups')).contains('Swapped') }) + + it('swaps USDT with existing permit, and existing and sufficient token approval', () => { + cy.hardhat().then(async (hardhat) => { + await hardhat.fund(hardhat.wallet, CurrencyAmount.fromRawAmount(USDT, 2e6)) + await hardhat.mine() + await hardhat.approval.setTokenAllowanceForPermit2({ owner: hardhat.wallet, token: USDT }, 1e6) + await hardhat.mine() + await hardhat.approval.setPermit2Allowance({ owner: hardhat.wallet, token: USDT }) + await hardhat.mine() + }) + setupInputs(USDT, USDC_MAINNET) + cy.get('#swap-currency-input .token-amount-input').clear().type('1') + initiateSwap() + + // Verify transaction + cy.wait('@eth_sendRawTransaction') + cy.hardhat().then((hardhat) => hardhat.mine()) + cy.contains('Swap success!') + cy.get(getTestSelector('popups')).contains('Swapped') + }) }) it('swaps when user has already approved token and permit2', () => { diff --git a/src/components/swap/ConfirmSwapModal.tsx b/src/components/swap/ConfirmSwapModal.tsx index bc62f52f77..a5b204a9b7 100644 --- a/src/components/swap/ConfirmSwapModal.tsx +++ b/src/components/swap/ConfirmSwapModal.tsx @@ -97,6 +97,7 @@ function useConfirmModalState({ // See the `approve` function here: https://etherscan.io/address/0xdAC17F958D2ee523a2206206994597C13D831ec7#code if ( allowance.state === AllowanceState.REQUIRED && + allowance.needsSetupApproval && allowance.token.equals(USDT_MAINNET) && allowance.allowedAmount.greaterThan(0) ) {