Skip to content

Commit

Permalink
making requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchand-Nicolas committed Sep 30, 2023
1 parent 3a4d1a7 commit 7e7b298
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 63 deletions.
10 changes: 6 additions & 4 deletions components/UI/menus/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type PopupProps = {
description: string;
buttonName: string;
onClick: () => void;
onClose: () => void;
onClose?: () => void;
};

const Popup: FunctionComponent<PopupProps> = ({
Expand All @@ -33,9 +33,11 @@ const Popup: FunctionComponent<PopupProps> = ({
<Button onClick={onClick}>{buttonName}</Button>
</div>
</div>
<button onClick={onClose} className={styles.close}>
<CloseIcon width="16" />
</button>
{onClose && (
<button onClick={onClose} className={styles.close}>
<CloseIcon width="16" />
</button>
)}
</div>
</div>
);
Expand Down
19 changes: 0 additions & 19 deletions components/UI/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import { useRouter } from "next/router";
import theme from "../../styles/theme";
import { FaDiscord, FaTwitter } from "react-icons/fa";
import useHasDomain from "../../hooks/useHasDomain";
import Popup from "./menus/popup";

const Navbar: FunctionComponent = () => {
const [nav, setNav] = useState<boolean>(false);
Expand All @@ -48,13 +46,6 @@ const Navbar: FunctionComponent = () => {
const { hashes } = useTransactionManager();
const [showWallet, setShowWallet] = useState<boolean>(false);
const router = useRouter();
const hasDomain = useHasDomain(address);
const [showDomainPopup, setShowDomainPopup] = useState<boolean>(false);

useEffect(() => {
if (!address) return;
setShowDomainPopup(!hasDomain);
}, [address, hasDomain]);

useEffect(() => {
// to handle autoconnect starknet-react adds connector id in local storage
Expand Down Expand Up @@ -162,16 +153,6 @@ const Navbar: FunctionComponent = () => {
return (
<>
<div className={`fixed w-full z-[1]`} id="nav">
{showDomainPopup && (
<Popup
title="Mandatory Starknet Domain"
banner="/visuals/profile.webp"
description="To access Starknet Quest, you must own a Starknet domain. It's your passport to the Starknet ecosystem. Get yours now."
buttonName="Get a Starknet Domain"
onClick={() => window.open("https://app.starknet.id/")}
onClose={() => setShowDomainPopup(false)}
/>
)}
<div
className={`${styles.navbarContainer} ${
navbarBg ? styles.navbarScrolled : ""
Expand Down
48 changes: 36 additions & 12 deletions components/quests/quest.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { FunctionComponent } from "react";
import React, { FunctionComponent, useEffect, useState } from "react";
import styles from "../../styles/quests.module.css";
import useHasRootDomain from "../../hooks/useHasRootDomain";
import { useAccount } from "@starknet-react/core";
import Popup from "../UI/menus/popup";
import { starknetIdAppLink } from "../../utils/links";

type QuestProps = {
onClick: () => void;
Expand All @@ -16,20 +20,40 @@ const Quest: FunctionComponent<QuestProps> = ({
issuer,
reward,
}) => {
const { address } = useAccount();
const hasRootDomain = useHasRootDomain(address);
const [showDomainPopup, setShowDomainPopup] = useState<boolean>(false);

useEffect(() => {
if (!address) return;
setShowDomainPopup(!hasRootDomain);
}, [address, hasRootDomain]);

return (
<div className={styles.questCard} onClick={onClick}>
<img src={imgSrc} className={styles.questImage} />
<div className={styles.questInfos}>
<h3 className={styles.questTitle}>{title}</h3>
<div className="flex mt-2 mb-1 items-center">
<p className="text-gray-400">{issuer.name}</p>
</div>
<div className="flex mt-2 mb-1 items-center">
<img width={20} src={issuer.logoFavicon} />
<p className="text-white ml-2">{reward}</p>
<>
{showDomainPopup && (
<Popup
title="Mandatory Starknet Domain"
banner="/visuals/profile.webp"
description="To access Starknet Quest, you must own a Starknet domain. It's your passport to the Starknet ecosystem. Get yours now."
buttonName="Get a Starknet Domain"
onClick={() => window.open(starknetIdAppLink)}
/>
)}
<div className={styles.questCard} onClick={onClick}>
<img src={imgSrc} className={styles.questImage} />
<div className={styles.questInfos}>
<h3 className={styles.questTitle}>{title}</h3>
<div className="flex mt-2 mb-1 items-center">
<p className="text-gray-400">{issuer.name}</p>
</div>
<div className="flex mt-2 mb-1 items-center">
<img width={20} src={issuer.logoFavicon} />
<p className="text-white ml-2">{reward}</p>
</div>
</div>
</div>
</div>
</>
);
};

Expand Down
9 changes: 5 additions & 4 deletions components/quests/reward.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { useRouter } from "next/router";
import Lottie from "lottie-react";
import verifiedLottie from "../../public/visuals/verifiedLottie.json";
import { Call } from "starknet";
import useHasDomain from "../../hooks/useHasDomain";
import useHasRootDomain from "../../hooks/useHasRootDomain";
import Popup from "../UI/menus/popup";
import { starknetIdAppLink } from "../../utils/links";

type RewardProps = {
onClick: () => void;
Expand All @@ -35,7 +36,7 @@ const Reward: FunctionComponent<RewardProps> = ({
calls: mintCalldata,
});
const { address } = useAccount();
const hasDomain = useHasDomain(address);
const hasRootDomain = useHasRootDomain(address);
const [showDomainPopup, setShowDomainPopup] = useState<boolean>(false);
const router = useRouter();

Expand All @@ -53,13 +54,13 @@ const Reward: FunctionComponent<RewardProps> = ({

return (
<div className={styles.reward}>
{showDomainPopup && !hasDomain ? (
{showDomainPopup && !hasRootDomain ? (
<Popup
title="Mandatory Starknet Domain"
banner="/visuals/profile.webp"
description="To access Starknet Quest, you must own a Starknet domain. It's your passport to the Starknet ecosystem. Get yours now."
buttonName="Get a Starknet Domain"
onClick={() => window.open("https://app.starknet.id/")}
onClick={() => window.open(starknetIdAppLink)}
onClose={() => setShowDomainPopup(false)}
/>
) : null}
Expand Down
24 changes: 0 additions & 24 deletions hooks/useHasDomain.ts

This file was deleted.

19 changes: 19 additions & 0 deletions hooks/useHasRootDomain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import BN from "bn.js";
import { useContext, useEffect, useState } from "react";
import { StarknetIdJsContext } from "../context/StarknetIdJsProvider";
import { hexToDecimal } from "../utils/feltService";

export default function useHasRootDomain(address: string | BN | undefined) {
const [hasRootDomain, setHasRootDomain] = useState(false);
const { starknetIdNavigator } = useContext(StarknetIdJsContext);
useEffect(() => {
if (!address) return;
fetch(
`${
process.env.NEXT_PUBLIC_STARKNET_ID_API_LINK
}/addr_to_domain?addr=${hexToDecimal(address.toString())}`
).then((res) => res.status === 200 && setHasRootDomain(true));
}, [starknetIdNavigator, address]);

return hasRootDomain;
}
3 changes: 3 additions & 0 deletions utils/links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const starknetIdAppLink = `https://${
process.env.NEXT_PUBLIC_IS_TESTNET ? "goerli." : ""
}app.starknet.id/`;

0 comments on commit 7e7b298

Please sign in to comment.