Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new quest & achievements #167

Merged
merged 18 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/UI/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Footer: FunctionComponent = () => {
</div>
<div
className={styles.social}
onClick={() => window.open("http://discord.gg/8uS2Mgcsza")}
onClick={() => window.open("http://discord.gg/Td4a5wS5")}
>
<span>
<DiscordIcon width="17" color="#101012" />
Expand Down
15 changes: 6 additions & 9 deletions components/lands/land.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import styles from "../../styles/profile.module.css";
import landStyles from "../../styles/components/land.module.css";
import Button from "../UI/button";
import { SoloBuildings, StarkFighterBuildings } from "../../constants/nft";
import { AchievementsDocument } from "../../types/backTypes";

type LandProps = {
address: string;
Expand All @@ -13,7 +14,6 @@ type LandProps = {
setSinceDate: (s: string | null) => void;
setTotalNfts: (nb: number) => void;
setAchievementCount: (n: number) => void;
hasDomain: boolean;
};

export const Land = ({
Expand All @@ -23,7 +23,6 @@ export const Land = ({
setSinceDate,
setTotalNfts,
setAchievementCount,
hasDomain,
}: LandProps) => {
const [userNft, setUserNft] = useState<BuildingsInfo[]>();
const [hasNFTs, setHasNFTs] = useState<boolean>(false);
Expand Down Expand Up @@ -73,15 +72,14 @@ export const Land = ({
const response = await fetch(
`${process.env.NEXT_PUBLIC_API_LINK}/achievements/fetch?addr=${address}`
);
const results: UserAchievements[] = await response.json();

const results: AchievementsDocument[] = await response.json();
if (results) {
results.forEach((result: UserAchievements) => {
results.forEach((result: AchievementsDocument) => {
for (let i = result.achievements.length - 1; i >= 0; i--) {
if (result.achievements[i].completed) {
filteredAssets.push(result.achievements[i].id);
if (i === 2) count++;
break;
if (i === result.achievements.length - 1) count++;
if (result.category_type === "levels") break;
}
}
});
Expand All @@ -101,7 +99,7 @@ export const Land = ({
}/achievements/fetch_buildings?ids=${filteredAssets.join(",")}`
);
const results: BuildingsInfo[] = await response.json();
if (results) {
if (results && results.length > 0) {
setUserNft(results);
setHasNFTs(true);
} else setHasNFTs(false);
Expand Down Expand Up @@ -152,7 +150,6 @@ export const Land = ({
);
filteredAssets.push(highestValue);
}
if (hasDomain) filteredAssets.push(64000); // add starknetid building if user has a .stark domain

await getBuildingsFromAchievements(filteredAssets);
await getBuildingsInfo(filteredAssets);
Expand Down
2 changes: 1 addition & 1 deletion components/lands/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const Map: FunctionComponent<MapProps> = ({
) : null}
{mapReader.roadProps ? (
<RoadProps
tilesets={data?.defs.tilesets}
tileset={data.defs.tilesets[2]}
cityData={mapReader.roadProps}
tileData={mapReader.tileData[tileTypes.PROPS]}
/>
Expand Down
12 changes: 3 additions & 9 deletions components/lands/roadProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { useLoader } from "@react-three/fiber";
import RoadItem from "./roadItem";

type RoadItemsProps = {
tilesets: Tileset[];
tileset: Tileset;
cityData: (RoadObjects | null)[][];
tileData: TileData[];
};

const RoadProps: FunctionComponent<RoadItemsProps> = ({
tilesets,
tileset,
cityData,
tileData,
}) => {
Expand All @@ -27,19 +27,13 @@ const RoadProps: FunctionComponent<RoadItemsProps> = ({
TextureLoader,
"/land/textures/SID_BuildingSheet.png"
);
texture.repeat = new Vector2(1 / 80, 1 / 80);
texture.repeat = new Vector2(1 / tileset.__cHei, 1 / tileset.__cWid);
texture.magFilter = NearestFilter;
texture.wrapS = texture.wrapT = RepeatWrapping;

return texture;
}, []);

const tileset = useMemo(() => {
return tilesets.find(
(tileset: Tileset) => tileset.identifier === "SID_BuildingSheet"
);
}, []);

// Reuse same planes for props
const simplePlane = useMemo(() => {
// used for bench, sewerPlate & firehydrant props
Expand Down
2 changes: 1 addition & 1 deletion components/lands/scene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const Scene: FunctionComponent<SceneProps> = ({
}, [data]);

useEffect(() => {
fetch("/land/data/SIDCity_Base_V5.json")
fetch("/land/data/SIDCity_Base.json")
.then((response) => {
if (!response.ok) {
throw new Error(response.statusText);
Expand Down
8 changes: 6 additions & 2 deletions components/quests/questDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ const QuestDetails: FunctionComponent<QuestDetailsProps> = ({
address: string | undefined
) => {
if (address && quest.rewards_endpoint) {
fetch(`${quest.rewards_endpoint}?addr=${hexToDecimal(address)}`)
fetch(
`${process.env.NEXT_PUBLIC_API_LINK}/${
quest.rewards_endpoint
}?addr=${hexToDecimal(address)}`
)
.then((response) => response.json())
.then((data) => {
if (data.rewards) {
Expand Down Expand Up @@ -201,7 +205,7 @@ const QuestDetails: FunctionComponent<QuestDetailsProps> = ({
if (task.verify_endpoint_type === "oauth_discord") {
const rootUrl = "https://discord.com/api/oauth2/authorize";
const options = {
redirect_uri: `${task.verify_endpoint}`,
redirect_uri: `${process.env.NEXT_PUBLIC_API_LINK}/${task.verify_endpoint}`,
client_id: process.env.NEXT_PUBLIC_DISCORD_CLIENT_ID as string,
response_type: "code",
scope: ["identify", "guilds"].join(" "),
Expand Down
4 changes: 3 additions & 1 deletion components/quests/task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const Task: FunctionComponent<Task> = ({
setIsLoading(false);
} else {
try {
const response = await fetch(verifyEndpoint);
const response = await fetch(
`${process.env.NEXT_PUBLIC_API_LINK}/${verifyEndpoint}`
);

if (!response.ok) {
throw new Error(await response.text());
Expand Down
2 changes: 1 addition & 1 deletion components/quiz/quiz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Quiz: FunctionComponent<QuizProps> = ({
if (answers.length !== quiz.questions.length) return;
const load = () => {
setPassed("loading");
fetch(verifyEndpoint, {
fetch(`${process.env.NEXT_PUBLIC_API_LINK}/${verifyEndpoint}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
41 changes: 22 additions & 19 deletions components/skeletons/achievementSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@ import styles from "../../styles/achievements.module.css";
const AchievementSkeleton: FunctionComponent = () => {
return (
<>
<Skeleton
variant="rounded"
width={650}
height={245}
sx={{
bgcolor: "grey.900",
marginBottom: "40px",
borderRadius: "30px",
}}
/>
<Skeleton
variant="rounded"
width={650}
height={245}
sx={{
bgcolor: "grey.900",
borderRadius: "30px",
}}
/>
<div className={styles.achievementSkeleton}>
<Skeleton
variant="rounded"
className={styles.achievementLoading}
sx={{
bgcolor: "grey.900",
borderRadius: "30px",
margin: "40px auto 0",
}}
/>
</div>
<div className={styles.achievementSkeleton}>
<Skeleton
variant="rounded"
className={styles.achievementLoading}
sx={{
bgcolor: "grey.900",
borderRadius: "30px",
margin: "10px auto 0",
}}
/>
</div>
</>
);
};
Expand Down
5 changes: 5 additions & 0 deletions constants/nft.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// NFT names & buildings id from db
export enum SoloBuildings {
"Zklend Artemis" = 64001,
"AVNU Astronaut" = 64002,
"JediSwap Light Saber" = 64003,
"Starknet ID Tribe Totem" = 64004,
"Sithswap Helmet" = 64008,
"MySwap" = 64009,
"Morphine" = 64010,
"Carmine" = 64011,
"Ekubo" = 64012,
}

export enum StarkFighterBuildings {
Expand Down
7 changes: 3 additions & 4 deletions pages/[addressOrDomain].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const AddressOrDomain: NextPage = () => {
.then((addr) => {
setIdentity({
starknet_id: "0",
addr: hexToDecimal(addr),
addr: addr,
domain: addressOrDomain,
is_owner_main: false,
});
Expand Down Expand Up @@ -157,7 +157,7 @@ const AddressOrDomain: NextPage = () => {
} else {
setIdentity({
starknet_id: "0",
addr: hexToDecimal(addressOrDomain),
addr: addressOrDomain,
domain: name,
is_owner_main: false,
});
Expand All @@ -168,7 +168,7 @@ const AddressOrDomain: NextPage = () => {
} else {
setIdentity({
starknet_id: "0",
addr: hexToDecimal(addressOrDomain),
addr: addressOrDomain,
domain: minifyAddress(addressOrDomain),
is_owner_main: false,
});
Expand Down Expand Up @@ -231,7 +231,6 @@ const AddressOrDomain: NextPage = () => {
setSinceDate={setSinceDate}
setTotalNfts={setTotalNfts}
setAchievementCount={setAchievementCount}
hasDomain={identity.domain ? true : false}
/>
<div className={styles.profiles}>
<ProfileCard
Expand Down
63 changes: 33 additions & 30 deletions pages/achievements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ import {
import Achievement from "../components/achievements/achievement";
import { hexToDecimal } from "../utils/feltService";
import AchievementSkeleton from "../components/skeletons/achievementSkeleton";
import { useLocation } from "react-use";

const Achievements: NextPage = () => {
const location = useLocation();
const { address } = useAccount();
const [userAchievements, setUserAchievements] = useState<
AchievementsDocument[]
>([]);
const [hasChecked, setHasChecked] = useState<boolean>(false);

useEffect(() => {
setHasChecked(false);
setUserAchievements([]);
}, [location, address]);

useEffect(() => {
// If a call was made with an address in the first second, the call with 0 address should be cancelled
let shouldFetchWithZeroAddress = true;
Expand Down Expand Up @@ -54,7 +61,7 @@ const Achievements: NextPage = () => {
return () => {
clearTimeout(timer);
};
}, [address, hasChecked]);
}, [hasChecked, address]);

// Map through user achievements and check if any are completed
useEffect(() => {
Expand All @@ -63,25 +70,21 @@ const Achievements: NextPage = () => {
userAchievements.forEach((achievementCategory, index) => {
achievementCategory.achievements.forEach((achievement, aIndex) => {
if (!achievement.completed) {
if (achievement.verify_type === "default") {
const fetchPromise = fetch(
`${
process.env.NEXT_PUBLIC_API_LINK
}/achievements/verify_default?addr=${hexToDecimal(
address
)}&id=${achievement.id}`
)
.then((response) => response.json())
.then((data: CompletedDocument) => {
if (data?.achieved) {
const newUserAchievements = [...userAchievements];
newUserAchievements[index].achievements[aIndex].completed =
true;
setUserAchievements(newUserAchievements);
}
});
promises.push(fetchPromise);
}
const fetchPromise = fetch(
`${process.env.NEXT_PUBLIC_API_LINK}/achievements/verify_${
achievement.verify_type
}?addr=${hexToDecimal(address)}&id=${achievement.id}`
)
.then((response) => response.json())
.then((data: CompletedDocument) => {
if (data?.achieved) {
const newUserAchievements = [...userAchievements];
newUserAchievements[index].achievements[aIndex].completed =
true;
setUserAchievements(newUserAchievements);
}
});
promises.push(fetchPromise);
}
});
});
Expand All @@ -90,7 +93,7 @@ const Achievements: NextPage = () => {
setHasChecked(true);
});
}
}, [userAchievements.length, address]);
}, [userAchievements.length, hasChecked]);

return (
<div className={styles.screen}>
Expand All @@ -101,10 +104,10 @@ const Achievements: NextPage = () => {
Complete achievements and grow your Starknet on-chain reputation
</p>
</div>
<div className={styles.cardWrapper}>
<div className={styles.cards}>
{userAchievements.length > 0 ? (
userAchievements.map(
{userAchievements.length > 0 ? (
<div className={styles.cardWrapper}>
<div className={styles.cards}>
{userAchievements.map(
(achievementCategory: AchievementsDocument, index: number) => {
return (
<Achievement
Expand All @@ -114,12 +117,12 @@ const Achievements: NextPage = () => {
/>
);
}
)
) : (
<AchievementSkeleton />
)}
)}
</div>
</div>
</div>
) : (
<AchievementSkeleton />
)}
</div>
</div>
);
Expand Down
Binary file added public/achievements/starknetnfts/briq.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/achievements/starknetnfts/carbonable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/achievements/starknetnfts/duck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/achievements/starknetnfts/starknetid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/carmine/favicon.ico
Binary file not shown.
Binary file added public/carmine/specialist.webp
Binary file not shown.
Loading