Skip to content

Commit

Permalink
🐛(lld) hedera split address (#8381)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasWerey authored Dec 23, 2024
1 parent 46940f0 commit 80f5a8f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-lamps-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

Fix split address that didn't take in consideration special characters (cf Hedera)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
<Box horizontal {...boxProps}>
<Left>{left}</Left>
Expand Down
Original file line number Diff line number Diff line change
@@ -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" });
});
});

0 comments on commit 80f5a8f

Please sign in to comment.