Skip to content

Conversation

@cryptotavares
Copy link
Contributor

@cryptotavares cryptotavares commented Nov 5, 2025

Note

Adds a configurable ETH→USDC swap comparison UI that builds/sends Universal Router calldata, enables only on mainnet, and is integrated into the transactions section.

  • Transactions UI:
    • Add swapComparisonComponent to compare an ETH→USDC swap with configurable fee (amount, fee %, recipient), status, and tx hash display.
    • Disabled unless connected on mainnet; reacts to newChainIdInt, globalConnectionChange, and disableAndClear events.
  • Swap Logic:
    • Build Universal Router execute calldata using V4 actions (SWAP_EXACT_IN_SINGLE, SETTLE_ALL, TAKE_PORTION, TAKE_ALL) with ethers encoding and input validation.
    • Send transaction via eth_sendTransaction to UNIVERSAL_ROUTER with user-specified ETH value.
  • Integration:
    • Export from components/transactions/index.js and render in src/index.js transactions row.
    • Emit newChainIdInt in handleNewChain to drive component enablement.

Written by Cursor Bugbot for commit 138ec5f. This will update automatically on new commits. Configure here.

feeBips,
ethAmountDisplay: ethAmountInput || DEFAULT_ETH_AMOUNT,
feePercentageDisplay:
feePercentageInput || DEFAULT_FEE_PERCENTAGE.toString(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: UI shows invalid input; uses defaults for tx

The display values (ethAmountDisplay and feePercentageDisplay) can show invalid user input even though the actual transaction will use default values. When a user enters invalid input (e.g., "abc" for ETH amount or "200" for fee percentage), the display will show the invalid input, but getConfigValues() will use the default values for the actual transaction due to parseEthAmount()/parseFeePercentage() returning null for invalid input. This creates a mismatch between what the UI displays and what transaction will actually be sent.

Fix in Cursor Fix in Web

ethers.utils.parseEther(DEFAULT_ETH_AMOUNT).toHexString();

const feeBips =
parseFeePercentage(feePercentageInput) || DEFAULT_FEE_PERCENTAGE * 100;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Zero-fee input misinterpreted as fifty percent

When a user enters 0 for the fee percentage, parseFeePercentage returns 0, which is falsy in JavaScript. The || operator then incorrectly falls back to DEFAULT_FEE_PERCENTAGE * 100 (5000 basis points), causing a 0% fee input to be treated as 50%. This prevents users from setting a zero fee for testing.

Fix in Cursor Fix in Web

OGPoyraz
OGPoyraz previously approved these changes Nov 7, 2025
vinistevam
vinistevam previously approved these changes Nov 7, 2025
seaona
seaona previously approved these changes Nov 7, 2025
Copy link
Member

@seaona seaona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! Just added a small comment but non blocking

<div class="card full-width">
<div class="card-body">
<h4 class="card-title">
Swap Comparison (High Fee Test - Mainnet only)
Copy link
Member

@seaona seaona Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is intended to work on mainnet only, maybe we could simply display the component depending on which network we have selected, using globalContext.chainIdInt?

As at the moment, nothing prevents me to trigger the button if I'm on a different network, leading to unexpected results

image

@cryptotavares cryptotavares dismissed stale reviews from seaona, vinistevam, and OGPoyraz via 138ec5f November 7, 2025 11:53

document.addEventListener('newChainIdInt', function (e) {
swapButton.disabled = e.detail.chainIdInt !== 1;
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Enable Swap Without User Connection Checks

The newChainIdInt event handler enables the swap button when chainIdInt === 1 without checking if the user is connected. This allows the button to be enabled when on mainnet but not connected, potentially causing transaction failures when clicked.

Fix in Cursor Fix in Web

Copy link
Member

@seaona seaona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice addition 🙌

test-dapp-swap.mov

@cryptotavares cryptotavares merged commit 6d01c47 into main Nov 7, 2025
9 checks passed
@cryptotavares cryptotavares deleted the cryptotavares/add-swap-comparison-button branch November 7, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants