Skip to content

Commit

Permalink
chore(feed): enhance sanitizeFloatText
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou committed Nov 18, 2024
1 parent b02a670 commit 57224f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/components/socialFeed/SocialActions/TipModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import ModalBase from "../../modals/ModalBase";
import { SpacerColumn } from "../../spacer";

import { Username } from "@/components/user/Username";
import { sanitizeFloatAmount } from "@/utils/text";
import { sanitizeFloatText } from "@/utils/text";

type TipFormType = {
amount: string;
Expand All @@ -63,7 +63,7 @@ export const TipModal: React.FC<{
const formValues = watch();
const amount = nativeCurrency
? Decimal.fromUserInput(
sanitizeFloatAmount(formValues.amount),
sanitizeFloatText(formValues.amount),
nativeCurrency.decimals,
).atomics
: "0";
Expand Down
5 changes: 3 additions & 2 deletions packages/utils/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export const replaceBetweenString = (
) =>
`${origin.substring(0, startIndex)}${insertion}${origin.substring(endIndex)}`;

export const sanitizeFloatAmount = (amount: string) => {
if (amount.endsWith(".")) {
// Fix amount when missing the fractional part like "2." by removing the "."
export const sanitizeFloatText = (amount: string) => {
if (isFloatText(amount) && amount.endsWith(".")) {
return amount.slice(0, -1);
}
return amount;
Expand Down

0 comments on commit 57224f3

Please sign in to comment.