Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dirty-roses-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Sort payment quotes in ascending order
8 changes: 4 additions & 4 deletions packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@
.sort((a, b) => {
return (
Number.parseFloat(
toTokens(b.quote.originAmount, b.originToken.decimals),
toTokens(a.quote.originAmount, a.originToken.decimals),

Check warning on line 115 in packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts#L115

Added line #L115 was not covered by tests
) *
(b.originToken.prices.USD || 1) -
(a.originToken.prices.USD || 1) -

Check warning on line 117 in packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts#L117

Added line #L117 was not covered by tests
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.

Number.parseFloat(
toTokens(a.quote.originAmount, a.originToken.decimals),
toTokens(b.quote.originAmount, b.originToken.decimals),

Check warning on line 119 in packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts#L119

Added line #L119 was not covered by tests
) *
(a.originToken.prices.USD || 1)
(b.originToken.prices.USD || 1)

Check warning on line 121 in packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts#L121

Added line #L121 was not covered by tests
);
});

Expand Down
Loading