Skip to content

Conversation

@MananTank
Copy link
Member

@MananTank MananTank commented Dec 17, 2025


PR-Codex overview

This PR focuses on enhancing the SwapWidget and related components by improving the handling of chain selections and adding new properties for better functionality and user experience.

Detailed summary

  • Adjusted timeout duration in onModalUnmount function.
  • Updated useBridgeChains to useBridgeChain for better chain data retrieval.
  • Added type and selections properties in several components for improved token selection.
  • Enhanced chain fetching logic to support both buy and sell operations.
  • Improved UI responsiveness by adjusting padding and mobile view settings.

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

Summary by CodeRabbit

  • New Features

    • Bridge filtering now supports a testnet option and mutually exclusive origin/destination filters.
    • Token selection now accepts operation context (buy/sell) and selected-chain hints.
  • Improvements

    • Filter-driven chain lists yield more relevant token choices.
    • Loading skeletons adapt sizing for mobile and desktop.
    • Deferred buy-token assignment reduces redundant fetches during modal close.
    • Slightly longer modal unmount delay for smoother transitions.

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

@vercel
Copy link

vercel bot commented Dec 17, 2025

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

Project Deployment Review Updated (UTC)
docs-v2 Ready Ready Preview, Comment Dec 19, 2025 10:57pm
nebula Ready Ready Preview, Comment Dec 19, 2025 10:57pm
thirdweb_playground Ready Ready Preview, Comment Dec 19, 2025 10:57pm
thirdweb-www Ready Ready Preview, Comment Dec 19, 2025 10:57pm
wallet-ui Ready Ready Preview, Comment Dec 19, 2025 10:57pm

@linear
Copy link

linear bot commented Dec 17, 2025

@changeset-bot
Copy link

changeset-bot bot commented Dec 17, 2025

🦋 Changeset detected

Latest commit: 9c04b3f

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 17, 2025

Walkthrough

Adds query-parameter filtering and testnet option to bridge chains API; introduces option-driven hooks (useBridgeChains, useBridgeChain, useBridgeChainsWithFilters); and threads new filter props (type, selections) through bridge token/chain selection components and stories.

Changes

Cohort / File(s) Summary
Bridge API & types
packages/thirdweb/src/bridge/Chains.ts
Add testnet?: boolean and a discriminated union for filters (type
Core hooks
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts
Change useBridgeChains to accept options: chains.Options; add useBridgeChain({ chainId, client }) for single-chain lookup; add useBridgeChainsWithFilters to map { client, buyChainId, sellChainId, type } into chains.Options.
Swap UI / token flow
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx, packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx
Replace list-based chain lookup with useBridgeChain for single-chain resolution; extend TokenSection signature with selection (buy/sell chain ids); pass type and selections into SelectToken modals; delay buy-token assignment via onModalUnmount in one flow.
Select token UI (desktop + mobile)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx
Thread `type: "buy"
Select chain UI & skeletons
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.tsx
Use useBridgeChainsWithFilters with new type/selections props; update SelectBuyTokenProps to include type and selections; change ChainButtonSkeleton signature to accept { isMobile: boolean } and adapt icon/text skeleton sizing and padding.
SwapWidget hook call shape
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx
Change useBridgeChains(props.client)useBridgeChains({ client: props.client }).
Modal timing tweak
packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts
Increase onModalUnmount delay from modalCloseFadeOutDuration + 100+ 200 ms.
Stories
packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx
Add type="buy" and selections={{ buyChainId: undefined, sellChainId: undefined }} to SelectBridgeChain story usages.
Changeset
.changeset/dry-wasps-love.md
Add changeset describing patch release and improved chain listing behavior in token selection UI.

Sequence Diagram(s)

sequenceDiagram
  participant User as User
  participant UI as Swap / SelectToken UI
  participant SelectChain as SelectBridgeChain Component
  participant Hook as useBridgeChainsWithFilters / useBridgeChain
  participant API as chains() Endpoint

  User->>UI: Open chain/token selector (provides type & selections)
  UI->>SelectChain: Render with props (type, selections)
  SelectChain->>Hook: Request chains (map type/selections → chains.Options)
  activate Hook
  Hook->>API: GET /chains?{testnet?, filter params based on type/origin/destination, originChainId?, destinationChainId?}
  activate API
  API-->>Hook: Return filtered chains
  deactivate API
  Hook-->>SelectChain: Deliver data + isPending
  deactivate Hook
  SelectChain->>UI: Render chain list or skeletons
  UI->>User: Display chains and accept selection
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay special attention to:
    • packages/thirdweb/src/bridge/Chains.ts — query param mapping, discriminated-union handling, and cache key JSON serialization.
    • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts — React Query keys, correct options mapping, and correctness of the new helper hooks.
    • Components updated to accept/forward type and selections (select-token-ui.tsx, select-chain.tsx, swap-ui.tsx, FundWallet.tsx) — ensure prop types and render paths align.
    • Skeleton/layout sizing changes in select-chain.tsx.
    • Modal unmount timing change in ConnectWallet/constants.ts and its effect on delayed state updates.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is mostly empty except for the auto-generated PR-Codex overview. It lacks the required sections from the template: Notes for the reviewer and How to test. Add 'Notes for the reviewer' section highlighting important implementation details and 'How to test' section with specific testing instructions (e.g., unit tests, playground scenarios).
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Out of Scope Changes check ❓ Inconclusive Minor out-of-scope change detected: the onModalUnmount timeout duration adjustment in constants.ts (100ms increase) is tangential to the main filtering objective and lacks clear justification in the PR description. Clarify in the PR description why the onModalUnmount timeout was increased and confirm it's necessary for the chain selection filtering feature to work correctly.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title '[MNY-338] Add filters when fetching chains in chain selection ui' directly reflects the main change: implementing filter support for chain fetching in the selection UI.
Linked Issues check ✅ Passed The PR successfully implements the linked issue requirements: extends chains endpoint to accept filter parameters (testnet, originChainId, destinationChainId), implements filtering logic via useBridgeChainsWithFilters, and uses 'type' and 'selections' props for buy/sell context throughout components.
✨ 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-338

📜 Recent review details

Configuration used: Organization 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 34f10d2 and 9c04b3f.

📒 Files selected for processing (10)
  • .changeset/dry-wasps-love.md (1 hunks)
  • packages/thirdweb/src/bridge/Chains.ts (3 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx (3 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx (1 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.tsx (4 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx (7 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx (9 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts (2 hunks)
  • packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts (1 hunks)
  • packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx
  • packages/thirdweb/src/bridge/Chains.ts
  • packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts
  • .changeset/dry-wasps-love.md
🧰 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/SwapWidget.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.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/SwapWidget.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.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/SwapWidget.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.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/SwapWidget.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.tsx
🧬 Code graph analysis (2)
packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx (1)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts (1)
  • useBridgeChain (33-45)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx (3)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx (1)
  • SelectToken (65-146)
packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts (1)
  • onModalUnmount (22-24)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts (1)
  • useBridgeChain (33-45)
⏰ 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, vite)
  • GitHub Check: Unit Tests
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Size
  • GitHub Check: Lint Packages
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (10)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx (1)

369-369: LGTM! Clean API update for preloading hook.

The change from positional to object parameter aligns with the refactored hook signature. Since this is a preload call (result unused), the migration is complete and correct.

packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx (2)

214-229: Verify chainId property access consistency.

Line 217 accesses props.selectedToken?.chainId, while line 420 (TokenSection) accesses props.selectedToken?.data?.chainId. These appear to reference different object shapes:

  • Line 217: props.selectedToken is of type SelectedToken | undefined (defined at line 118-123)
  • Line 240: The selectedToken passed to TokenSection wraps the query result in a data property

This is correct, but the naming collision (selectedToken used for both the selection state and the query result wrapper) could cause confusion during maintenance.

Consider verifying that this distinction is clear to future maintainers, possibly through inline comments or more distinct naming.


419-423: Efficient single-chain lookup refactor.

The change from useBridgeChains (fetch all, then filter) to useBridgeChain (fetch one by ID) is a more efficient pattern for resolving a single chain by chainId.

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

38-43: Well-structured filtered chain fetching.

The refactored hook invocation passes type and selection context (buyChainId, sellChainId) to enable server-side filtering of available chains, aligning with the PR objectives to support buy/sell flows with origin/destination filters.


161-180: Improved mobile responsiveness for skeletons.

The ChainButtonSkeleton now accepts isMobile and conditionally adjusts icon size, text height, and padding. This ensures skeleton loading states match the final rendered size across devices.

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

303-310: Smart optimization: defer state update until modal unmounts.

The onModalUnmount wrapper prevents the buyToken state update from triggering a chain query refetch while the modal is closing. This avoids wasted network requests and potential UI flicker during the fade-out animation.

The comment clearly explains the rationale, making this a well-documented optimization.


230-272: Note asymmetry in buy vs. sell token modal auto-selection logic.

  • Buy modal (lines 260-269): immediately sets the sell token to the native token of the selected chain.
  • Sell modal (lines 297-311): defers setting the buy token via onModalUnmount.

This asymmetry is intentional and explained by the comment on lines 303-304: deferring the buy-token update avoids triggering a chain query that would be immediately discarded during the modal close animation.

While the logic is sound, consider whether the buy modal could benefit from the same optimization for consistency and to avoid potential edge cases if the modal behavior changes in the future.

Also applies to: 274-320


721-725: Efficient single-chain resolution in TokenSection.

Replacing useBridgeChains (fetch all) with useBridgeChain (fetch one by ID) is more efficient when only a single chain needs to be resolved. The hook internally uses useBridgeChains and filters, so this is primarily a convenience and readability improvement.

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

66-71: Filtered chain query enables origin/destination context.

The hook now accepts type and selection context (buyChainId, sellChainId) to fetch only chains relevant to the current buy/sell flow. This aligns with the PR objective to filter chains based on origin/destination parameters.


489-499: Improved loading state semantics with Container component.

Replacing the div with a Container that uses flex="column", center="both", and expand better aligns with the design system and ensures consistent layout behavior. The minHeight: "300px" is preserved to maintain the expected loading state size.

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.

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

MananTank commented Dec 17, 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.

@codecov
Copy link

codecov bot commented Dec 17, 2025

Codecov Report

❌ Patch coverage is 8.88889% with 82 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.19%. Comparing base (800503d) to head (9c04b3f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...act/web/ui/Bridge/swap-widget/use-bridge-chains.ts 11.11% 24 Missing ⚠️
...c/react/web/ui/Bridge/swap-widget/select-chain.tsx 5.55% 17 Missing ⚠️
packages/thirdweb/src/bridge/Chains.ts 5.88% 16 Missing ⚠️
...eact/web/ui/Bridge/swap-widget/select-token-ui.tsx 6.25% 15 Missing ⚠️
...es/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx 9.09% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8573      +/-   ##
==========================================
- Coverage   53.24%   53.19%   -0.05%     
==========================================
  Files         922      922              
  Lines       61414    61480      +66     
  Branches     4026     4032       +6     
==========================================
+ Hits        32699    32706       +7     
- Misses      28617    28676      +59     
  Partials       98       98              
Flag Coverage Δ
packages 53.19% <8.88%> (-0.05%) ⬇️
Files with missing lines Coverage Δ
...irdweb/src/react/web/ui/ConnectWallet/constants.ts 100.00% <100.00%> (ø)
...es/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx 6.25% <9.09%> (-0.08%) ⬇️
...eact/web/ui/Bridge/swap-widget/select-token-ui.tsx 4.79% <6.25%> (-0.09%) ⬇️
packages/thirdweb/src/bridge/Chains.ts 44.44% <5.88%> (-24.53%) ⬇️
...c/react/web/ui/Bridge/swap-widget/select-chain.tsx 8.38% <5.55%> (-0.60%) ⬇️
...act/web/ui/Bridge/swap-widget/use-bridge-chains.ts 10.41% <11.11%> (-2.09%) ⬇️

... and 2 files with indirect coverage changes

🚀 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.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 17, 2025

size-limit report 📦

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

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 (3)
packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts (1)

23-23: Verify the timing adjustment resolves the coordination issue.

The increased delay from 100ms to 200ms adds an extra 100ms to the modal unmount sequence (total 450ms). While this likely addresses a race condition in the swap widget modal interactions, ensure that:

  • The extra delay resolves the intended timing issue.
  • The added latency doesn't negatively impact perceived UX during rapid modal transitions.

Consider adding a brief comment explaining why 200ms is needed (e.g., to allow for cleanup after modal fade-out in swap flows), as this would improve maintainability per the SDK coding guidelines.

packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx (1)

19-109: Consider adding stories to demonstrate filter variations.

All four stories use identical filter props: type="buy" with both buyChainId and sellChainId set to undefined. Consider adding additional story variants to showcase:

  • type="sell" filtering
  • Scenarios where buyChainId or sellChainId are defined
  • How the filter state affects the displayed chains

This would provide better documentation of the filtering feature and help catch edge cases.

Example additional story:

export function WithSellTypeAndSelectedBuyChain() {
  const [selectedChain, setSelectedChain] = useState<BridgeChain | undefined>(
    undefined,
  );
  return (
    <SwapWidgetContainer theme="dark" className="w-full">
      <SelectBridgeChain
        type="sell"
        selections={{
          buyChainId: 1, // Ethereum mainnet selected
          sellChainId: undefined,
        }}
        isMobile={false}
        client={storyClient}
        onSelectChain={setSelectedChain}
        onBack={() => {}}
        selectedChain={selectedChain}
      />
    </SwapWidgetContainer>
  );
}
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.tsx (1)

136-140: Add keys to skeleton components.

The skeleton components are rendered without keys, which React will warn about. While the biome-ignore comment suppresses the linter, React's reconciliation can still be inefficient without keys.

Apply this diff to add keys:

        {props.isPending &&
-         new Array(20).fill(0).map(() => (
-           // biome-ignore lint/correctness/useJsxKeyInIterable: ok
+         new Array(20).fill(0).map((_, i) => (
-           <ChainButtonSkeleton isMobile={props.isMobile} />
+           <ChainButtonSkeleton key={i} isMobile={props.isMobile} />
          ))}
📜 Review details

Configuration used: Organization 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 2d5b05e and ffd5bb0.

📒 Files selected for processing (10)
  • .changeset/dry-wasps-love.md (1 hunks)
  • packages/thirdweb/src/bridge/Chains.ts (3 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx (3 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx (1 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.tsx (4 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx (7 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx (9 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts (2 hunks)
  • packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts (1 hunks)
  • packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx (4 hunks)
✅ Files skipped from review due to trivial changes (2)
  • .changeset/dry-wasps-love.md
  • packages/thirdweb/src/bridge/Chains.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{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/select-chain.tsx
  • packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts
  • packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.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/select-chain.tsx
  • packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts
  • packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.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/select-chain.tsx
  • packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts
  • packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.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/select-chain.tsx
  • packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts
  • packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx
**/*.stories.tsx

📄 CodeRabbit inference engine (CLAUDE.md)

Add Storybook stories (*.stories.tsx) alongside new UI components for documentation

Files:

  • packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx
**/*.stories.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

For new UI components, add Storybook stories (*.stories.tsx) alongside the code

Files:

  • packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx
🧬 Code graph analysis (2)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts (2)
packages/thirdweb/src/bridge/Chains.ts (1)
  • chains (55-100)
packages/thirdweb/src/exports/thirdweb.ts (1)
  • ThirdwebClient (25-25)
packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx (1)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts (1)
  • useBridgeChain (33-45)
⏰ 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: Build Packages
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Unit Tests
  • GitHub Check: Lint Packages
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Size
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx (1)

213-228: Verify the selection state logic for buy flow.

The SelectToken modal is invoked with type="buy" and selections.buyChainId set to the currently selected token's chain. However, when opening a token selection modal of type "buy", the user is selecting a destination (buy) chain, so the already-selected destination chain shouldn't constrain the available options.

Based on the useBridgeChainsWithFilters logic:

  • type="buy" with sellChainId=undefined maps to { type: "destination" }, showing all destination chains ✓
  • The buyChainId value is ignored in this case

While the current implementation is functionally correct, the state model might be clearer if selections were structured differently or if there were a comment explaining why buyChainId is passed but not used for filtering in the buy flow.

Consider adding a comment to clarify the selection state:

        <SelectToken
          type="buy"
          selections={{
+           // buyChainId tracks the selected destination but doesn't filter chains in buy flow
            buyChainId: props.selectedToken?.chainId,
            sellChainId: undefined,
          }}

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx (1)

274-320: Fix typo and address fragile modal timing workaround.

Line 303 contains a typo: "unnecessay" should be "unnecessary".

The delayed buyToken assignment (lines 305-310) relies on onModalUnmount, which uses a hardcoded timeout of 450ms rather than actually detecting modal unmount. This approach is fragile and will break if:

  • The modal animation duration (modalCloseFadeOutDuration) changes
  • User interactions occur during the delay window
  • Multiple token selections happen in rapid succession

Consider tracking modal unmount state explicitly (e.g., via a ref or state flag) or using a proper animation end callback instead of relying on a magic timeout.

🧹 Nitpick comments (2)
.changeset/dry-wasps-love.md (1)

5-5: Minor grammar improvement.

The phrasing could be slightly more polished. Consider: "A more reliable list of chains shown in the token selection UI in SwapWidget based on origin and destination chain selections" or "Improved reliability of the chains list shown in the token selection UI in SwapWidget based on origin and destination chain selections."

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts (1)

33-45: Consider optimizing useBridgeChain to conditionally fetch.

The hook always fetches all chains even when chainId is undefined, which is wasteful. While the result is cached (mitigating repeated fetches), the initial load could be optimized.

🔎 Proposed optimization
 export function useBridgeChain({
   chainId,
   client,
 }: {
   chainId: number | undefined;
   client: ThirdwebClient;
 }) {
-  const chainQuery = useBridgeChains({ client });
+  const chainQuery = useBridgeChains({ 
+    client,
+    enabled: chainId !== undefined 
+  });
   return {
     data: chainQuery.data?.find((chain) => chain.chainId === chainId),
     isPending: chainQuery.isPending,
   };
 }

Note: This assumes useBridgeChains supports an enabled option. If not, you could wrap it in a conditional or update useQuery directly with an enabled flag.

📜 Review details

Configuration used: Organization 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 ffd5bb0 and 34f10d2.

📒 Files selected for processing (10)
  • .changeset/dry-wasps-love.md (1 hunks)
  • packages/thirdweb/src/bridge/Chains.ts (3 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx (3 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx (1 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.tsx (4 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx (7 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx (9 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts (2 hunks)
  • packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts (1 hunks)
  • packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx
  • packages/thirdweb/src/bridge/Chains.ts
  • packages/thirdweb/src/stories/Bridge/Swap/SelectChain.stories.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx
  • packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts
  • packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx
🧰 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/use-bridge-chains.ts
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.tsx
  • 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/use-bridge-chains.ts
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.tsx
  • 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/use-bridge-chains.ts
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.tsx
  • 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/use-bridge-chains.ts
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.tsx
  • 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/use-bridge-chains.ts (2)
packages/thirdweb/src/bridge/Chains.ts (1)
  • chains (55-100)
packages/thirdweb/src/exports/thirdweb.ts (1)
  • ThirdwebClient (25-25)
⏰ 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: Unit Tests
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Size
  • GitHub Check: Lint Packages
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-bridge-chains.ts (2)

5-31: LGTM! Hook refactored to accept filter options.

The signature change from client parameter to options object properly supports the new filtering capabilities. The queryKey correctly includes the full options object to ensure proper cache separation for different filter combinations.


47-80: LGTM! Filter mapping logic correctly implements the API contract.

The conditional logic properly maps buy/sell types to origin/destination filters:

  • Buy mode with sellChainId → originChainId (destinations reachable from origin)
  • Buy mode without selection → type="destination" (all possible destinations)
  • Sell mode with buyChainId → destinationChainId (origins that can reach destination)
  • Sell mode without selection → type="origin" (all possible origins)

This matches the API behavior documented in the comments and the relevant code snippets.

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

18-53: LGTM! Chain selection properly integrated with filtering.

The component correctly:

  • Switched to useBridgeChainsWithFilters for filtered chain fetching
  • Accepts and threads through type and selections props
  • Passes buy/sell chain IDs to enable origin/destination filtering

The hook integration aligns with the new filtering architecture introduced across the Bridge UI components.


139-180: LGTM! Skeleton made responsive based on mobile state.

The ChainButtonSkeleton now correctly adapts icon size, text height, and padding based on the isMobile prop, ensuring consistent responsive behavior with the actual chain buttons.

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

230-272: LGTM! Buy token modal correctly passes filter props.

The buy token modal now receives:

  • type="buy" to fetch destination chains
  • selections with current buy/sell chain IDs to enable filtered fetching

This enables the chain selection UI to show only relevant chains based on the current sell chain selection.


689-925: LGTM! TokenSection refactored to use single-chain fetching.

The component now:

  • Accepts selection prop with buy/sell chain IDs for filter coordination
  • Uses useBridgeChain to fetch chain data for the selected token
  • Properly handles undefined chain scenarios

Note: As mentioned in the review of use-bridge-chains.ts, useBridgeChain fetches all chains even when chainId is undefined, which could be optimized. However, caching mitigates the performance impact.

@graphite-app
Copy link
Contributor

graphite-app bot commented Dec 19, 2025

Merge activity

<!--

## 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 enhances the `SwapWidget` and related components by improving the chain selection logic and UI responsiveness, introducing a more reliable token selection process, and adjusting the timeout for modal unmounting.

### Detailed summary
- Updated `setTimeout` duration in `onModalUnmount` to 200ms.
- Changed `useBridgeChains` to `useBridgeChain` for better chain fetching.
- Added `type` and `selections` props to various components for handling buy/sell logic.
- Implemented a new `useBridgeChainsWithFilters` function for filtered chain queries.
- Enhanced UI components to accommodate new selection logic.
- Improved loading states and mobile responsiveness in `SelectBridgeChain` and `SelectToken`.

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

<!-- end pr-codex -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  - Bridge filtering now supports testnet and mutually exclusive origin/destination filters.
  - Token selection accepts operation context (buy/sell) and selected-chain hints.

* **Improvements**
  - Filter-driven chain lists yield more relevant token choices.
  - Loading skeletons adapt sizing for mobile and desktop.
  - Deferred buy-token assignment reduces redundant fetches during modal close.
  - Slightly longer modal unmount delay for smoother transitions.

<sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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