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

fix: small UI issues #890

Merged
merged 2 commits into from
Sep 26, 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
2 changes: 1 addition & 1 deletion components/UI/desktopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const DesktopNav: FunctionComponent<DesktopNavProps> = ({ close }) => {
<li className={styles.burgerItem}>Documentation</li>
</Link>
<Link href="https://www.starknet.id/pdfs/Terms.pdf" target="_blank">
<li className={styles.burgerItem}>Term of use</li>
<li className={styles.burgerItem}>Terms of use</li>
</Link>
<Link
href="https://starknet.id/pdfs/PrivacyPolicy.pdf"
Expand Down
8 changes: 6 additions & 2 deletions components/identities/identitiesGalleryV1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import React, {
} from "react";
import { useRouter } from "next/router";
import styles from "../../styles/components/identitiesV1.module.css";
import { getDomainKind, minifyDomain } from "../../utils/stringService";
import {
advancedMinifyDomain,
getDomainKind,
minifyDomain,
} from "../../utils/stringService";
import ErrorIcon from "@mui/icons-material/Error";
import { Tooltip } from "@mui/material";
import {
Expand Down Expand Up @@ -82,7 +86,7 @@ const IdentitiesGalleryV1: FunctionComponent<IdentitiesGalleryV1Props> = ({
<div className={styles.identityInfo}>
<p className="font-bold font-quickZap">
{identity.domain
? minifyDomain(identity.domain)
? advancedMinifyDomain(identity.domain, 14, 18)
: `ID: ${identity.id}`}
</p>
{needAutoRenewal?.includes(identity.domain) ? (
Expand Down
27 changes: 27 additions & 0 deletions tests/utils/stringService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
generateSuggestedNames,
generateSuggestedDomains,
getEnsFromStark,
advancedMinifyDomain,
} from "../../utils/stringService";

describe("Should test is1234Domain", () => {
Expand Down Expand Up @@ -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("");
});
});
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved

describe("cleanUsername function", () => {
it("should remove @ symbol if it exists in the username", () => {
const username = "@john";
Expand Down
16 changes: 16 additions & 0 deletions utils/stringService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved

export function minifyDomain(
domain: string,
characterToBreak?: number
Expand Down