From 7c73f75f5ddc94ed67100731af6a998fa198b2ce Mon Sep 17 00:00:00 2001 From: pedromcunha Date: Wed, 11 Dec 2024 16:37:04 -0500 Subject: [PATCH 1/2] Omit trailing zeros from formatted input amount --- packages/ui/src/utils/numbers.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/utils/numbers.ts b/packages/ui/src/utils/numbers.ts index 7ad1602a..501f67ac 100644 --- a/packages/ui/src/utils/numbers.ts +++ b/packages/ui/src/utils/numbers.ts @@ -179,6 +179,7 @@ function truncateBalance(balance: string) { * @param maxLength The maximum total length of the string representation. * @returns A plain string representation of the number, trimmed to the specified length. */ + function formatFixedLength(amount: string, maxLength: number) { if (!/^[-+]?\d*\.?\d*$/.test(amount)) return 'Invalid number' @@ -203,7 +204,10 @@ function formatFixedLength(amount: string, maxLength: number) { } // Ensure no unnecessary trailing zeros and remove any trailing decimal points - result = result.replace(/\.0+$/, '').replace(/\.$/, '') + result = result + .replace(/\.0+$/, '') + .replace(/\.(\d*[^0])0+$/, '.$1') + .replace(/\.$/, '') // Add negative sign back if the number was negative if (isNegative) { From aa034bd4ad52bda23283f35b1de3c2e4f5e150b0 Mon Sep 17 00:00:00 2001 From: pedromcunha Date: Wed, 11 Dec 2024 16:37:38 -0500 Subject: [PATCH 2/2] feat: changeset --- .changeset/heavy-carrots-promise.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/heavy-carrots-promise.md diff --git a/.changeset/heavy-carrots-promise.md b/.changeset/heavy-carrots-promise.md new file mode 100644 index 00000000..a2fad1f3 --- /dev/null +++ b/.changeset/heavy-carrots-promise.md @@ -0,0 +1,5 @@ +--- +'@reservoir0x/relay-kit-ui': patch +--- + +Remove trailing zeros from formatted amount