Skip to content

Commit

Permalink
Merge pull request #212 from starknet-id/feat/add_braavos_quests
Browse files Browse the repository at this point in the history
feat: add Braavos quests
  • Loading branch information
fricoben authored Oct 9, 2023
2 parents d5c887f + f859208 commit cb69e94
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 8 deletions.
1 change: 1 addition & 0 deletions components/UI/menus/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const Popup: FunctionComponent<PopupProps> = ({
<img className={styles.banner} src={banner} alt="banner" />
</div>
<div className={styles.contentSide}>
<button className={styles.close} onClick={onClose}></button>
<p className={styles.description}>{description}</p>
<div className={styles.button}>
<Button onClick={onClick}>{buttonName}</Button>
Expand Down
2 changes: 1 addition & 1 deletion components/UI/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const Navbar: FunctionComponent = () => {

return (
<>
<div className={`fixed w-full z-[1]`} id="nav">
<div className={`fixed w-full z-[2]`} id="nav">
<div
className={`${styles.navbarContainer} ${
navbarBg ? styles.navbarScrolled : ""
Expand Down
6 changes: 6 additions & 0 deletions components/quests/questDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ type QuestDetailsProps = {
taskId?: string;
res?: string;
errorMsg?: string;
setShowDomainPopup: (show: boolean) => void;
hasRootDomain: boolean;
};

const QuestDetails: FunctionComponent<QuestDetailsProps> = ({
quest,
taskId,
res,
errorMsg,
setShowDomainPopup,
hasRootDomain,
}) => {
const { address } = useAccount();
const { provider } = useProvider();
Expand Down Expand Up @@ -300,6 +304,8 @@ const QuestDetails: FunctionComponent<QuestDetailsProps> = ({
name: quest.issuer,
logoFavicon: quest.logo,
}}
hasRootDomain={hasRootDomain}
setShowDomainPopup={setShowDomainPopup}
/>
);
})}
Expand Down
3 changes: 3 additions & 0 deletions components/quests/task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const Task: FunctionComponent<Task> = ({
setShowQuiz,
quizName,
issuer,
setShowDomainPopup,
hasRootDomain,
}) => {
const [isClicked, setIsClicked] = useState(false);
const [isVerified, setIsVerified] = useState(false);
Expand Down Expand Up @@ -157,6 +159,7 @@ const Task: FunctionComponent<Task> = ({
) : (
<div
onClick={(e) => {
if (!hasRootDomain) return setShowDomainPopup(true);
if (verifyEndpointType === "quiz") return openTask();
if (verifyRedirect && address) window.open(verifyRedirect);
verify(e);
Expand Down
20 changes: 20 additions & 0 deletions hooks/useHasRootOrBraavosDomain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import BN from "bn.js";
import { useContext, useEffect, useState } from "react";
import { StarknetIdJsContext } from "../context/StarknetIdJsProvider";
import { utils } from "starknetid.js";

export default function useHasRootOrBraavosDomain(
address: string | BN | undefined
) {
const [hasDomain, setHasDomain] = useState(false);
const { starknetIdNavigator } = useContext(StarknetIdJsContext);
useEffect(() => {
if (!address) return;
starknetIdNavigator?.getStarkName(address.toString()).then((res) => {
if (utils.isStarkRootDomain(res) || utils.isBraavosSubdomain(res))
setHasDomain(true);
});
}, [starknetIdNavigator, address]);

return hasDomain;
}
17 changes: 12 additions & 5 deletions pages/quest/[questPage].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ErrorScreen from "../../components/UI/screens/errorScreen";
import NftIssuer from "../../components/quests/nftIssuer";
import BackButton from "../../components/UI/backButton";
import useHasRootDomain from "../../hooks/useHasRootDomain";
import useHasRootOrBraavosDomain from "../../hooks/useHasRootOrBraavosDomain";
import { useAccount } from "@starknet-react/core";
import { starknetIdAppLink } from "../../utils/links";
import Popup from "../../components/UI/menus/popup";
Expand Down Expand Up @@ -41,13 +42,16 @@ const QuestPage: NextPage = () => {
});
const [errorPageDisplay, setErrorPageDisplay] = useState(false);
const { address } = useAccount();
const hasRootDomain = useHasRootDomain(address);
const hasRootDomain =
questId && parseInt(questId as string) >= 100
? useHasRootOrBraavosDomain(address)
: useHasRootDomain(address);
const [showDomainPopup, setShowDomainPopup] = useState<boolean>(false);

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

// this fetches quest data
useEffect(() => {
Expand Down Expand Up @@ -81,6 +85,7 @@ const QuestPage: NextPage = () => {
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)}
onClose={() => setShowDomainPopup(false)}
/>
)}
<div className={homeStyles.backButton}>
Expand All @@ -103,6 +108,8 @@ const QuestPage: NextPage = () => {
taskId={taskId as string | undefined}
res={res as string | undefined}
errorMsg={errorMsg as string | undefined}
setShowDomainPopup={setShowDomainPopup}
hasRootDomain={hasRootDomain}
/>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion styles/Home.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.screen404,
.screen {
z-index: 0;
z-index: 1;
position: relative;
padding-top: 12vh;
background-color: var(--background);
Expand Down
2 changes: 1 addition & 1 deletion styles/components/popup.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
left: 0;
width: 100%;
height: 100%;
z-index: var(--z-index-popup);
z-index: 2;
display: flex;
justify-content: center;
align-items: center;
Expand Down
2 changes: 2 additions & 0 deletions types/frontTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Task = {
verifyError?: string;
quizName?: string;
issuer?: Issuer;
setShowDomainPopup: (show: boolean) => void;
hasRootDomain: boolean;
};

type TaskProps = Task & { id: number };
Expand Down

1 comment on commit cb69e94

@vercel
Copy link

@vercel vercel bot commented on cb69e94 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.