-
Notifications
You must be signed in to change notification settings - Fork 619
[MNY-254] SDK: Preserve token and amount selection in BuyWidget when going back to initial screen #8260
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
…going back to initial screen
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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. |
WalkthroughState for token and amount selection was lifted from FundWallet to BuyWidget’s BridgeWidgetContent. FundWallet now receives and updates selection via props and exported types (SelectedToken, AmountSelection). BuyWidget imports these types, initializes state (with NATIVE_TOKEN_ADDRESS default), and passes it to FundWallet. initialSelection was removed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant BuyWidget as BridgeWidgetContent
participant FundWallet
note over BuyWidget: Initialize state<br/>selectedToken (default via NATIVE_TOKEN_ADDRESS)<br/>amountSelection
User->>BuyWidget: Open Buy flow
BuyWidget->>FundWallet: Render with { selectedToken, setSelectedToken, amountSelection, setAmountSelection }
User->>FundWallet: Choose token / enter amount
FundWallet->>BuyWidget: setSelectedToken(token)
FundWallet->>BuyWidget: setAmountSelection(sel)
BuyWidget->>FundWallet: Re-render with updated props
note over FundWallet: Uses props for queries,<br/>balances, and child components
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Comment |
size-limit report 📦
|
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: 2
🧹 Nitpick comments (5)
packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx (3)
88-91: TSDoc missing for new public types; simplify SelectedToken typing
- Add TSDoc with a custom tag (e.g., @internal) per package guidelines.
- Avoid embedding undefined in the alias and then repeating
| undefinedat usage. Define a concrete shape and useSelectedToken | undefinedwhere needed.As per coding guidelines
- selectedToken: SelectedToken | undefined; + selectedToken: SelectedToken | undefined; setSelectedToken: (token: SelectedToken | undefined) => void; amountSelection: AmountSelection; setAmountSelection: (amountSelection: AmountSelection) => void; @@ -export type SelectedToken = - | { - chainId: number; - tokenAddress: string; - } - | undefined; +/** + * The currently selected destination token. + * @internal + * @example + * const sel: SelectedToken = { chainId: 1, tokenAddress: "0x..." }; + */ +export type SelectedToken = { + chainId: number; + tokenAddress: string; +}; @@ -export type AmountSelection = +/** + * Represents user's amount input as either fiat or token units. + * @internal + * @example + * const a1: AmountSelection = { type: "usd", value: "100" }; + * const a2: AmountSelection = { type: "token", value: "0.05" }; + */ +export type AmountSelection = | { type: "usd"; value: string; } | { type: "token"; value: string; };Also applies to: 117-133
284-318: Disable Continue until token and amount are valid to avoid no-op clicksButton is clickable when token/amount are invalid, but onClick returns early. Disable it instead.
- <Button - disabled={!receiver} + <Button + disabled={!canContinue} fullWidth onClick={() => { if (!receiver || !destinationToken) { return; }Add this near other derived values in the component:
// derive once per render to gate button state const fiatPricePerToken = destinationToken?.prices[props.currency]; const { tokenValue } = getAmounts(props.amountSelection, fiatPricePerToken); const canContinue = Boolean(receiver && destinationToken && tokenValue);
456-463: Preserve 0 values in inputs (avoid falsy checks)Current truthy checks hide legitimate 0, causing UX glitches.
- <DecimalInput - value={tokenValue ? String(tokenValue) : ""} + <DecimalInput + value={tokenValue !== undefined ? String(tokenValue) : ""} setValue={(value) => { props.setAmount({ type: "token", value, }); }}- <DecimalInput - value={String(fiatValue || 0)} + <DecimalInput + value={fiatValue !== undefined ? String(fiatValue) : ""} setValue={(value) => { props.setAmount({ type: "usd", value, }); }}Also applies to: 503-521
packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx (2)
462-466: Optionally sync amountSelection whenprops.amountchangesIf
amountprop can change after mount, keep state aligned when user hasn't typed yet.import { useEffect } from "react"; useEffect(() => { if (props.amount === undefined) return; setAmountSelection((prev) => prev.value ? prev : { type: "token", value: props.amount! }, ); }, [props.amount]);
32-36: Decouple types from component fileImporting types from a component file works, but consider moving
SelectedTokenandAmountSelectionto a localtypes.tsto reduce coupling and avoid future cycles.
📜 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 (2)
packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx(4 hunks)packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx(6 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{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@/typesor localtypes.tsbarrels
Prefer type aliases over interface except for nominal shapes
Avoidanyandunknownunless 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@/typeswhere applicable
Prefertypealiases overinterfaceexcept for nominal shapes
Avoidanyandunknownunless 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/BuyWidget.tsxpackages/thirdweb/src/react/web/ui/Bridge/FundWallet.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/BuyWidget.tsxpackages/thirdweb/src/react/web/ui/Bridge/FundWallet.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@exampleand 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/BuyWidget.tsxpackages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx
🧠 Learnings (1)
📚 Learning: 2025-10-03T23:36:00.631Z
Learnt from: MananTank
PR: thirdweb-dev/js#8181
File: packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx:27-27
Timestamp: 2025-10-03T23:36:00.631Z
Learning: In packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx, the component intentionally uses a hardcoded English locale (connectLocaleEn) rather than reading from the provider, as BuyWidget is designed to be English-only and does not require internationalization support.
Applied to files:
packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx
🧬 Code graph analysis (2)
packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx (2)
packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx (2)
AmountSelection(124-132)SelectedToken(117-122)packages/thirdweb/src/exports/thirdweb.ts (1)
NATIVE_TOKEN_ADDRESS(31-31)
packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx (1)
packages/thirdweb/src/react/web/ui/Bridge/common/token-balance.tsx (1)
useTokenBalance(7-23)
⏰ 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: Build Packages
- GitHub Check: Size
- GitHub Check: Unit Tests
- GitHub Check: Lint Packages
- GitHub Check: E2E Tests (pnpm, vite)
- GitHub Check: E2E Tests (pnpm, esbuild)
- GitHub Check: E2E Tests (pnpm, webpack)
- GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx (1)
503-507: State wiring LGTM; preserves selection across screensPassing controlled
selectedTokenandamountSelectioninto FundWallet meets the PR goal.packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx (1)
151-155: No changes needed:useTokenQuerydisables fetching whenchainIdis undefined (enabled: !!params.chainId) and falls back toNATIVE_TOKEN_ADDRESSfor an undefinedtokenAddress.

PR-Codex overview
This PR focuses on enhancing the
BuyWidgetandFundWalletcomponents by introducing state management for token selection and amount selection, improving the user experience during transactions.Detailed summary
NATIVE_TOKEN_ADDRESSimport toBuyWidget.tsx.AmountSelectionandSelectedTokentypes inFundWallet.tsx.initialSelectioninFundWalletwithselectedTokenandamountSelectionprops.BuyWidgetforamountSelectionandselectedToken.FundWalletto use props for token selection and amount instead of local state.FundWalletcomponent to handle props for token and amount selection updates.Summary by CodeRabbit
New Features
Refactor