From ed9d45ffac1c7b6fd64205be7aa9902839713a39 Mon Sep 17 00:00:00 2001 From: Iris Date: Mon, 16 Oct 2023 14:15:45 +0200 Subject: [PATCH] ref: add useCreationDate hook --- hooks/useExpiryDate.ts | 35 +++++++++++++++++++++++++++++++++++ pages/[addressOrDomain].tsx | 32 +++----------------------------- public/starknet/favicon.ico | Bin 4286 -> 4286 bytes 3 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 hooks/useExpiryDate.ts diff --git a/hooks/useExpiryDate.ts b/hooks/useExpiryDate.ts new file mode 100644 index 00000000..a0d4e6f5 --- /dev/null +++ b/hooks/useExpiryDate.ts @@ -0,0 +1,35 @@ +import { useEffect, useState } from "react"; +import { memberSince } from "../utils/profile"; + +export default function useExpiryDate(identity: Identity | undefined) { + const [sinceDate, setSinceDate] = useState(null); + + useEffect(() => { + if (!identity || !identity.addr) return; + fetch( + `https://${ + process.env.NEXT_PUBLIC_IS_TESTNET === "true" ? "api-testnet" : "api" + }.starkscan.co/api/v0/transactions?from_block=1&limit=1&order_by=asc&contract_address=${ + identity.addr + }`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + "x-api-key": `${process.env.NEXT_PUBLIC_STARKSCAN}`, + }, + } + ) + .then((res) => res.json()) + .then((data) => { + if (data.data[0].timestamp) { + const sinceData = memberSince(data.data[0].timestamp); + setSinceDate(sinceData); + } else { + setSinceDate(null); + } + }); + }, [identity]); + + return sinceDate; +} diff --git a/pages/[addressOrDomain].tsx b/pages/[addressOrDomain].tsx index 7b9472f7..fc61e1ab 100644 --- a/pages/[addressOrDomain].tsx +++ b/pages/[addressOrDomain].tsx @@ -13,10 +13,11 @@ import { utils } from "starknetid.js"; import ErrorScreen from "../components/UI/screens/errorScreen"; import ProfileCard from "../components/UI/profileCard"; import { Land } from "../components/lands/land"; -import { hasVerifiedSocials, memberSince } from "../utils/profile"; +import { hasVerifiedSocials } from "../utils/profile"; import { useMediaQuery } from "@mui/material"; import VerifiedIcon from "../components/UI/iconsComponents/icons/verifiedIcon"; import CopyIcon from "../components/UI/iconsComponents/icons/copyIcon"; +import useExpiryDate from "../hooks/useExpiryDate"; const AddressOrDomain: NextPage = () => { const router = useRouter(); @@ -31,10 +32,10 @@ const AddressOrDomain: NextPage = () => { const [isOwner, setIsOwner] = useState(false); const dynamicRoute = useRouter().asPath; const isMobile = useMediaQuery("(max-width:768px)"); - const [sinceDate, setSinceDate] = useState(null); const [achievements, setAchievements] = useState([]); const [soloBuildings, setSoloBuildings] = useState([]); const [selectedTab, setSelectedTab] = useState("nfts"); + const sinceDate = useExpiryDate(identity); useEffect(() => setNotFound(false), [dynamicRoute]); @@ -193,33 +194,6 @@ const AddressOrDomain: NextPage = () => { } }, [addressOrDomain, address, dynamicRoute]); - useEffect(() => { - if (!identity || !identity.addr) return; - fetch( - `https://${ - process.env.NEXT_PUBLIC_IS_TESTNET === "true" ? "api-testnet" : "api" - }.starkscan.co/api/v0/transactions?from_block=1&limit=1&order_by=asc&contract_address=${ - identity.addr - }`, - { - method: "GET", - headers: { - "Content-Type": "application/json", - "x-api-key": `${process.env.NEXT_PUBLIC_STARKSCAN}`, - }, - } - ) - .then((res) => res.json()) - .then((data) => { - if (data.data[0].timestamp) { - const sinceData = memberSince(data.data[0].timestamp); - setSinceDate(sinceData); - } else { - setSinceDate(null); - } - }); - }, [identity]); - const copyToClipboard = () => { setCopied(true); navigator.clipboard.writeText(identity?.addr as string); diff --git a/public/starknet/favicon.ico b/public/starknet/favicon.ico index e0d6c00c0a17a47cab15cc452d3927e6f0f8ca35..d3e7e9a95e462e5bc189ad755db5dc0af20eb7f3 100644 GIT binary patch literal 4286 zcmc&&3rv;g8U8x0L-9sIYr$!E$yDm*;yRrj#x`S1trgC(0>=WS>*ny)#>>xk{*QCEvxzhIZ(|oqu}kph{oG zWcQBX5?7Vq?z23Zfh6Y(R~qsi2ihIWGGLFNkM!7SNS`(} z^f^5i>C>l&x125C+2fPo_)aDYHXXPoGU`3s1Bq^t=@HqtTSnz|nKU`Gs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