diff --git a/lib/utils.ts b/lib/utils.ts new file mode 100644 index 00000000..4a72ff5b --- /dev/null +++ b/lib/utils.ts @@ -0,0 +1,3 @@ +export function truncateAddress(address: string): string { + return `${address.slice(0, 6)}...${address.slice(-4)}`; +} diff --git a/src/app/story/[storylineId]/page.tsx b/src/app/story/[storylineId]/page.tsx index e6060da7..92c394b4 100644 --- a/src/app/story/[storylineId]/page.tsx +++ b/src/app/story/[storylineId]/page.tsx @@ -8,13 +8,10 @@ import { RatingSummary } from "../../../components/RatingSummary"; import { getTokenPrice, type TokenPriceInfo } from "../../../../lib/price"; import { IS_TESTNET } from "../../../../lib/contracts/constants"; import { type Address } from "viem"; +import { truncateAddress } from "../../../../lib/utils"; type Params = Promise<{ storylineId: string }>; -function truncateAddress(address: string): string { - return `${address.slice(0, 6)}...${address.slice(-4)}`; -} - export default async function StoryPage({ params }: { params: Params }) { const { storylineId } = await params; const id = Number(storylineId); diff --git a/src/components/ConnectWallet.tsx b/src/components/ConnectWallet.tsx index d122e07d..c8b53100 100644 --- a/src/components/ConnectWallet.tsx +++ b/src/components/ConnectWallet.tsx @@ -2,10 +2,7 @@ import { useAccount, useConnect, useDisconnect } from "wagmi"; import { injected } from "wagmi/connectors"; - -function truncateAddress(address: string): string { - return `${address.slice(0, 6)}...${address.slice(-4)}`; -} +import { truncateAddress } from "../../lib/utils"; export function ConnectWallet() { const { address, isConnected } = useAccount(); diff --git a/src/components/RatingWidget.tsx b/src/components/RatingWidget.tsx index 72cdca1d..4d1e3f48 100644 --- a/src/components/RatingWidget.tsx +++ b/src/components/RatingWidget.tsx @@ -6,6 +6,7 @@ import { useQuery } from "@tanstack/react-query"; import { publicClient } from "../../lib/rpc"; import { erc20Abi } from "../../lib/price"; import type { Address } from "viem"; +import { truncateAddress } from "../../lib/utils"; interface RatingData { id: number; @@ -29,10 +30,6 @@ interface RatingWidgetProps { tokenAddress: string; } -function truncateAddress(address: string): string { - return `${address.slice(0, 6)}...${address.slice(-4)}`; -} - function StarDisplay({ rating, size = "sm" }: { rating: number; size?: "sm" | "lg" }) { const sizeClass = size === "lg" ? "text-base" : "text-xs"; return ( diff --git a/src/components/StoryCard.tsx b/src/components/StoryCard.tsx index ef18a37f..3566e354 100644 --- a/src/components/StoryCard.tsx +++ b/src/components/StoryCard.tsx @@ -1,9 +1,6 @@ import Link from "next/link"; import type { Storyline } from "../../lib/supabase"; - -function truncateAddress(address: string): string { - return `${address.slice(0, 6)}...${address.slice(-4)}`; -} +import { truncateAddress } from "../../lib/utils"; export function StoryCard({ storyline,