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

add registration countdown and register claim button #2600

Merged
merged 6 commits into from
Dec 27, 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
4 changes: 2 additions & 2 deletions landing/src/components/modules/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SidebarMenuItem,
} from "@/components/ui/sidebar";
import { Link } from "@tanstack/react-router";
import { Castle, Gamepad2, Home, PlayCircle, Scale, Sheet, Ship, Twitter } from "lucide-react";
import { Castle, Coins, Gamepad2, Home, PlayCircle, Scale, Sheet, Ship, Twitter } from "lucide-react";
import { TypeH2 } from "../typography/type-h2";

import { ReactComponent as Discord } from "@/assets/icons/discord.svg";
Expand All @@ -20,12 +20,12 @@ const items = [
url: "/",
icon: Home,
},
{ title: "Claim", url: "/claim", icon: Coins },
{
title: "Bridge",
url: "/trade",
icon: Ship,
},

{
title: "Realms",
url: "/mint",
Expand Down
45 changes: 45 additions & 0 deletions landing/src/components/modules/season-registration-timer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useLeaderboardStatus } from "@/hooks/usePrizeClaim";
import { useEffect, useState } from "react";

export const SeasonRegistrationTimer = () => {
const [timeLeft, setTimeLeft] = useState({ hours: "00", minutes: "00", seconds: "00" });

const { leaderboard } = useLeaderboardStatus();

const registrationEnd = leaderboard?.registration_end_timestamp;

useEffect(() => {
if (!registrationEnd) return;

const timer = setInterval(() => {
const now = Math.floor(Date.now() / 1000);
const end = Number(registrationEnd);
if (now >= end) {
setTimeLeft({ hours: "00", minutes: "00", seconds: "00" });
clearInterval(timer);
return;
}

const diff = end - now;
const hours = Math.floor(diff / 3600);
const minutes = Math.floor((diff % 3600) / 60);
const seconds = diff % 60;
setTimeLeft({
hours: String(hours).padStart(2, "0"),
minutes: String(minutes).padStart(2, "0"),
seconds: String(seconds).padStart(2, "0"),
});
}, 1000);

return () => clearInterval(timer);
}, [registrationEnd]);

return (
<div className="bg-white/5 backdrop-blur-sm rounded-xl p-8 text-center flex flex-row gap-2 items-baseline">
<h2 className="text-2xl font-bold text-primary mb-4 font-">Registration Countdown: </h2>
<div className="text-3xl text-primary font-semibold">
{timeLeft.hours}:{timeLeft.minutes}:{timeLeft.seconds}
</div>
</div>
);
};
2 changes: 2 additions & 0 deletions landing/src/components/modules/top-navigation-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Button } from "../ui/button";
import { ResourceIcon } from "../ui/elements/ResourceIcon";
import { SidebarTrigger } from "../ui/sidebar";
import { ModeToggle } from "./mode-toggle";
import { SeasonRegistrationTimer } from "./season-registration-timer";
import { SeasonStartTimer } from "./season-start-timer";

interface TopNavigationViewProps {
Expand Down Expand Up @@ -63,6 +64,7 @@ export const TopNavigationView = ({
</Button>
</div>
<SeasonStartTimer />
<SeasonRegistrationTimer />
<div className="flex gap-2 justify-between">
{!isConnected ? (
<>
Expand Down
15 changes: 15 additions & 0 deletions landing/src/dojo/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ export function createSystemCalls({ provider }: SetupNetworkResult) {
return await provider.bridge_finish_withdraw_from_realm(props);
};

const register_to_leaderboard = async (props: SystemProps.RegisterToLeaderboardProps) => {
await provider.register_to_leaderboard(props);
};

const end_game = async (props: SystemProps.EndGameProps) => {
await provider.end_game(props);
};

const claim_leaderboard_rewards = async (props: SystemProps.ClaimLeaderboardRewardsProps) => {
await provider.claim_leaderboard_rewards(props);
};

const isLive = async () => {
try {
await provider.uuid();
Expand All @@ -169,6 +181,9 @@ export function createSystemCalls({ provider }: SetupNetworkResult) {
bridge_resources_into_realm: withQueueing(withErrorHandling(bridge_resources_into_realm)),
bridge_start_withdraw_from_realm: withQueueing(withErrorHandling(bridge_start_withdraw_from_realm)),
bridge_finish_withdraw_from_realm: withQueueing(withErrorHandling(bridge_finish_withdraw_from_realm)),
register_to_leaderboard: withQueueing(withErrorHandling(register_to_leaderboard)),
end_game: withQueueing(withErrorHandling(end_game)),
claim_leaderboard_rewards: withQueueing(withErrorHandling(claim_leaderboard_rewards)),
};

// TODO: Fix Type
Expand Down
13 changes: 13 additions & 0 deletions landing/src/dojo/modelManager/leaderboard/LeaderboardManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export class LeaderboardManager {
const contribution = getComponentValue(this.dojoResult.setup.components.Contribution, contributionEntityId);
if (!contribution) return;

if (this.hasClaimedReward(contribution.player_address)) return;

const effectiveContribution =
(Number(contribution.amount) * RESOURCE_RARITY[contribution.resource_type as ResourcesIds]!) /
configManager.getResourcePrecision();
Expand Down Expand Up @@ -153,6 +155,8 @@ export class LeaderboardManager {
owner_address = ContractAddress(owner_address);
percentage = Number(percentage) / 10_000;

if (this.hasClaimedReward(owner_address)) return;

const previousPoints = keyPointsMap.get(getKey(owner_address)) || 0;
const userShare = totalPoints * percentage;
const newPointsForPlayer = previousPoints + userShare;
Expand All @@ -161,9 +165,18 @@ export class LeaderboardManager {
});
}
});

return true;
}

public hasClaimedReward(playerAddress: ContractAddress) {
const claimed = getComponentValue(
this.dojoResult.setup.components.LeaderboardRewardClaimed,
getEntityIdFromKeys([playerAddress]),
);
return claimed?.claimed;
}

public getAddressShares(playerAddress: ContractAddress, hyperstructureEntityId: ID) {
const hyperstructure = getComponentValue(
this.dojoResult.setup.components.Hyperstructure,
Expand Down
Loading
Loading