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

πŸ›(lld) hedera split address #8381

Merged
merged 1 commit into from
Dec 23, 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
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" });
});
});
Loading