Skip to content

Conversation

@gregfromstl
Copy link
Contributor

@gregfromstl gregfromstl commented Aug 8, 2025


PR-Codex overview

This PR focuses on sorting payment quotes in ascending order within the usePaymentMethods.ts file by adjusting the calculation logic for comparing quotes.

Detailed summary

  • Updated the sorting logic in usePaymentMethods.ts to sort payment quotes based on originAmount and prices.USD.
  • Swapped the usage of a and b in the calculations to ensure correct ascending order sorting.

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

Summary by CodeRabbit

  • Bug Fixes

    • Corrected the sorting of payment quotes to ensure they are now displayed in ascending order based on their USD value.
  • Chores

    • Added documentation for the patch update related to payment quote sorting.

@gregfromstl gregfromstl requested review from a team as code owners August 8, 2025 19:28
@linear
Copy link

linear bot commented Aug 8, 2025

@changeset-bot
Copy link

changeset-bot bot commented Aug 8, 2025

🦋 Changeset detected

Latest commit: de9b4f0

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

@vercel
Copy link

vercel bot commented Aug 8, 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 Aug 8, 2025 7:42pm
nebula ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2025 7:42pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2025 7:42pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2025 7:42pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2025 7:42pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

Walkthrough

A changeset file was added to document a patch update for the "thirdweb" package, specifying that payment quotes are now sorted in ascending order. The sorting logic within usePaymentMethods.ts was corrected to ensure quotes are properly ordered by USD value. No public API or signature changes were made.

Changes

Cohort / File(s) Change Summary
Changeset Documentation
.changeset/dirty-roses-carry.md
Added a changeset file documenting a patch update for the "thirdweb" package regarding payment quote sorting.
Payment Methods Sorting Logic
packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts
Corrected the sorting logic for payment quotes to ensure ascending order by USD value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 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.
✨ 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/mny-96-sort-wallet-quotes-in-ascending-order

🪧 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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 8, 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: 1

🔭 Outside diff range comments (1)
packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (1)

100-108: Apply the same ?? 1 fix to the insufficient-balance sorter

For parity and correctness, avoid treating 0 USD as 1 here as well.

-            ) *
-              (a.originToken.prices.USD || 1) -
+            ) *
+              (a.originToken.prices.USD ?? 1) -
             Number.parseFloat(
               toTokens(b.quote.originAmount, b.originToken.decimals),
             ) *
-              (b.originToken.prices.USD || 1)
+              (b.originToken.prices.USD ?? 1)
🧹 Nitpick comments (1)
packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (1)

96-124: Optional: precompute USD values to avoid repeated conversions during sort

This reduces repeated toTokens + parseFloat work inside the comparator and keeps logic DRY.

// compute once per item and sort by the precomputed key (Schwartzian transform)
const insufficientBalanceQuotes = validTokenQuotes
  .filter((s) => s.balance < s.quote.originAmount)
  .map((q) => ({
    q,
    usd:
      Number.parseFloat(toTokens(q.quote.originAmount, q.originToken.decimals)) *
      (q.originToken.prices.USD ?? 1),
  }))
  .sort((a, b) => a.usd - b.usd)
  .map((x) => x.q);

const sufficientBalanceQuotes = validTokenQuotes
  .filter((s) => s.balance >= s.quote.originAmount)
  .map((q) => ({
    q,
    usd:
      Number.parseFloat(toTokens(q.quote.originAmount, q.originToken.decimals)) *
      (q.originToken.prices.USD ?? 1),
  }))
  .sort((a, b) => a.usd - b.usd)
  .map((x) => x.q);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c458ea and de9b4f0.

📒 Files selected for processing (2)
  • .changeset/dirty-roses-carry.md (1 hunks)
  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{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

Files:

  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.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/usePaymentMethods.ts
🧠 Learnings (7)
📓 Common learnings
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
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: 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.
📚 Learning: 2025-07-18T19:19:55.613Z
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

Applied to files:

  • .changeset/dirty-roses-carry.md
📚 Learning: 2025-05-27T19:55:25.056Z
Learnt from: MananTank
PR: thirdweb-dev/js#7177
File: apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_hooks/useTokenPriceData.ts:49-49
Timestamp: 2025-05-27T19:55:25.056Z
Learning: In the ERC20 public pages token price data hook (`useTokenPriceData.ts`), direct array access on `json.data[0]` without optional chaining is intentionally correct and should not be changed to use safety checks.

Applied to files:

  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts
📚 Learning: 2025-06-26T19:46:04.024Z
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.

Applied to files:

  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts
📚 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/core/hooks/usePaymentMethods.ts
📚 Learning: 2025-07-18T19:19:55.613Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to test/src/test-wallets.ts : Predefined test accounts are in `test/src/test-wallets.ts`

Applied to files:

  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts
📚 Learning: 2025-07-18T19:19:55.613Z
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

Applied to files:

  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts
⏰ 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: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Build Packages
  • GitHub Check: Lint Packages
  • GitHub Check: Unit Tests
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (1)

115-121: Ascending comparator fix is correct

The comparator now returns value(a) - value(b), which sorts ascending as intended. Matches the PR objective.

.changeset/dirty-roses-carry.md (1)

1-5: Changeset looks good

Proper patch entry for "thirdweb" with a concise message that matches the code change.

toTokens(a.quote.originAmount, a.originToken.decimals),
) *
(b.originToken.prices.USD || 1) -
(a.originToken.prices.USD || 1) -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use nullish coalescing instead of logical OR for USD price

|| 1 treats a legitimate 0 USD price as 1. Use ?? 1 to only default when price is null/undefined.

-              (a.originToken.prices.USD || 1) -
+              (a.originToken.prices.USD ?? 1) -
...
-              (b.originToken.prices.USD || 1)
+              (b.originToken.prices.USD ?? 1)

Also applies to: 121-121

🤖 Prompt for AI Agents
In packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts at lines 117 and
121, replace the logical OR operator (||) used for defaulting USD prices with
the nullish coalescing operator (??). This change ensures that a valid 0 USD
price is not incorrectly replaced by 1, and the default of 1 is only applied
when the price is null or undefined.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 64.03 KB (0%) 1.3 s (0%) 136 ms (+336.71% 🔺) 1.5 s
thirdweb (cjs) 357.38 KB (0%) 7.2 s (0%) 163 ms (+20.81% 🔺) 7.4 s
thirdweb (minimal + tree-shaking) 5.72 KB (0%) 115 ms (0%) 72 ms (+1365.27% 🔺) 187 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 60 ms (+1830.66% 🔺) 70 ms
thirdweb/react (minimal + tree-shaking) 19.16 KB (0%) 384 ms (0%) 109 ms (+656.09% 🔺) 492 ms

@codecov
Copy link

codecov bot commented Aug 8, 2025

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.33%. Comparing base (7c458ea) to head (de9b4f0).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...thirdweb/src/react/core/hooks/usePaymentMethods.ts 0.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7819   +/-   ##
=======================================
  Coverage   56.33%   56.33%           
=======================================
  Files         905      905           
  Lines       58821    58821           
  Branches     4144     4146    +2     
=======================================
  Hits        33137    33137           
  Misses      25578    25578           
  Partials      106      106           
Flag Coverage Δ
packages 56.33% <0.00%> (ø)
Files with missing lines Coverage Δ
...thirdweb/src/react/core/hooks/usePaymentMethods.ts 5.51% <0.00%> (ø)
🚀 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.

2 participants