Skip to content

Conversation

gregfromstl
Copy link
Member

@gregfromstl gregfromstl commented Sep 15, 2025

Adds a brief pause after we receive a COMPLETED onramp status. This ensures balance is the latest value in our RPC and any subsequent transactions do not fail on simulation.


PR-Codex overview

This PR addresses a potential race condition in the thirdweb widget onramps, ensuring that the simulation does not fail due to timing issues with token balance updates.

Detailed summary

  • Added a 2-second pause using setTimeout in useStepExecutor.ts to handle race conditions where the onramp provider reports a completed status before the token balance updates.
  • Updated the onramp status to "completed" after the pause.
  • Introduced a typedStatusResult object for a discriminated union.

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

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of widget onramps by adding a brief post-completion delay to prevent false failure states and reduce flakiness after successful transactions. No changes to user flows or interfaces.
  • Chores

    • Added release metadata for a patch update noting the onramp reliability fix.
    • No code-visible API changes or alterations to exported functionality.

Adds a brief pause after we receive a COMPLETED onramp status. This
ensures balance is the latest value in our RPC and any subsequent
transactions do not fail on simulation.
@gregfromstl gregfromstl requested review from a team as code owners September 15, 2025 16:37
Copy link

changeset-bot bot commented Sep 15, 2025

🦋 Changeset detected

Latest commit: 5d9480e

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 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 Sep 15, 2025 4:54pm
nebula Ready Ready Preview Comment Sep 15, 2025 4:54pm
thirdweb_playground Ready Ready Preview Comment Sep 15, 2025 4:54pm
thirdweb-www Ready Ready Preview Comment Sep 15, 2025 4:54pm
wallet-ui Ready Ready Preview Comment Sep 15, 2025 4:54pm

Copy link
Contributor

coderabbitai bot commented Sep 15, 2025

Walkthrough

Introduces a changeset entry for the thirdweb package (patch) and updates useStepExecutor to insert a 2-second delay after detecting onramp completion before marking it completed, with a comment explaining an RPC balance update race condition. No public API changes.

Changes

Cohort / File(s) Summary of Changes
Release metadata
.changeset/floppy-clocks-wave.md
Adds a patch-level changeset for thirdweb describing prevention of incorrect widget onramp failures; metadata only, no code changes.
Onramp completion flow delay
packages/thirdweb/src/react/core/hooks/useStepExecutor.ts
On detecting onramp status COMPLETED, adds a 2s wait before setting completion and recording status; adds comment about RPC balance update race; no API surface changes.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor User
    participant Widget
    participant useStepExecutor
    participant OnrampProvider as Onramp Provider
    participant RPC as RPC/Balance

    User->>Widget: Initiate onramp
    Widget->>useStepExecutor: Start onramp flow
    useStepExecutor->>OnrampProvider: Poll onramp status
    OnrampProvider-->>useStepExecutor: Status = COMPLETED
    note over useStepExecutor: New behavior: wait ~2s to avoid race with RPC balance updates
    useStepExecutor-->>useStepExecutor: Delay 2000ms
    useStepExecutor->>RPC: (Subsequent) Balance reflects funds
    useStepExecutor-->>Widget: Mark onramp completed + record status
    Widget-->>User: Show completion
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description includes a clear, concise summary of the change and a PR-Codex overview, but it does not populate the repository's required template fields: the formatted title/issue tag, "Notes for the reviewer", and "How to test" sections are left empty or unfilled. Because the <description_template> is specified as required for this repository, those missing sections mean the description does not fully meet the template's expectations. As a result the description cannot be considered complete against the repository standard. Please update the PR description to follow the repository template: set the title in the required "[SDK/Dashboard/Portal] Feature/Fix: …" format and include the issue tag if applicable, add a "Notes for the reviewer" section explaining the race-condition context and any tradeoffs, and add a "How to test" section with concrete manual steps or tests to reproduce and validate the 2-second pause fix; also list key files changed and areas reviewers should focus on. Once those sections are filled the description will meet the repository's required template.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Fix: Add brief pause after onramp" is concise, a single sentence, and accurately reflects the primary change (adding a short pause after onramp completion to avoid RPC race conditions). It clearly communicates the developer's intent and is appropriate for a teammate scanning history. Including an explicit scope prefix (e.g., "[SDK]" or "[Portal]") would further align the title with the repository's conventional format.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch greg/fix-onramp-race-condition

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.

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

graphite-app bot commented Sep 15, 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.

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/core/hooks/useStepExecutor.ts (1)

388-391: Break out on FAILED to avoid infinite polling loop.

When onramp reports FAILED, we set state but never exit the poller; it will loop forever. Align with tx polling which throws on failure.

-        } else if (status === "FAILED") {
-          setOnrampStatus("failed");
-        }
+        } else if (status === "FAILED") {
+          setOnrampStatus("failed");
+          throw new Error("Onramp failed");
+        }
🧹 Nitpick comments (3)
.changeset/floppy-clocks-wave.md (1)

1-5: Changeset added correctly; consider a clearer, action-oriented description.

Suggestion: “Onramp: add 2s post‑completion pause to avoid RPC balance race causing simulation failures.” Improves changelog usefulness.

packages/thirdweb/src/react/core/hooks/useStepExecutor.ts (2)

375-379: Make the 2s pause abortable (respect cancel) and configurable.

Current timeout can’t be canceled mid-wait; honor the provided AbortSignal and avoid hard-coding.

Apply within this range:

-          await new Promise((resolve) => setTimeout(resolve, 2000));
+          await abortableDelay(2000, abortSignal);

Add helper (outside this range, near poller util or top-level in this file):

function abortableDelay(ms: number, signal: AbortSignal): Promise<void> {
  return new Promise((resolve, reject) => {
    const t = setTimeout(resolve, ms);
    const onAbort = () => {
      clearTimeout(t);
      signal.removeEventListener("abort", onAbort);
      reject(new Error("Aborted"));
    };
    signal.addEventListener("abort", onAbort, { once: true });
  });
}

Optional: surface postOnrampDelayMs?: number in StepExecutorOptions with default 2000.


240-241: DRY the identical “RPC catch-up” sleeps into a shared utility.

Both approval/fee path and onramp use a 2s delay. Centralize via abortableDelay(ms, signal) for consistency and cancellation support.

Also applies to: 375-379

📜 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 f9bbf81 and 5d9480e.

📒 Files selected for processing (2)
  • .changeset/floppy-clocks-wave.md (1 hunks)
  • packages/thirdweb/src/react/core/hooks/useStepExecutor.ts (1 hunks)
🧰 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 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/core/hooks/useStepExecutor.ts
**/*.{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/core/hooks/useStepExecutor.ts
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/core/hooks/useStepExecutor.ts
.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/floppy-clocks-wave.md
⏰ 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: Size
  • GitHub Check: Unit Tests
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Lint Packages
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript)

Copy link
Contributor

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 63.96 KB (0%) 1.3 s (0%) 395 ms (+52.75% 🔺) 1.7 s
thirdweb (cjs) 361.44 KB (0%) 7.3 s (0%) 2.2 s (-3.48% 🔽) 9.5 s
thirdweb (minimal + tree-shaking) 5.73 KB (0%) 115 ms (0%) 107 ms (+407.27% 🔺) 222 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 52 ms (+91.01% 🔺) 62 ms
thirdweb/react (minimal + tree-shaking) 19.15 KB (0%) 383 ms (0%) 105 ms (+861.33% 🔺) 488 ms

Copy link

codecov bot commented Sep 15, 2025

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 56.53%. Comparing base (f9bbf81) to head (5d9480e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...s/thirdweb/src/react/core/hooks/useStepExecutor.ts 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8052      +/-   ##
==========================================
- Coverage   56.53%   56.53%   -0.01%     
==========================================
  Files         904      904              
  Lines       58864    58865       +1     
  Branches     4166     4166              
==========================================
  Hits        33280    33280              
- Misses      25478    25479       +1     
  Partials      106      106              
Flag Coverage Δ
packages 56.53% <0.00%> (-0.01%) ⬇️
Files with missing lines Coverage Δ
...s/thirdweb/src/react/core/hooks/useStepExecutor.ts 1.82% <0.00%> (-0.01%) ⬇️
🚀 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.

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.

1 participant