Skip to content

Conversation

@MananTank
Copy link
Member

@MananTank MananTank commented Dec 12, 2025


PR-Codex overview

This PR focuses on improving the token selection user experience in the SwapWidget by automatically setting the sell or buy token to the native token of the respective chain when no token is selected.

Detailed summary

  • Added logic to set sellToken to the native token of the buy token's chain if not selected.
  • Added logic to set buyToken to the native token of the sell token's chain if not selected.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features
    • Enhanced SwapWidget Token Selection: When you select a buy token without a sell token already chosen, the widget now automatically sets the sell token to the native token of that chain. The same applies when selecting a sell token first.

✏️ Tip: You can customize this high-level summary in your review settings.

@linear
Copy link

linear bot commented Dec 12, 2025

@vercel
Copy link

vercel bot commented Dec 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs-v2 Ready Ready Preview Comment Dec 12, 2025 7:00pm
nebula Ready Ready Preview Comment Dec 12, 2025 7:00pm
thirdweb_playground Ready Ready Preview Comment Dec 12, 2025 7:00pm
thirdweb-www Ready Ready Preview Comment Dec 12, 2025 7:00pm
wallet-ui Ready Ready Preview Comment Dec 12, 2025 7:00pm

@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2025

🦋 Changeset detected

Latest commit: 5ec84bd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
thirdweb Patch
@thirdweb-dev/nebula Patch
@thirdweb-dev/wagmi-adapter Patch
wagmi-inapp Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 12, 2025

Walkthrough

Adds automatic token selection logic to SwapWidget: when a user selects a buy or sell token without an existing counterpart token, the complementary token is automatically set to the native token of the selected token's chain.

Changes

Cohort / File(s) Summary
Changeset metadata
\.changeset/eager-loops-obey.md
New changeset file documenting patch release with Token Selection UX improvements for SwapWidget.
Token auto-fill logic
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx
Added NATIVE_TOKEN_ADDRESS and getAddress imports. Implemented auto-fill behavior: selecting a buy token without a sell token automatically sets the sell token to the native token of the buy token's chain; selecting a sell token without a buy token automatically sets the buy token to the native token of the sell token's chain. Logic executes within existing onSelectedToken handlers for both buy and sell token modals.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify native token detection and auto-fill logic correctly handles edge cases (e.g., when either token is already native, chain validity)
  • Confirm getAddress utility behaves as expected with NATIVE_TOKEN_ADDRESS
  • Check that auto-fill logic doesn't interfere with existing duplicate token selection handling

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The description includes a PR-Codex summary explaining the UX improvements but lacks the required template structure with Notes for the reviewer and How to test sections. Complete the description by filling in the Notes for the reviewer and How to test sections from the template to provide clarity on testing approach.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly references the linked issue (MNY-314) and clearly summarizes the main change: Token Selection UX improvements in SwapWidget.
Linked Issues check ✅ Passed The code changes implement the core objective: automatically pre-selecting the native token of a chain when the other token is not selected, reducing the need for additional chain searches.
Out of Scope Changes check ✅ Passed All changes are scoped to the SwapWidget token selection UX improvement. The changeset, imports, and auto-fill logic are directly aligned with the linked issue MNY-314.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mny-314

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

Comment @coderabbitai help to get the list of available commands and usage tips.

@MananTank MananTank marked this pull request as ready for review December 12, 2025 17:43
@MananTank MananTank requested review from a team as code owners December 12, 2025 17:43
@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Dec 12, 2025
Copy link
Member Author

MananTank commented Dec 12, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 12, 2025

size-limit report 📦

Path Size
@thirdweb-dev/nexus (esm) 105.66 KB (0%)
@thirdweb-dev/nexus (cjs) 319.47 KB (0%)

@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.63%. Comparing base (38f4a89) to head (5ec84bd).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8552   +/-   ##
=======================================
  Coverage   54.63%   54.63%           
=======================================
  Files         921      921           
  Lines       61193    61193           
  Branches     4150     4152    +2     
=======================================
  Hits        33434    33434           
  Misses      27657    27657           
  Partials      102      102           
Flag Coverage Δ
packages 54.63% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@graphite-app graphite-app bot changed the base branch from mny-331 to graphite-base/8552 December 12, 2025 18:35
@graphite-app
Copy link
Contributor

graphite-app bot commented Dec 12, 2025

Merge activity

