Skip to content

Conversation

MananTank
Copy link
Member

@MananTank MananTank commented Sep 29, 2025


PR-Codex overview

This PR focuses on improving the token search functionality in the SwapWidget by implementing a debounced search mechanism, which enhances the user experience by reducing the frequency of search queries.

Detailed summary

  • Updated the token search logic in use-tokens.ts to use a query and tokenAddress based on search conditions.
  • Introduced a debouncedSearch variable in select-token-ui.tsx to minimize search input delays.
  • Modified the filtering of owned tokens to use debouncedSearch instead of search.

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

Summary by CodeRabbit

  • New Features
    • Improved token search in SwapWidget: debounced input for smoother typing, faster results, and more accurate matching by symbol, name, or address.
  • Bug Fixes
    • Reduced unnecessary queries and flicker during token search, improving responsiveness and stability.
  • Chores
    • Added a changeset entry for a patch release noting Token Search improvements in SwapWidget.

Copy link

linear bot commented Sep 29, 2025

Copy link

changeset-bot bot commented Sep 29, 2025

🦋 Changeset detected

Latest commit: 7495f46

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

This PR includes changesets to release 3 packages
Name Type
thirdweb Patch
@thirdweb-dev/nebula Patch
@thirdweb-dev/wagmi-adapter 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

Copy link

vercel bot commented Sep 29, 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 Sep 29, 2025 8:16pm
nebula Ready Ready Preview Comment Sep 29, 2025 8:16pm
thirdweb_playground Ready Ready Preview Comment Sep 29, 2025 8:16pm
thirdweb-www Ready Ready Preview Comment Sep 29, 2025 8:16pm
wallet-ui Ready Ready Preview Comment Sep 29, 2025 8:16pm

Copy link
Contributor

coderabbitai bot commented Sep 29, 2025

Walkthrough

Introduces debounced search in the token selection UI and updates token fetching to use a new "query" parameter for text searches while keeping "tokenAddress" for address inputs. Adds a changeset marking a patch release referencing "Token Search improvements in SwapWidget".

Changes

Cohort / File(s) Summary
SwapWidget search debounce
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx
Adds useDebouncedValue(…, 500); replaces direct search usage with debouncedSearch in queries, filtering, and dependency arrays.
Token fetching parameter update
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-tokens.ts
Replaces "name" with "query" for non-address searches; keeps "tokenAddress" when input is an address; adjusts branching to set only one of query/tokenAddress.
Release metadata
.changeset/beige-sites-jog.md
Adds patch changeset for "thirdweb" with summary: “Token Search improvements in SwapWidget”.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant UI as SelectToken UI
  participant H as useTokens Hook
  participant S as tokens()

  U->>UI: Type search input
  UI->>UI: Debounce input (500ms) [debouncedSearch]
  UI->>H: Request tokens with debouncedSearch
  alt Input is address
    H->>S: tokens({ tokenAddress })
  else Input is text
    H->>S: tokens({ query })
  end
  S-->>H: Token results
  H-->>UI: Provide tokens
  UI-->>U: Render filtered list (symbol/name/address)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The provided pull request description includes the repository’s template comments but does not fill in any of the required sections such as the title field, notes for the reviewer, or instructions on how to test, instead only providing a PR-Codex overview. Please populate the template’s sections by specifying the formatted PR title, adding reviewer notes, and detailing steps to test the changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title “[MNY-213] SDK/SwapWidget: token search improvements” clearly identifies the main change of enhancing token search behavior within the SwapWidget component and follows the required concise, single-sentence format without extraneous details.
Linked Issues Check ✅ Passed The changes directly address the linked issue MNY-213 by updating the search hook to use a debounced query parameter and refining UI filtering to match both token symbol and name (e.g., “usdc” now matches by symbol), thereby fulfilling the requested functionality.
Out of Scope Changes Check ✅ Passed All modifications are focused on the SwapWidget’s token search logic and related hooks or UI components; there are no alterations outside the scope of improving search behavior as defined by the linked issue.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mny-213

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 September 29, 2025 15:10
@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Sep 29, 2025
@MananTank MananTank requested review from a team as code owners September 29, 2025 15:10
Copy link
Member Author

MananTank commented Sep 29, 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.

Copy link
Contributor

github-actions bot commented Sep 29, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 64.69 KB (0%) 1.3 s (0%) 366 ms (+55.35% 🔺) 1.7 s
thirdweb (cjs) 361.52 KB (0%) 7.3 s (0%) 2.3 s (+0.18% 🔺) 9.6 s
thirdweb (minimal + tree-shaking) 5.73 KB (0%) 115 ms (0%) 107 ms (+933.34% 🔺) 222 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 36 ms (+445.63% 🔺) 46 ms
thirdweb/react (minimal + tree-shaking) 19.14 KB (0%) 383 ms (0%) 103 ms (+530.19% 🔺) 485 ms

Copy link

codecov bot commented Sep 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.28%. Comparing base (b8afa98) to head (7495f46).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8145   +/-   ##
=======================================
  Coverage   56.28%   56.28%           
=======================================
  Files         906      906           
  Lines       59208    59208           
  Branches     4177     4176    -1     
=======================================
  Hits        33324    33324           
  Misses      25779    25779           
  Partials      105      105           
Flag Coverage Δ
packages 56.28% <ø> (ø)
🚀 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.

Copy link
Contributor

graphite-app bot commented Sep 29, 2025

Merge activity

@graphite-app graphite-app bot changed the base branch from mny-212 to graphite-base/8145 September 29, 2025 19:00
@graphite-app graphite-app bot changed the base branch from graphite-base/8145 to main September 29, 2025 19:24
<!--

## 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 token search functionality in the `SwapWidget` by incorporating a debounce mechanism to optimize search input handling and refining the token filtering logic.

### Detailed summary
- Updated `use-tokens.ts` to use `query` and `tokenAddress` based on search conditions.
- Added `useDebouncedValue` hook in `select-token-ui.tsx` for debouncing the search input.
- Changed token filtering logic to utilize `debouncedSearch` instead of raw `search` value.

> ✨ 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 (8)
packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-tokens.ts (2)

24-26: Normalize/trim search before address detection and request params.

Trimming avoids false negatives for inputs with spaces and keeps requests clean.

Apply:

-      const isSearchAddress = options.search
-        ? isAddress(options.search)
-        : false;
+      const searchTerm = (options.search ?? "").trim();
+      const isSearchAddress = searchTerm ? isAddress(searchTerm) : false;
...
-        query: options.search && !isSearchAddress ? options.search : undefined,
-        tokenAddress:
-          options.search && isSearchAddress ? options.search : undefined,
+        query: searchTerm && !isSearchAddress ? searchTerm : undefined,
+        tokenAddress: searchTerm && isSearchAddress ? searchTerm : undefined,

Also applies to: 34-36


16-17: Stabilize react‑query key to reduce unnecessary cache misses.

Avoid passing the entire options object (identity changes often).

-    queryKey: ["tokens", options],
+    queryKey: [
+      "tokens",
+      options.chainId,
+      options.offset,
+      options.limit,
+      (options.search ?? "").trim().toLowerCase(),
+    ],

As per coding guidelines.

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

61-84: Normalize debounced input once and pass the trimmed value to queries.

Prevents sending/using trailing spaces and keeps filter logic consistent.

-  const debouncedSearch = useDebouncedValue(search, 500);
+  const debouncedSearch = useDebouncedValue(search, 500);
+  const normalizedSearch = debouncedSearch.trim();
...
-    search: debouncedSearch,
+    search: normalizedSearch,

95-106: Avoid repeated .toLowerCase(); handle empty query fast.

Micro-opt and clearer intent.

-  const filteredOwnedTokens = useMemo(() => {
-    return ownedTokensQuery.data?.tokens?.filter((token) => {
-      return (
-        token.symbol.toLowerCase().includes(debouncedSearch.toLowerCase()) ||
-        token.name.toLowerCase().includes(debouncedSearch.toLowerCase()) ||
-        token.token_address
-          .toLowerCase()
-          .includes(debouncedSearch.toLowerCase())
-      );
-    });
-  }, [ownedTokensQuery.data?.tokens, debouncedSearch]);
+  const filteredOwnedTokens = useMemo(() => {
+    const q = normalizedSearch.toLowerCase();
+    if (!q) return ownedTokensQuery.data?.tokens;
+    return ownedTokensQuery.data?.tokens?.filter((token) => {
+      return (
+        token.symbol.toLowerCase().includes(q) ||
+        token.name.toLowerCase().includes(q) ||
+        token.token_address.toLowerCase().includes(q)
+      );
+    });
+  }, [ownedTokensQuery.data?.tokens, normalizedSearch]);

152-163: Don’t mutate props when sorting.

Array.prototype.sort mutates; clone first to avoid side‑effects.

-  const sortedOwnedTokens = useMemo(() => {
-    return props.ownedTokens.sort((a, b) => {
+  const sortedOwnedTokens = useMemo(() => {
+    return [...props.ownedTokens].sort((a, b) => {
       if (a.icon_uri && !b.icon_uri) {
         return -1;
       }
       if (!a.icon_uri && b.icon_uri) {
         return 1;
       }
       return 0;
     });
   }, [props.ownedTokens]);

177-187: Prefer non‑mutating sort for derived arrays too.

Keeps a consistent immutable style.

-  const sortedOtherTokens = useMemo(() => {
-    return otherTokens.sort((a, b) => {
+  const sortedOtherTokens = useMemo(() => {
+    return [...otherTokens].sort((a, b) => {
       if (a.iconUri && !b.iconUri) {
         return -1;
       }
       if (!a.iconUri && b.iconUri) {
         return 1;
       }
       return 0;
     });
   }, [otherTokens]);

496-499: UX copy: include “symbol” in placeholder.

Matches the new behavior and header text.

-              placeholder="Search by token or address"
+              placeholder="Search by token, symbol, or address"

58-60: Add explicit return type to exported component.

Keeps TS surfaces explicit.

-export function SelectToken(props: SelectTokenUIProps) {
+export function SelectToken(props: SelectTokenUIProps): JSX.Element | null {

As per coding guidelines.

📜 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 b8afa98 and 7495f46.

📒 Files selected for processing (3)
  • .changeset/beige-sites-jog.md (1 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx (4 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-tokens.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
.changeset/*.md

📄 CodeRabbit inference engine (AGENTS.md)

.changeset/*.md: Each change in packages/* must include a changeset for the appropriate package
Version bump rules: patch for non‑API changes; minor for new/modified public API

Files:

  • .changeset/beige-sites-jog.md
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each 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
Avoid any and unknown unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose

**/*.{ts,tsx}: Use explicit function declarations and explicit return types in TypeScript
Limit each file to one stateless, single‑responsibility function
Re‑use shared types from @/types where applicable
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Prefer composition over inheritance; use utility types (Partial, Pick, etc.)
Lazy‑import optional features and avoid top‑level side‑effects to reduce bundle size

Files:

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

📄 CodeRabbit inference engine (CLAUDE.md)

Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

Files:

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

📄 CodeRabbit inference engine (AGENTS.md)

packages/thirdweb/**/*.{ts,tsx}: Every public symbol must have comprehensive TSDoc with at least one compiling @example and a custom tag (@beta, @internal, @experimental, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
Lazy‑load heavy dependencies inside async paths (e.g., const { jsPDF } = await import("jspdf"))

Files:

  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-tokens.ts
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx
🧠 Learnings (2)
📚 Learning: 2025-09-24T11:08:43.783Z
Learnt from: MananTank
PR: thirdweb-dev/js#8106
File: packages/thirdweb/src/react/web/ui/Bridge/bridge-widget/bridge-widget.tsx:34-41
Timestamp: 2025-09-24T11:08:43.783Z
Learning: In BridgeWidgetProps for packages/thirdweb/src/react/web/ui/Bridge/bridge-widget/bridge-widget.tsx, the Swap onError callback signature requires a non-undefined SwapPreparedQuote parameter (unlike Buy's onError which allows undefined quote). This is intentional - SwapWidget's onError is only called when a quote is available.

Applied to files:

  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-tokens.ts
  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/*client.tsx : Interactive UI that relies on hooks (`useState`, `useEffect`, React Query, wallet hooks).

Applied to files:

  • packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx
⏰ 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: Size
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Unit Tests
  • GitHub Check: Lint Packages
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
.changeset/beige-sites-jog.md (1)

2-5: Changeset scope/bump looks right.

Patch bump for “thirdweb” matches a non‑API behavioral tweak. Title is clear.

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

34-36: Confirm symbol search via query is supported — the tokens API’s query option is documented to search by token name or symbol and is applied in the request URL.

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