diff --git a/components/UI/actions/clickable/clickableDiscordIcon.tsx b/components/UI/actions/clickable/clickableDiscordIcon.tsx index b86ce761..b0b540c3 100644 --- a/components/UI/actions/clickable/clickableDiscordIcon.tsx +++ b/components/UI/actions/clickable/clickableDiscordIcon.tsx @@ -1,97 +1,34 @@ import { Tooltip } from "@mui/material"; -import { useRouter } from "next/router"; -import React, { - FunctionComponent, - useContext, - useEffect, - useState, -} from "react"; +import React, { FunctionComponent } from "react"; import DiscordIcon from "../../../UI/iconsComponents/icons/discordIcon"; import styles from "../../../../styles/components/icons.module.css"; import { minifyDomain } from "../../../../utils/stringService"; import VerifiedIcon from "../../../UI/iconsComponents/icons/verifiedIcon"; -import { StarknetIdJsContext } from "../../../../context/StarknetIdJsProvider"; +import theme from "../../../../styles/theme"; type ClickableDiscordIconProps = { width: string; - tokenId: string; - isOwner: boolean; - domain: string; + discordId?: string; + domain?: string; }; const ClickableDiscordIcon: FunctionComponent = ({ width, - tokenId, - isOwner, domain, + discordId, }) => { - const router = useRouter(); - const [discordId, setDiscordId] = useState(); - const { starknetIdNavigator } = useContext(StarknetIdJsContext); - - useEffect(() => { - starknetIdNavigator - ?.getVerifierData(tokenId, "discord") - .then((response) => { - if (response.toString(10) !== "0") { - setDiscordId(response.toString(10)); - } else { - setDiscordId(undefined); - } - }) - .catch(() => { - return; - }); - }, [starknetIdNavigator, tokenId]); - - function startVerification(link: string): void { - sessionStorage.setItem("tokenId", tokenId); - router.push(link); - } - - return isOwner ? ( -
- -
- startVerification( - `${process.env.NEXT_PUBLIC_STARKNETID_APP_LINK}/identities` - ) - } - > - {discordId ? ( -
- -
- ) : null} - -
-
-
- ) : discordId ? ( -
- -
- window.open(`https://discord.com/channels/@me/${discordId}`) - } - > -
- -
- + return discordId ? ( + +
+
+
- -
+ +
+
) : null; }; diff --git a/components/UI/actions/clickable/clickableGithubIcon.tsx b/components/UI/actions/clickable/clickableGithubIcon.tsx index 192f2d34..713a4d97 100644 --- a/components/UI/actions/clickable/clickableGithubIcon.tsx +++ b/components/UI/actions/clickable/clickableGithubIcon.tsx @@ -1,50 +1,23 @@ import { Tooltip } from "@mui/material"; -import { useRouter } from "next/router"; -import React, { - FunctionComponent, - useContext, - useEffect, - useState, -} from "react"; +import React, { FunctionComponent, useEffect, useState } from "react"; import GithubIcon from "../../../UI/iconsComponents/icons/githubIcon"; import styles from "../../../../styles/components/icons.module.css"; import { minifyDomain } from "../../../../utils/stringService"; import VerifiedIcon from "../../../UI/iconsComponents/icons/verifiedIcon"; -import { StarknetIdJsContext } from "../../../../context/StarknetIdJsProvider"; +import theme from "../../../../styles/theme"; type ClickableGithubIconProps = { width: string; - tokenId: string; - isOwner: boolean; - domain: string; + githubId?: string; + domain?: string; }; const ClickableGithubIcon: FunctionComponent = ({ width, - tokenId, - isOwner, + githubId, domain, }) => { - const router = useRouter(); - const [githubId, setGithubId] = useState(); const [githubUsername, setGithubUsername] = useState(); - const { starknetIdNavigator } = useContext(StarknetIdJsContext); - - useEffect(() => { - starknetIdNavigator - ?.getVerifierData(tokenId, "github") - .then((response) => { - if (response.toString(10) !== "0") { - setGithubId(response.toString(10)); - } else { - setGithubId(undefined); - setGithubUsername(undefined); - } - }) - .catch(() => { - return; - }); - }, [tokenId, domain]); useEffect(() => { if (githubId) { @@ -57,52 +30,18 @@ const ClickableGithubIcon: FunctionComponent = ({ } }, [githubId]); - function startVerification(link: string): void { - sessionStorage.setItem("tokenId", tokenId); - router.push(link); - } - - return isOwner ? ( -
- +
window.open(`https://github.com/${githubUsername}`)} > -
- startVerification( - `${process.env.NEXT_PUBLIC_STARKNETID_APP_LINK}/identities` - ) - } - > - {githubUsername ? ( -
- -
- ) : null} - -
- -
- ) : githubUsername ? ( -
- -
window.open(`https://github.com/${githubUsername}`)} - > -
- -
- +
+
- -
+ +
+
) : null; }; diff --git a/components/UI/actions/clickable/clickableTwitterIcon.tsx b/components/UI/actions/clickable/clickableTwitterIcon.tsx index 05c90e36..a5fc573a 100644 --- a/components/UI/actions/clickable/clickableTwitterIcon.tsx +++ b/components/UI/actions/clickable/clickableTwitterIcon.tsx @@ -1,80 +1,30 @@ import { Tooltip } from "@mui/material"; -import { useRouter } from "next/router"; -import React, { - FunctionComponent, - useContext, - useEffect, - useState, -} from "react"; +import React, { FunctionComponent } from "react"; import TwitterIcon from "../../../UI/iconsComponents/icons/twitterIcon"; import VerifiedIcon from "../../../UI/iconsComponents/icons/verifiedIcon"; import styles from "../../../../styles/components/icons.module.css"; -import { StarknetIdJsContext } from "../../../../context/StarknetIdJsProvider"; +import theme from "../../../../styles/theme"; type ClickableTwitterIconProps = { width: string; - tokenId: string; - isOwner: boolean; - domain: string; + twitterId?: string; + domain?: string; }; const ClickableTwitterIcon: FunctionComponent = ({ width, - tokenId, - isOwner, + twitterId, domain, }) => { - const router = useRouter(); - const [twitterId, setTwitterId] = useState(); - const { starknetIdNavigator } = useContext(StarknetIdJsContext); - - useEffect(() => { - starknetIdNavigator - ?.getVerifierData(tokenId, "twitter") - .then((response) => { - if (response.toString(10) !== "0") { - setTwitterId(response.toString(10)); - } else { - setTwitterId(undefined); - } - }) - .catch(() => { - return; - }); - }, [tokenId, domain]); - - function startVerification(link: string): void { - sessionStorage.setItem("tokenId", tokenId); - router.push(link); - } - - return isOwner ? ( -
- -
- startVerification( - `${process.env.NEXT_PUBLIC_STARKNETID_APP_LINK}/identities` - ) - } - > - {twitterId ? ( -
- -
- ) : null} - + return twitterId ? ( + +
+
+
- -
+ +
+
) : null; }; diff --git a/components/UI/actions/socialmediaActions.tsx b/components/UI/actions/socialmediaActions.tsx index 85688ded..3de23518 100644 --- a/components/UI/actions/socialmediaActions.tsx +++ b/components/UI/actions/socialmediaActions.tsx @@ -1,32 +1,55 @@ -import React, { FunctionComponent } from "react"; +import React, { FunctionComponent, useEffect, useState } from "react"; import ClickableDiscordIcon from "./clickable/clickableDiscordIcon"; import ClickableGithubIcon from "./clickable/clickableGithubIcon"; import ClickableTwitterIcon from "./clickable/clickableTwitterIcon"; +import { isStarkRootDomain } from "starknetid.js/packages/core/dist/utils"; -const SocialMediaActions: FunctionComponent = ({ - tokenId, - isOwner, - domain = "", +type SocialMediaActionsProps = { + identity: Identity; +}; + +const SocialMediaActions: FunctionComponent = ({ + identity, }) => { + const [apiIdentity, setApiIdentity] = useState(); + + useEffect(() => { + if (isStarkRootDomain(identity?.domain ?? "")) { + const refreshData = () => + fetch( + `${process.env.NEXT_PUBLIC_STARKNET_ID_API_LINK}/domain_to_data?domain=${identity.domain}` + ) + .then(async (response) => { + if (!response.ok) { + throw new Error(await response.text()); + } + return response.json(); + }) + .then((data: Identity) => { + setApiIdentity(data); + }); + refreshData(); + const timer = setInterval(() => refreshData(), 30e3); + return () => clearInterval(timer); + } + }, [identity]); + return (
); diff --git a/components/UI/iconsComponents/icons/verifiedIcon.tsx b/components/UI/iconsComponents/icons/verifiedIcon.tsx index 81ce95d4..3f8d8415 100644 --- a/components/UI/iconsComponents/icons/verifiedIcon.tsx +++ b/components/UI/iconsComponents/icons/verifiedIcon.tsx @@ -28,7 +28,7 @@ const verifiedIcon: FunctionComponent = ({ width, color }) => { /> = ({
{connector && connector.id === "braavos" ? ( braavos logo diff --git a/pages/[addressOrDomain].tsx b/pages/[addressOrDomain].tsx index 5e013697..f4b5f350 100644 --- a/pages/[addressOrDomain].tsx +++ b/pages/[addressOrDomain].tsx @@ -105,7 +105,7 @@ const AddressOrDomain: NextPage = () => { } setIdentity({ ...data, - id: id.toString(), + starknet_id: id.toString(), }); if (hexToDecimal(address) === data.addr) setIsOwner(true); setInitProfile(true); @@ -119,7 +119,7 @@ const AddressOrDomain: NextPage = () => { ?.getAddressFromStarkName(addressOrDomain) .then((addr) => { setIdentity({ - id: "0", + starknet_id: "0", addr: hexToDecimal(addr), domain: addressOrDomain, is_owner_main: false, @@ -150,7 +150,7 @@ const AddressOrDomain: NextPage = () => { if (data.error) return; setIdentity({ ...data, - id: id.toString(), + starknet_id: id.toString(), }); if (hexToDecimal(address) === data.addr) setIsOwner(true); setInitProfile(true); @@ -161,7 +161,7 @@ const AddressOrDomain: NextPage = () => { }); } else { setIdentity({ - id: "0", + starknet_id: "0", addr: hexToDecimal(addressOrDomain), domain: name, is_owner_main: false, @@ -172,7 +172,7 @@ const AddressOrDomain: NextPage = () => { } } else { setIdentity({ - id: "0", + starknet_id: "0", addr: hexToDecimal(addressOrDomain), domain: minifyAddress(addressOrDomain), is_owner_main: false, @@ -310,7 +310,7 @@ const AddressOrDomain: NextPage = () => {
starknet.id avatar @@ -351,11 +351,7 @@ const AddressOrDomain: NextPage = () => {
- +
diff --git a/styles/components/icons.module.css b/styles/components/icons.module.css index 54542d9f..e2ea7578 100644 --- a/styles/components/icons.module.css +++ b/styles/components/icons.module.css @@ -27,7 +27,6 @@ background-color: #55acee; border-radius: 25%; padding: 0.5rem; - cursor: pointer; position: relative; } @@ -39,11 +38,13 @@ .clickableIconGithub { background-color: #24292e; + cursor: pointer; } .clickableIconDiscord { background-color: #7289d9; } + .button_icon { width: 24px; margin-right: 12px; diff --git a/types/frontTypes.d.ts b/types/frontTypes.d.ts index 337b1bbe..a2acdaf7 100644 --- a/types/frontTypes.d.ts +++ b/types/frontTypes.d.ts @@ -64,10 +64,15 @@ type Reward = { }; type Identity = { - id: string; addr: string; - domain: string; - is_owner_main: boolean; + domain?: string; + domain_expiry?: number | null; + is_owner_main?: boolean; + owner_addr?: string; + old_discord?: string; + old_twitter?: string; + old_github?: string; + starknet_id?: string; error?: string; }; @@ -77,12 +82,6 @@ type NftCard = { url: string; }; -type SocialMediaActions = { - tokenId: string; - isOwner: boolean; - domain?: string; -}; - type StarkscanNftProps = { animation_url: string | null; attributes: Attribute[];