@graphite-app graphite-app bot changed the base branch from graphite-base/8552 to main December 12, 2025 18:47
<!--

## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes"

If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000):

## Notes for the reviewer

Anything important to call out? Be sure to also clarify these in your comments.

## How to test

Unit tests, playground, etc.

-->

<!-- start pr-codex -->

---

## PR-Codex overview
This PR focuses on improving the user experience in the `SwapWidget` by automatically selecting the native token when no sell or buy token is selected.

### Detailed summary
- Added logic to set the `sellToken` as the native token of the buy token's chain if no sell token is selected.
- Added logic to set the `buyToken` as the native token of the sell token's chain if no buy token is selected.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx (1)

287-298: LGTM!

The sell-token auto-selection correctly mirrors the buy-token logic, maintaining consistency and symmetry in the user experience.

Optional: Consider extracting the auto-selection logic.

The token auto-selection logic is duplicated between lines 252-260 and 289-297. While the duplication is minimal and the current implementation is clear, you could optionally extract it into a helper function if similar patterns emerge elsewhere in the codebase:

function autoSelectComplementaryToken(params: {
  selectedToken: TokenSelection;
  complementaryToken: TokenSelection | undefined;
  setComplementaryToken: (token: TokenSelection | undefined) => void;
}) {
  if (
    !params.complementaryToken &&
    params.selectedToken.tokenAddress.toLowerCase() !==
      NATIVE_TOKEN_ADDRESS.toLowerCase()
  ) {
    params.setComplementaryToken({
      tokenAddress: getAddress(NATIVE_TOKEN_ADDRESS),
      chainId: params.selectedToken.chainId,
    });
  }
}

Then call it in both handlers:

// In buy token selection:
autoSelectComplementaryToken({
  selectedToken: token,
  complementaryToken: props.sellToken,
  setComplementaryToken: props.setSellToken,
});

// In sell token selection:
autoSelectComplementaryToken({
  selectedToken: token,
  complementaryToken: props.buyToken,
  setComplementaryToken: props.setBuyToken,
});

This is purely a maintainability consideration and not required for the current scope.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 38f4a89 and 5ec84bd.

📒 Files selected for processing (2)
  • .changeset/eager-loops-obey.md (1 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each TypeScript file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes in TypeScript
Avoid any and unknown in TypeScript unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.) in TypeScript

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity and testability
Re-use shared types from @/types or local types.ts barrel exports
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics whenever possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic in TypeScript files; avoid restating TypeScript types and signatures in prose

Files:

  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx
packages/thirdweb/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

packages/thirdweb/src/**/*.{ts,tsx}: Comment only ambiguous logic in SDK code; avoid restating TypeScript in prose
Load heavy dependencies inside async paths to keep initial bundle lean (e.g. const { jsPDF } = await import("jspdf");)

Lazy-load heavy dependencies inside async paths to keep the initial bundle lean (e.g., const { jsPDF } = await import('jspdf');)

Files:

  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx
**/*.{js,jsx,ts,tsx,json}

📄 CodeRabbit inference engine (AGENTS.md)

Biome governs formatting and linting; its rules live in biome.json. Run pnpm fix & pnpm lint before committing, ensure there are no linting errors

Files:

  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Lazy-import optional features; avoid top-level side-effects

Files:

  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx
🧬 Code graph analysis (1)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx (2)
apps/playground-web/src/app/x402/components/constants.ts (1)
  • token (4-9)
packages/thirdweb/src/exports/thirdweb.ts (1)
  • NATIVE_TOKEN_ADDRESS (31-31)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Build Packages
  • GitHub Check: Lint Packages
  • GitHub Check: Unit Tests
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
.changeset/eager-loops-obey.md (1)

1-5: LGTM!

The changeset follows the correct format and accurately describes the UX improvement.

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx (2)

9-9: LGTM!

The imports are appropriate for the token auto-selection feature. NATIVE_TOKEN_ADDRESS enables native token detection, and getAddress ensures address normalization.

Also applies to: 12-12


250-261: LGTM!

The auto-selection logic correctly handles the UX improvement:

  • Only fills when sell token is unselected
  • Skips auto-fill if the buy token is native (avoiding confusing native-to-native swaps on the same chain)
  • Sets sell token to the native token of the buy token's chain, reducing user clicks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages SDK Involves changes to the thirdweb SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants