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

set up pnl leaderboard api #73

Merged
merged 4 commits into from
Feb 3, 2025
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 src/constants/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export enum NAVBAR_MODE {
DEFAULT = "default",
}

export const LEADERBOARD_POINTS_API = 'https://api.overlay.market/point-system/points/leaderboard'
export const LEADERBOARD_POINTS_API = 'https://api.overlay.market/leaderboard-pnl/points/leaderboard'
13 changes: 7 additions & 6 deletions src/pages/Leaderboard/LeaderboardTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const LeaderboardTable: React.FC<LeaderboardTableProps> = ({
}) => {
const { address: account } = useAccount();
const isMobile = useMediaQuery("(max-width: 767px)");
const isMultipleSessions = false;

return (
<Table>
Expand All @@ -39,12 +40,12 @@ const LeaderboardTable: React.FC<LeaderboardTableProps> = ({
>
Leaderboard Rankings
</StyledHeader>
{!isMobile && (
{!isMobile && isMultipleSessions && (
<StyledHeader textalign={"right"}>
Points-Previous Week
</StyledHeader>
)}
<StyledHeader textalign={"right"}>Total Points</StyledHeader>
<StyledHeader textalign={"right"}>Total PnL</StyledHeader>
</tr>
</thead>

Expand Down Expand Up @@ -73,13 +74,13 @@ const LeaderboardTable: React.FC<LeaderboardTableProps> = ({
</Text>
</Flex>
</StyledCell>
{!isMobile && (
{!isMobile && isMultipleSessions && (
<StyledCell textalign="right">
{currentUserData?.previousWeekPoints ?? "0"}
</StyledCell>
)}
<StyledCell textalign="right">
{currentUserData?.totalPoints ?? "0"}
{currentUserData?.totalPoints ? (+currentUserData?.totalPoints).toFixed(2) + "%" : "0"}
</StyledCell>
</CurrentUserRankingRow>
<BgRow></BgRow>
Expand Down Expand Up @@ -125,12 +126,12 @@ const LeaderboardTable: React.FC<LeaderboardTableProps> = ({
<Text>{shortenAddress(rank._id)}</Text>
</Flex>
</StyledCell>
{!isMobile && (
{!isMobile && isMultipleSessions && (
<StyledCell textalign="right">
{rank.previousWeekPoints}
</StyledCell>
)}
<StyledCell textalign="right">{rank.totalPoints}</StyledCell>
<StyledCell textalign="right">{rank.totalPoints.toFixed(2) + "%"}</StyledCell>
</StyledRow>
))}
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Leaderboard/PointsUpdateSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const PointsUpdateSection: React.FC<PointsUpdateSectionProps> = ({

<Flex direction={"column"} gap={"4px"}>
<Text size={"1"} style={{ color: theme.color.grey1 }}>
Points Updated At
Updated At
</Text>
<Text size={"3"} style={{ fontWeight: "600" }}>
{pointsUpdatedAt ? (
Expand Down
10 changes: 5 additions & 5 deletions src/pages/Leaderboard/UserPointsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const UserPointsSection: React.FC<UserPointsSectionProps> = ({
color: isMobile ? theme.color.grey1 : theme.color.grey2,
}}
>
You have {isLoading ? <Loader /> : `${userPoints ?? "0"} points`}
You have {isLoading ? <Loader /> : `${userPoints ? userPoints.toFixed(2) + "%" : "0"} PnL`}
</Text>
</Flex>
) : (
Expand All @@ -57,18 +57,18 @@ const UserPointsSection: React.FC<UserPointsSectionProps> = ({
color: isMobile ? theme.color.grey1 : theme.color.grey2,
}}
>
to see points
to see your place on the leaderboard
</Text>
</Flex>
)}

<Flex gap={"8px"} align={"center"}>
<Text size={"1"} style={{ color: theme.color.grey3 }}>
Points are calculated on Thursdays
Leaderboard is updated every minute!
</Text>
<Link target="_blank" href={LEADERBOARD_LEARN_MORE_LINK}>
{false && <Link target="_blank" href={LEADERBOARD_LEARN_MORE_LINK}>
<GradientText>Learn more</GradientText>
</Link>
</Link>}
</Flex>
</Flex>
);
Expand Down
11 changes: 9 additions & 2 deletions src/pages/Leaderboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ExtendedUserData,
LeaderboardPointsData,
PrevWeekDetails,
SessionDetails,
UserData,
} from "./types";
import { Address } from "viem";
Expand All @@ -21,7 +22,7 @@ import { GradientText } from "./user-points-section-styles";

const INITIAL_NUMBER_OF_ROWS = 10;
const ROWS_PER_LOAD = 20;
const comingSoon = true;
const comingSoon = false;

const Leaderboard: React.FC = () => {
const { address: account } = useAccount();
Expand Down Expand Up @@ -78,6 +79,12 @@ const Leaderboard: React.FC = () => {
}
}, [pointsData]);

const sessionDetails = useMemo<SessionDetails | undefined>(() => {
if (pointsData) {
return pointsData.sessionDetails;
}
}, [pointsData]);

const initialUserData = useMemo<UserData | undefined>(() => {
if (pointsData) {
return pointsData.user;
Expand Down Expand Up @@ -252,7 +259,7 @@ const Leaderboard: React.FC = () => {
userPoints={currentUserData?.totalPoints}
isLoading={fetchingPointsData}
/>
<PointsUpdateSection pointsUpdatedAt={prevWeekDetails?.sessionEnd} />
<PointsUpdateSection pointsUpdatedAt={sessionDetails?.sessionLastUpdated || prevWeekDetails?.sessionEnd} />
</Flex>

<LeaderboardTable ranks={ranks} currentUserData={currentUserData} />
Expand Down
7 changes: 7 additions & 0 deletions src/pages/Leaderboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ export interface PrevWeekDetails {
sessionStart: string
sessionEnd: string
}

export interface SessionDetails {
sessionStart: string
sessionEnd: string
sessionLastUpdated: string
}
export interface UserData {
_id: string
totalPoints: number
Expand All @@ -18,5 +24,6 @@ export interface LeaderboardPointsData {
previousWeekDetails: PrevWeekDetails
totalUsers: number
leaderboardTable: [UserData]
sessionDetails: SessionDetails
user?: UserData
}