diff --git a/.changeset/rotten-lamps-care.md b/.changeset/rotten-lamps-care.md new file mode 100644 index 000000000000..0cb7589d04ce --- /dev/null +++ b/.changeset/rotten-lamps-care.md @@ -0,0 +1,5 @@ +--- +"ledger-live-desktop": patch +--- + +Fix split address that didn't take in consideration special characters (cf Hedera) diff --git a/apps/ledger-live-desktop/src/renderer/components/OperationsList/AddressCell.tsx b/apps/ledger-live-desktop/src/renderer/components/OperationsList/AddressCell.tsx index 836d809ef563..6b7fee9cd2de 100644 --- a/apps/ledger-live-desktop/src/renderer/components/OperationsList/AddressCell.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/OperationsList/AddressCell.tsx @@ -3,6 +3,20 @@ import styled from "styled-components"; import { Operation } from "@ledgerhq/types-live"; import Box from "~/renderer/components/Box"; +export const splitAddress = (value: string): { left: string; right: string } => { + let left, right; + if (value.includes(".")) { + const parts = value.split("."); + left = parts[0] + "."; + right = parts.slice(1).join("."); + } else { + const third = Math.round(value.length / 3); + left = value.slice(0, third); + right = value.slice(third, value.length); + } + return { left, right }; +}; + export const SplitAddress = ({ value, color, @@ -22,11 +36,9 @@ export const SplitAddress = ({ ff, fontSize, }; - const third = Math.round(value.length / 3); - // FIXME why not using CSS for this? meaning we might be able to have a left & right which both take 50% & play with overflow & text-align - const left = value.slice(0, third); - const right = value.slice(third, value.length); + const { left, right } = splitAddress(value); + return ( {left} diff --git a/apps/ledger-live-desktop/src/renderer/components/OperationsList/tests/splitAddress.test.ts b/apps/ledger-live-desktop/src/renderer/components/OperationsList/tests/splitAddress.test.ts new file mode 100644 index 000000000000..accb89444624 --- /dev/null +++ b/apps/ledger-live-desktop/src/renderer/components/OperationsList/tests/splitAddress.test.ts @@ -0,0 +1,38 @@ +import { splitAddress } from "../AddressCell"; + +describe("splitAddress", () => { + it("should split address with a dot correctly", () => { + const result = splitAddress("0.0.931774"); + expect(result).toEqual({ left: "0.", right: "0.931774" }); + }); + + it("should split address with a special character and a dot correctly", () => { + const result = splitAddress("abc.def-ghi"); + expect(result).toEqual({ left: "abc.", right: "def-ghi" }); + }); + + it("should split address with a special characters", () => { + const result = splitAddress("abc-def-ghi"); + expect(result).toEqual({ left: "abc-", right: "def-ghi" }); + }); + + it("should split address without a dot correctly", () => { + const result = splitAddress("abcdefghi"); + expect(result).toEqual({ left: "abc", right: "defghi" }); + }); + + it("should handle empty string", () => { + const result = splitAddress(""); + expect(result).toEqual({ left: "", right: "" }); + }); + + it("should handle string with one character", () => { + const result = splitAddress("a"); + expect(result).toEqual({ left: "", right: "a" }); + }); + + it("should handle string with two characters", () => { + const result = splitAddress("ab"); + expect(result).toEqual({ left: "a", right: "b" }); + }); +});