Skip to content

Commit

Permalink
ref: add useCreationDate hook
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Oct 16, 2023
1 parent cce8c8a commit ed9d45f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
35 changes: 35 additions & 0 deletions hooks/useExpiryDate.ts
Original file line number Diff line number Diff line change
@@ -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<string | null>(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;
}
32 changes: 3 additions & 29 deletions pages/[addressOrDomain].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<string | null>(null);
const [achievements, setAchievements] = useState<BuildingsInfo[]>([]);
const [soloBuildings, setSoloBuildings] = useState<BuildingsInfo[]>([]);
const [selectedTab, setSelectedTab] = useState<LandTabs>("nfts");
const sinceDate = useExpiryDate(identity);

useEffect(() => setNotFound(false), [dynamicRoute]);

Expand Down Expand Up @@ -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);
Expand Down
Binary file modified public/starknet/favicon.ico
Binary file not shown.

0 comments on commit ed9d45f

Please sign in to comment.