Skip to content

Commit

Permalink
fix: minify domain
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Jul 18, 2024
1 parent f451808 commit f54173c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/components/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React, { FunctionComponent, useEffect, useState } from "react";
import styles from "../styles/components/stats.module.css";
import { ethers } from "ethers";
import { minifyAddress } from "@/utils/stringService";
import { minifyAddress, shortenDomain } from "@/utils/stringService";
import { StarknetIdNavigator } from "starknetid.js";

type StatsProps = {
Expand Down Expand Up @@ -47,7 +47,7 @@ const Stats: FunctionComponent<StatsProps> = ({
return fetch(`https://enstate.rs/n/${addr}`)
.then((res) => res.json())
.then((data) => {
if (data.name) return data.name;
if (data.name) return shortenDomain(data.name);
else return minifyAddress(addr, true);
})
.catch(() => {
Expand All @@ -58,7 +58,7 @@ const Stats: FunctionComponent<StatsProps> = ({
return starknetIdNavigator
.getStarkName(addr)
.then((name) => {
if (name) return name;
if (name) return shortenDomain(name);
else return minifyAddress(addr, true);
})
.catch(() => {
Expand Down
16 changes: 16 additions & 0 deletions utils/stringService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ export function minifyAddress(
return (firstPart + "..." + secondPart).toLowerCase();
}

export function shortenDomain(
domain?: string,
characterToBreak?: number
): string {
if (!domain) return "";

if (domain.length > (characterToBreak ?? 20)) {
const firstPart = domain.substring(0, 5);
const secondPart = domain.substring(domain.length - 6, domain.length);

return (firstPart + "..." + secondPart).toLowerCase();
} else {
return domain.toLowerCase();
}
}

export function numberToWords(num: number): string {
const numWords = [
"ZERO",
Expand Down

0 comments on commit f54173c

Please sign in to comment.