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

fix: remove calls to api #28

Merged
merged 4 commits into from
Sep 22, 2024
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
14 changes: 9 additions & 5 deletions app/components/leaderboard/leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const Leaderboard: FunctionComponent<DataTableProps> = ({
);
const [error, setError] = useState<string | undefined>(undefined);
const [currentResult, setCurrentResult] = useState<SearchResult | null>();
const enableSearch = false;

useEffect(() => {
if (!isLoaded || isInit) return;
Expand Down Expand Up @@ -128,11 +129,14 @@ const Leaderboard: FunctionComponent<DataTableProps> = ({
return (
<div className={styles.main}>
<div className={styles.searchSection}>
<SearchBar
starknetIdNavigator={starknetIdNavigator}
setCurrentResult={setCurrentResult}
onSearch={onSearch}
/>
<div className={styles.searchTitle}>The game has ended</div>
{enableSearch ? (
<SearchBar
starknetIdNavigator={starknetIdNavigator}
setCurrentResult={setCurrentResult}
onSearch={onSearch}
/>
) : null}
</div>
<div className={styles.tableSection}>
<div className={styles.titleSection}>
Expand Down
98 changes: 76 additions & 22 deletions app/components/leaderboard/leaderboardWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,89 @@
"use client";

import React from "next";
import { FunctionComponent, useEffect, useState } from "react";
import { FunctionComponent } from "react";
import { LeaderboardData } from "@/constants/types";
import { getWinners } from "@/services/leaderboardService";
import Leaderboard from "./leaderboard";

const LeaderboardWrapper: FunctionComponent = () => {
const [isLoaded, setIsLoaded] = useState(false);
const [data, setData] = useState<LeaderboardData[]>();
const [participants, setParticipants] = useState<number>(0);
// const [isLoaded, setIsLoaded] = useState(false);
// const [data, setData] = useState<LeaderboardData[]>();
// const [participants, setParticipants] = useState<number>(3607);
const participants = 3607;
const winners: LeaderboardData[] = [
{
address:
"0x075f829bfd061ea938d7f8e399db70ac410b719cb1f0a321ce1d80dca44fbbd0",
rank: 1,
times_clicked: 1,
reward: "5",
},
{
address: "0xcd61a050a000af3093cdbbf536717356b709683b",
rank: 2,
times_clicked: 1,
},
{
address: "0x27674c788249dbe99e8e5f12cafe1f1c8b9e7a12",
rank: 3,
times_clicked: 1,
},
{
address:
"0x0625eb7e2a2b279eeaff6edd753abfd82f5e2fd0f69af0b2ab6528f8e517d9df",
rank: 4,
times_clicked: 1,
},
{
address: "0x84ef5a8fcfd2873d053dbc76276a98801ed081e1",
rank: 5,
times_clicked: 1,
},
{
address:
"0x04e1ec4b3f6c8658f4e2adc0237fac75cf9b20aecb0638597e3cb8d26c0d9519",
rank: 6,
times_clicked: 1,
},
{
address: "0x611f08e009a02b77d1ce331e01b616b93ee5738c",
rank: 7,
times_clicked: 1,
},
{
address:
"0x07fbe54431c250c3560ffa44b1d7d57b056e320dade627ff6123466dc081b0b7",
rank: 8,
times_clicked: 1,
},
{
address:
"0x04d25fa97c8080069ba27839f12691bb13ea74ccdb89a55b576fa3d2d8b39d48",
rank: 9,
times_clicked: 10,
},
{
address: "0xf6400fe683ab896001caca296e6940c819b68449",
rank: 10,
times_clicked: 1,
},
];

useEffect(() => {
if (isLoaded) return;
getWinners()
.then((res) => {
setData(res.winners);
setParticipants(res.nb_players);
setIsLoaded(true);
})
.catch((err) => {
console.log("Error while fetching tracking virtualTxId", err);
});
});
// useEffect(() => {
// if (isLoaded) return;
// getWinners()
// .then((res) => {
// setData(res.winners);
// setParticipants(res.nb_players);
// setIsLoaded(true);
// })
// .catch((err) => {
// console.log("Error while fetching tracking virtualTxId", err);
// });
// });

return (
<Leaderboard
data={data as LeaderboardData[]}
isLoaded={isLoaded}
participants={participants}
/>
<Leaderboard data={winners} isLoaded={true} participants={participants} />
);
};

Expand Down
13 changes: 7 additions & 6 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export default function Home() {
const [showNotifPlayed, setShowNotifPlayed] = useState<boolean>(false);
const [showErrorMsg, setShowErrorMsg] = useState<boolean>(false);
const [errorMsg, setErrorMsg] = useState<string>("");
const [leaderboard, setLeaderboard] = useState<boolean>(false);
// const [leaderboard, setLeaderboard] = useState<boolean>(false);
const leaderboard = true;
const [maintenance, setMaintenance] = useState<boolean>(false);
const unexpectedError = isUnexpectedError();

Expand Down Expand Up @@ -185,7 +186,7 @@ export default function Home() {

useEffect(() => {
if (!isLoaded && process.env.NEXT_PUBLIC_ENABLE_LEADERBOARD === "true") {
setLeaderboard(true);
// setLeaderboard(true);
setIsLoaded(true);
}
}, []);
Expand Down Expand Up @@ -653,7 +654,9 @@ export default function Home() {

return (
<>
{maintenance ? (
{leaderboard ? (
<LeaderboardWrapper />
) : maintenance ? (
<Maintenance
isLoaded={isLoaded}
isMobile={isMobile}
Expand All @@ -665,8 +668,6 @@ export default function Home() {
isMobile={isMobile}
priceValue={priceValue}
/>
) : leaderboard ? (
<LeaderboardWrapper />
) : (
<>
<main className={styles.main}>
Expand Down Expand Up @@ -741,7 +742,7 @@ export default function Home() {
icon={<img src="/visuals/eth.svg" width={14} />}
enableHover={false}
>
{priceValue}
{priceValue as string}
</Button>
)
) : null}
Expand Down
28 changes: 28 additions & 0 deletions app/styles/leaderboard.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@
margin: 10px auto;
}

.searchTitle {
display: flex;
flex-direction: column;
gap: 12px;
position: relative;
width: 500px;
height: 200px;
margin: auto;
justify-content: center;
text-align: center;

color: var(--content);
font-family: "Airstrike";
font-size: 32px;
font-style: normal;
font-weight: 700;
line-height: 32px;
letter-spacing: 0.04em;
}

@media (max-width: 1024px) {
.tableSection {
padding: 24px;
Expand All @@ -93,6 +113,10 @@
height: 104px;
margin: 10px auto;
}
.searchTitle {
width: 350px;
height: 90px;
}
}

@media (max-width: 490px) {
Expand All @@ -110,4 +134,8 @@
height: 71px;
margin: 10px auto;
}
.searchTitle {
width: 250px;
height: 65px;
}
}