From 99b40e2f9d9da8f5feae86f722c6da0f20775ee7 Mon Sep 17 00:00:00 2001 From: Jeesun Kim <3912060+jeesunikim@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:44:31 -0800 Subject: [PATCH] remove leadingZeros for and validate.getAmountError --- src/app/(sidebar)/transaction/build/components/Params.tsx | 3 ++- src/app/(sidebar)/transaction/fee-bump/page.tsx | 3 ++- src/components/formComponentTemplateEndpoints.tsx | 8 +++++--- src/components/formComponentTemplateTxnOps.tsx | 6 ++++-- src/helpers/removeLeadingZeroes.ts | 2 ++ 5 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 src/helpers/removeLeadingZeroes.ts diff --git a/src/app/(sidebar)/transaction/build/components/Params.tsx b/src/app/(sidebar)/transaction/build/components/Params.tsx index 35438bdf..2cfe2acd 100644 --- a/src/app/(sidebar)/transaction/build/components/Params.tsx +++ b/src/app/(sidebar)/transaction/build/components/Params.tsx @@ -19,6 +19,7 @@ import { TimeBoundsPicker } from "@/components/FormElements/TimeBoundsPicker"; import { sanitizeObject } from "@/helpers/sanitizeObject"; import { isEmptyObject } from "@/helpers/isEmptyObject"; +import { removeLeadingZeroes } from "@/helpers/removeLeadingZeroes"; import { TransactionBuildParams } from "@/store/createStore"; import { useStore } from "@/store/useStore"; @@ -335,7 +336,7 @@ export const Params = () => { { const id = "fee"; diff --git a/src/app/(sidebar)/transaction/fee-bump/page.tsx b/src/app/(sidebar)/transaction/fee-bump/page.tsx index 2726a319..c70a73c3 100644 --- a/src/app/(sidebar)/transaction/fee-bump/page.tsx +++ b/src/app/(sidebar)/transaction/fee-bump/page.tsx @@ -12,6 +12,7 @@ import { validate } from "@/validate"; import { sanitizeObject } from "@/helpers/sanitizeObject"; import { txHelper, FeeBumpedTxResponse } from "@/helpers/txHelper"; +import { removeLeadingZeroes } from "@/helpers/removeLeadingZeroes"; import { Box } from "@/components/layout/Box"; import { PositiveIntPicker } from "@/components/FormElements/PositiveIntPicker"; @@ -202,7 +203,7 @@ export default function FeeBumpTransaction() { { const id = "fee"; diff --git a/src/components/formComponentTemplateEndpoints.tsx b/src/components/formComponentTemplateEndpoints.tsx index aaee4c5e..44aa1495 100644 --- a/src/components/formComponentTemplateEndpoints.tsx +++ b/src/components/formComponentTemplateEndpoints.tsx @@ -17,6 +17,8 @@ import { MultiLedgerEntriesPicker } from "@/components/FormElements/XdrLedgerKey import { ConfigSettingIdPicker } from "@/components/FormElements/ConfigSettingIdPicker"; import { parseJsonString } from "@/helpers/parseJsonString"; +import { removeLeadingZeroes } from "@/helpers/removeLeadingZeroes"; + import { validate } from "@/validate"; import { AnyObject, @@ -349,7 +351,7 @@ export const formComponentTemplateEndpoints = ( id={id} label="Destination Amount" labelSuffix={!templ.isRequired ? "optional" : undefined} - value={templ.value || ""} + value={templ.value ? removeLeadingZeroes(templ.value) : ""} error={templ.error} onChange={templ.onChange} /> @@ -698,7 +700,7 @@ export const formComponentTemplateEndpoints = ( id={id} label="Source Amount" labelSuffix={!templ.isRequired ? "optional" : undefined} - value={templ.value || ""} + value={templ.value ? removeLeadingZeroes(templ.value) : ""} error={templ.error} onChange={templ.onChange} /> @@ -761,7 +763,7 @@ export const formComponentTemplateEndpoints = ( id={id} label="Starting Balance" labelSuffix={!templ.isRequired ? "optional" : undefined} - value={templ.value || ""} + value={templ.value ? removeLeadingZeroes(templ.value) : ""} error={templ.error} onChange={templ.onChange} /> diff --git a/src/components/formComponentTemplateTxnOps.tsx b/src/components/formComponentTemplateTxnOps.tsx index 8dff0251..f3c48c8f 100644 --- a/src/components/formComponentTemplateTxnOps.tsx +++ b/src/components/formComponentTemplateTxnOps.tsx @@ -15,6 +15,8 @@ import { NumberFractionPicker } from "@/components/FormElements/NumberFractionPi import { RevokeSponsorshipPicker } from "@/components/FormElements/RevokeSponsorshipPicker"; import { ClaimantsPicker } from "@/components/FormElements/ClaimantsPicker"; +import { removeLeadingZeroes } from "@/helpers/removeLeadingZeroes"; + import { validate } from "@/validate"; import { AnyObject, @@ -124,7 +126,7 @@ export const formComponentTemplateTxnOps = ({ id={id} label={custom?.label || "Amount"} labelSuffix={!templ.isRequired ? "optional" : undefined} - value={templ.value || ""} + value={templ.value ? removeLeadingZeroes(templ.value) : ""} error={templ.error} onChange={templ.onChange} note={custom?.note} @@ -641,7 +643,7 @@ export const formComponentTemplateTxnOps = ({ id={id} label="Starting Balance" labelSuffix={!templ.isRequired ? "optional" : undefined} - value={templ.value || ""} + value={templ.value ? removeLeadingZeroes(templ.value) : ""} error={templ.error} onChange={templ.onChange} /> diff --git a/src/helpers/removeLeadingZeroes.ts b/src/helpers/removeLeadingZeroes.ts new file mode 100644 index 00000000..7c2af85d --- /dev/null +++ b/src/helpers/removeLeadingZeroes.ts @@ -0,0 +1,2 @@ +export const removeLeadingZeroes = (numStr: string) => + numStr.replace(/^0+/, "") || "0";