-
Notifications
You must be signed in to change notification settings - Fork 604
[MNY-213] SDK/SwapWidget: token search improvements #8145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 7495f46 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughIntroduces 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
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Comment |
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
size-limit report 📦
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
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 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 -->
ee2eac0
to
7495f46
Compare
There was a problem hiding this 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.
📒 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 inpackages/*
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 localtypes.ts
barrels
Prefer type aliases over interface except for nominal shapes
Avoidany
andunknown
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
Prefertype
aliases overinterface
except for nominal shapes
Avoidany
andunknown
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 viaquery
is supported — thetokens
API’squery
option is documented to search by token name or symbol and is applied in the request URL.
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
use-tokens.ts
to use aquery
andtokenAddress
based on search conditions.debouncedSearch
variable inselect-token-ui.tsx
to minimize search input delays.debouncedSearch
instead ofsearch
.Summary by CodeRabbit