diff --git a/components/UI/desktopNav.tsx b/components/UI/desktopNav.tsx index 4b1a47b4..7dadd949 100644 --- a/components/UI/desktopNav.tsx +++ b/components/UI/desktopNav.tsx @@ -60,7 +60,7 @@ const DesktopNav: FunctionComponent = ({ close }) => {
  • Documentation
  • -
  • Term of use
  • +
  • Terms of use
  • = ({

    {identity.domain - ? minifyDomain(identity.domain) + ? advancedMinifyDomain(identity.domain, 14, 18) : `ID: ${identity.id}`}

    {needAutoRenewal?.includes(identity.domain) ? ( diff --git a/tests/utils/stringService.test.js b/tests/utils/stringService.test.js index 9ee45d8c..f1767ce4 100644 --- a/tests/utils/stringService.test.js +++ b/tests/utils/stringService.test.js @@ -34,6 +34,7 @@ import { generateSuggestedNames, generateSuggestedDomains, getEnsFromStark, + advancedMinifyDomain, } from "../../utils/stringService"; describe("Should test is1234Domain", () => { @@ -417,6 +418,32 @@ describe("Should test shortenDomain function", () => { }); }); +describe("Should test advancedMinifyDomain function", () => { + it("Should return the same domain if the length is less than the default characterToBreak", () => { + expect(advancedMinifyDomain("example.com")).toEqual("example.com"); + }); + + it("Should return the shortened domain if the length is greater than the default characterToBreak", () => { + expect( + advancedMinifyDomain("averylongdomainnametoshorten.com", 10, 13) + ).toEqual("averylongd..."); + }); + + it("Should return the same domain if the length is less than the custom characterToBreak", () => { + expect(advancedMinifyDomain("example.com", 10, 15)).toEqual("example.com"); + }); + + it("Should return the shortened domain if the length is greater than the custom characterToBreak", () => { + expect( + advancedMinifyDomain("averylongdomainnametoshorten.com", 10, 15) + ).toEqual("averylongd..."); + }); + + it("Should return an empty string if the domain is undefined", () => { + expect(advancedMinifyDomain(undefined)).toEqual(""); + }); +}); + describe("cleanUsername function", () => { it("should remove @ symbol if it exists in the username", () => { const username = "@john"; diff --git a/utils/stringService.ts b/utils/stringService.ts index 84471073..0046d5b5 100644 --- a/utils/stringService.ts +++ b/utils/stringService.ts @@ -29,6 +29,22 @@ export function shortenDomain( } } +export function advancedMinifyDomain( + domain?: string, + firstPartMaxLength?: number, + characterToBreak?: number +): string { + if (!domain) return ""; + + if (domain.length > (characterToBreak ?? 20)) { + const firstPart = domain.substring(0, firstPartMaxLength ?? 10); + + return (firstPart + "...").toLowerCase(); + } else { + return domain.toLowerCase(); + } +} + export function minifyDomain( domain: string, characterToBreak?: number