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

fix: handle wrong type inputValue and add tests #156

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from

Conversation

tiendn
Copy link
Contributor

@tiendn tiendn commented Oct 29, 2024

Problem

In this function, it should handle in case of pass param not a string

export const formatInputTokenValue = (inputValue: string) => {
 // code implement 
+ if (inputValue === null || inputValue === undefined || inputValue === "") {
+    return "0";
+ }
+
+ // Convert number to string
+ const inputStr = typeof inputValue === "number" ? Number(inputValue).toString() : inputValue;

  if (inputStr === "0") return inputStr;

.....

- let filteredValue = inputValue.replace(/^0+/, "").replaceAll(/[^0-9.]/g, "");
+ let filteredValue = inputStr.replace(/^0+/, "").replaceAll(/[^0-9.]/g, "");
}

Test

Add formatInputTokenValue unittest.

Copy link

vercel bot commented Oct 29, 2024

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

Name Status Preview Comments Updated (UTC)
storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 29, 2024 4:02am
v2-bend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 29, 2024 4:02am
v2-berps ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 29, 2024 4:02am
v2-honey ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 29, 2024 4:02am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
v2-dex ⬜️ Ignored (Inspect) Visit Preview Oct 29, 2024 4:02am

Copy link

vercel bot commented Oct 29, 2024

@tiendn is attempting to deploy a commit to the Berachain Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant