Skip to content

[SDK] Fix TransactionWidget when wallet has enough currency #7656

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

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Jul 21, 2025


PR-Codex overview

This PR focuses on fixing the TransactionWidget to handle scenarios where a user's wallet has insufficient funds for a transaction, ensuring they are prompted to fund their wallet with the necessary amount.

Detailed summary

  • Updated the TransactionWidget in transaction-button.tsx to reflect the correct amount.
  • Enhanced the logic in TransactionPayment.tsx to check if the userBalance is less than the totalCost.
  • Added a condition to fund the wallet with the difference if the balance is insufficient.
  • Adjusted the onContinue function to handle both cases: insufficient funds and sufficient funds.

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

Summary by CodeRabbit

  • Bug Fixes

    • Resolved an issue in the transaction widget where wallet balances were not correctly checked, ensuring transactions only proceed when sufficient funds are available.
    • Improved handling of transaction amounts, so the widget now accurately requests additional funds only when the wallet balance is insufficient.
  • Chores

    • Removed a hardcoded transaction amount from the payment preview interface.

Copy link

vercel bot commented Jul 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 21, 2025 9:08am
nebula ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 21, 2025 9:08am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 21, 2025 9:08am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 21, 2025 9:08am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 21, 2025 9:08am

Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

This change updates the transaction payment logic to more accurately handle wallet balance checks in the TransactionWidget. The update removes a hardcoded transaction amount in one component and refines the calculation of the required funding amount based on the user's actual balance, ensuring correct behavior when proceeding with transactions.

Changes

File(s) Change Summary
.changeset/lucky-ravens-hope.md Adds a changeset describing the patch update and its purpose.
apps/playground-web/src/components/pay/transaction-button.tsx Removes the hardcoded amount={"0.001"} prop from the TransactionWidget in PayTransactionPreview.
packages/thirdweb/src/react/web/ui/Bridge/TransactionPayment.tsx Refines onClick logic to conditionally calculate and pass the funding amount based on user balance and cost.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TransactionWidget
    participant TransactionPayment

    User->>TransactionWidget: Initiate transaction
    TransactionWidget->>TransactionPayment: Request to proceed
    TransactionPayment->>TransactionWidget: Check userBalance vs. totalCost
    alt userBalance < totalCost
        TransactionPayment->>TransactionWidget: onContinue(shortfall amount)
    else userBalance >= totalCost or undefined
        TransactionPayment->>TransactionWidget: onContinue(totalCost)
    end
    TransactionWidget->>User: Proceed with transaction or request funding
Loading

Estimated code review effort

2 (10–30 minutes)

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.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 426bb8b and 1b2f474.

📒 Files selected for processing (3)
  • .changeset/lucky-ravens-hope.md (1 hunks)
  • apps/playground-web/src/components/pay/transaction-button.tsx (0 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/TransactionPayment.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/playground-web/src/components/pay/transaction-button.tsx
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • CLAUDE.md
**/*.{ts,tsx,js,jsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • CLAUDE.md
🧠 Learnings (3)
📓 Common learnings
Learnt from: MananTank
PR: thirdweb-dev/js#7307
File: apps/dashboard/src/app/nebula-app/move-funds/move-funds.tsx:324-346
Timestamp: 2025-06-09T15:15:02.350Z
Learning: In the move-funds functionality, MananTank prefers having both individual toast.promise notifications for each token transfer AND batch summary toasts, even though this creates multiple notifications. This dual notification approach is acceptable for the move-funds user experience.
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Support for in-app wallets (social/email login)
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules
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).
Learnt from: MananTank
PR: thirdweb-dev/js#7081
File: apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/assets/create/create-token-page-impl.tsx:110-118
Timestamp: 2025-05-20T18:54:15.781Z
Learning: In the thirdweb dashboard's token asset creation flow, the `transferBatch` function from `thirdweb/extensions/erc20` accepts the raw quantity values from the form without requiring explicit conversion to wei using `toUnits()`. The function appears to handle this conversion internally or is designed to work with the values in the format they're already provided.
Learnt from: gregfromstl
PR: thirdweb-dev/js#7450
File: packages/thirdweb/src/bridge/Webhook.ts:57-81
Timestamp: 2025-06-26T19:46:04.024Z
Learning: In the onramp webhook schema (`packages/thirdweb/src/bridge/Webhook.ts`), the `currencyAmount` field is intentionally typed as `z.number()` while other amount fields use `z.string()` because `currencyAmount` represents fiat currency amounts in decimals (like $10.50), whereas other amount fields represent token amounts in wei (very large integers that benefit from bigint representation). The different naming convention (`currencyAmount` vs `amount`) reflects this intentional distinction.
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Surface breaking changes prominently in PR descriptions
.changeset/lucky-ravens-hope.md (5)

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Unified Wallet and Account interfaces in wallet architecture

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Smart wallets with account abstraction

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Support for in-app wallets (social/email login)

Learnt from: MananTank
PR: #7081
File: apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/assets/create/create-token-page-impl.tsx:110-118
Timestamp: 2025-05-20T18:54:15.781Z
Learning: In the thirdweb dashboard's token asset creation flow, the transferBatch function from thirdweb/extensions/erc20 accepts the raw quantity values from the form without requiring explicit conversion to wei using toUnits(). The function appears to handle this conversion internally or is designed to work with the values in the format they're already provided.

packages/thirdweb/src/react/web/ui/Bridge/TransactionPayment.tsx (4)

Learnt from: gregfromstl
PR: #7450
File: packages/thirdweb/src/bridge/Webhook.ts:57-81
Timestamp: 2025-06-26T19:46:04.024Z
Learning: In the onramp webhook schema (packages/thirdweb/src/bridge/Webhook.ts), the currencyAmount field is intentionally typed as z.number() while other amount fields use z.string() because currencyAmount represents fiat currency amounts in decimals (like $10.50), whereas other amount fields represent token amounts in wei (very large integers that benefit from bigint representation). The different naming convention (currencyAmount vs amount) reflects this intentional distinction.

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).

Learnt from: jnsdls
PR: #7364
File: apps/dashboard/src/app/(app)/account/components/AccountHeader.tsx:36-41
Timestamp: 2025-06-18T02:13:34.500Z
Learning: In the logout flow in apps/dashboard/src/app/(app)/account/components/AccountHeader.tsx, when doLogout() fails, the cleanup steps (resetAnalytics(), wallet disconnect, router refresh) should NOT execute. This is intentional to maintain consistency - if server-side logout fails, client-side cleanup should not occur.

Learnt from: MananTank
PR: #7307
File: apps/dashboard/src/app/nebula-app/move-funds/move-funds.tsx:324-346
Timestamp: 2025-06-09T15:15:02.350Z
Learning: In the move-funds functionality, MananTank prefers having both individual toast.promise notifications for each token transfer AND batch summary toasts, even though this creates multiple notifications. This dual notification approach is acceptable for the move-funds user experience.

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

364-383: Improved wallet balance handling logic.

The updated logic correctly distinguishes between insufficient and sufficient wallet balance scenarios:

  • When userBalance exists but is insufficient, it calculates the exact shortfall amount
  • When userBalance is sufficient (or undefined), it passes the full transaction cost
  • This fixes the previous behavior that may have incorrectly handled cases where the wallet had enough currency

The explicit null checks and clear conditional logic improve reliability of the transaction flow.

.changeset/lucky-ravens-hope.md (1)

1-6: Well-documented changeset entry.

The changeset clearly describes the fix for TransactionWidget wallet balance handling, properly categorized as a patch update for the thirdweb package.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added Playground Changes involving the Playground codebase. packages SDK Involves changes to the thirdweb SDK labels Jul 21, 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.

@joaquim-verges joaquim-verges changed the title [thirdweb] Fix TransactionWidget when wallet has enough currency [SDK] Fix TransactionWidget when wallet has enough currency Jul 21, 2025
@joaquim-verges joaquim-verges marked this pull request as ready for review July 21, 2025 08:59
@joaquim-verges joaquim-verges requested review from a team as code owners July 21, 2025 08:59
Copy link
Contributor

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 63.23 KB (0%) 1.3 s (0%) 554 ms (+155.3% 🔺) 1.9 s
thirdweb (cjs) 353.45 KB (0%) 7.1 s (0%) 1.8 s (+17.02% 🔺) 8.8 s
thirdweb (minimal + tree-shaking) 5.7 KB (0%) 114 ms (0%) 200 ms (+1964.08% 🔺) 314 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 12 ms (+48.48% 🔺) 22 ms
thirdweb/react (minimal + tree-shaking) 19.59 KB (0%) 392 ms (0%) 170 ms (+454.38% 🔺) 561 ms

Copy link

codecov bot commented Jul 21, 2025

Codecov Report

Attention: Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.

Project coverage is 56.40%. Comparing base (426bb8b) to head (1b2f474).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...web/src/react/web/ui/Bridge/TransactionPayment.tsx 0.00% 15 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    #7656      +/-   ##
==========================================
- Coverage   56.41%   56.40%   -0.01%     
==========================================
  Files         908      908              
  Lines       58218    58228      +10     
  Branches     4226     4226              
==========================================
  Hits        32844    32844              
- Misses      25264    25274      +10     
  Partials      110      110              
Flag Coverage Δ
packages 56.40% <0.00%> (-0.01%) ⬇️
Files with missing lines Coverage Δ
...web/src/react/web/ui/Bridge/TransactionPayment.tsx 6.60% <0.00%> (-0.20%) ⬇️
🚀 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.

@joaquim-verges joaquim-verges merged commit bfa0a42 into main Jul 21, 2025
26 of 27 checks passed
@joaquim-verges joaquim-verges deleted the _thirdweb_Fix_TransactionWidget_when_wallet_has_enough_currency branch July 21, 2025 09:13
@joaquim-verges joaquim-verges mentioned this pull request Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages Playground Changes involving the Playground codebase. SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant