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

Remove leading zeros for inputs with validate.getAmountError #1142

Merged
merged 1 commit into from
Nov 7, 2024
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
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";