Skip to content

Commit

Permalink
remove leadingZeros for <PositiveIntPicker/> and validate.getAmountEr…
Browse files Browse the repository at this point in the history
…ror (#1142)
  • Loading branch information
jeesunikim authored Nov 7, 2024
1 parent 46ccc52 commit fbd718d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/app/(sidebar)/transaction/build/components/Params.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -335,7 +336,7 @@ export const Params = () => {
<PositiveIntPicker
id="fee"
label="Base Fee"
value={txnParams.fee}
value={removeLeadingZeroes(txnParams.fee)}
error={paramsError.fee}
onChange={(e) => {
const id = "fee";
Expand Down
3 changes: 2 additions & 1 deletion src/app/(sidebar)/transaction/fee-bump/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -202,7 +203,7 @@ export default function FeeBumpTransaction() {
<PositiveIntPicker
id="fee"
label="Base Fee"
value={fee}
value={removeLeadingZeroes(fee)}
error={paramsError.fee}
onChange={(e) => {
const id = "fee";
Expand Down
8 changes: 5 additions & 3 deletions src/components/formComponentTemplateEndpoints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
/>
Expand Down Expand Up @@ -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}
/>
Expand Down Expand Up @@ -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}
/>
Expand Down
6 changes: 4 additions & 2 deletions src/components/formComponentTemplateTxnOps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
/>
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/removeLeadingZeroes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const removeLeadingZeroes = (numStr: string) =>
numStr.replace(/^0+/, "") || "0";

0 comments on commit fbd718d

Please sign in to comment.