Skip to content
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

[SDK] fix: Handle comma decimal input in PayEmbed #6386

Merged
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/mean-animals-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Handle comma for decimal input in PayEmbed
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@
onChange={(e) => {
let value = e.target.value;

// Replace comma with period if it exists
value = value.replace(",", ".");

Check warning on line 658 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx#L658

Added line #L658 was not covered by tests
Copy link

Choose a reason for hiding this comment

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

Consider using replaceAll() instead of replace() since the input may contain multiple commas that need to be converted to decimal points. Example: "1,234,56" -> "1.234.56"

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.


if (value.startsWith(".")) {
value = `0${value}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
onChange={(e) => {
let value = e.target.value;

// Replace comma with period if it exists
value = value.replace(",", ".");

Check warning on line 77 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/BuyTokenInput.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/BuyTokenInput.tsx#L77

Added line #L77 was not covered by tests

if (value.startsWith(".")) {
value = `0${value}`;
}
Expand Down