Skip to content

Conversation

@MananTank
Copy link
Member

@MananTank MananTank commented Oct 15, 2025


PR-Codex overview

This PR focuses on enhancing the BuyWidget and FundWallet components by introducing state management for token selection and amount selection, improving the user experience during transactions.

Detailed summary

  • Added NATIVE_TOKEN_ADDRESS import to BuyWidget.tsx.
  • Introduced AmountSelection and SelectedToken types in FundWallet.tsx.
  • Replaced initialSelection in FundWallet with selectedToken and amountSelection props.
  • Updated state management in BuyWidget for amountSelection and selectedToken.
  • Adjusted FundWallet to use props for token selection and amount instead of local state.
  • Modified the FundWallet component to handle props for token and amount selection updates.

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

Summary by CodeRabbit

  • New Features

    • Defaults to the native token when no token is specified, improving the initial funding experience.
  • Refactor

    • Centralized token and amount selection in the parent widget for more consistent, predictable behavior across the Buy/Fund flow.
    • Streamlined state updates between selection controls and related UI, reducing mismatches and improving responsiveness.

@linear
Copy link

linear bot commented Oct 15, 2025

@changeset-bot
Copy link

changeset-bot bot commented Oct 15, 2025

⚠️ No Changeset found

Latest commit: b096d45

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel
Copy link

vercel bot commented Oct 15, 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 Oct 15, 2025 7:56pm
nebula Ready Ready Preview Comment Oct 15, 2025 7:56pm
thirdweb_playground Ready Ready Preview Comment Oct 15, 2025 7:56pm
thirdweb-www Building Building Oct 15, 2025 7:56pm
wallet-ui Ready Ready Preview Comment Oct 15, 2025 7:56pm

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


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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Walkthrough

State 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

Cohort / File(s) Summary of changes
Bridge widget parent state lift
packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx
Imports and uses SelectedToken and AmountSelection types; adds state for selectedToken and amountSelection; defaults token using NATIVE_TOKEN_ADDRESS; passes selectedToken/setSelectedToken and amountSelection/setAmountSelection to FundWallet; removes initialSelection flow.
FundWallet externalized state
packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx
Exports SelectedToken and AmountSelection types; FundWalletProps now require selectedToken, setSelectedToken, amountSelection, setAmountSelection; removes internal initialSelection state; updates internal logic and child wiring to use props for selection and amounts.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description still contains the template placeholders and lacks the required sections such as “Notes for the reviewer” and “How to test,” so it does not adhere to the repository’s description template. Please remove the template comments and populate the “Notes for the reviewer” and “How to test” sections with relevant details to comply with the repository’s PR description guidelines.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 pull request title clearly states the primary change, which is preserving the token and amount selection in the BuyWidget when returning to the initial screen, and it is concise and free of extraneous details.
Linked Issues Check ✅ Passed The changes lift the token and amount state into the parent BuyWidget and pass them through to FundWallet, which ensures that selections are preserved when returning to the initial screen as specified by issue MNY-254.
Out of Scope Changes Check ✅ Passed All modifications focus on state management for token and amount selection in the BuyWidget and FundWallet components and do not introduce any unrelated or out-of-scope changes.
✨ 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-254

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
Copy link
Contributor

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 64.51 KB (0%) 1.3 s (0%) 235 ms (+118.7% 🔺) 1.6 s
thirdweb (cjs) 365.68 KB (0%) 7.4 s (0%) 1.1 s (+8.69% 🔺) 8.4 s
thirdweb (minimal + tree-shaking) 5.73 KB (0%) 115 ms (0%) 149 ms (+3325.16% 🔺) 264 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 71 ms (+747.35% 🔺) 81 ms
thirdweb/react (minimal + tree-shaking) 19.13 KB (0%) 383 ms (0%) 122 ms (+2332.27% 🔺) 505 ms

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: 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 | undefined at usage. Define a concrete shape and use SelectedToken | undefined where 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 clicks

Button 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 when props.amount changes

If amount prop 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 file

Importing types from a component file works, but consider moving SelectedToken and AmountSelection to a local types.ts to 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.

📥 Commits

Reviewing files that changed from the base of the PR and between e830109 and b096d45.

📒 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 @/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/BuyWidget.tsx
  • packages/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.tsx
  • packages/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 @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/BuyWidget.tsx
  • packages/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 screens

Passing controlled selectedToken and amountSelection into FundWallet meets the PR goal.

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

151-155: No changes needed: useTokenQuery disables fetching when chainId is undefined (enabled: !!params.chainId) and falls back to NATIVE_TOKEN_ADDRESS for an undefined tokenAddress.

@jakeloo jakeloo merged commit 6a6b0fb into main Oct 16, 2025
57 of 63 checks passed
@jakeloo jakeloo deleted the mny-254 branch October 16, 2025 17:20
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.

3 participants