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 4 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
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
96 changes: 55 additions & 41 deletions landing/src/hooks/gql/gql.ts

Large diffs are not rendered by default.

129 changes: 129 additions & 0 deletions landing/src/hooks/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7303,6 +7303,49 @@ export type EternumStatisticsQueryVariables = Exact<{ [key: string]: never; }>;

export type EternumStatisticsQuery = { __typename?: 'World__Query', s0EternumAddressNameModels?: { __typename?: 's0_eternum_AddressNameConnection', totalCount: number } | null, s0EternumHyperstructureModels?: { __typename?: 's0_eternum_HyperstructureConnection', totalCount: number } | null, s0EternumRealmModels?: { __typename?: 's0_eternum_RealmConnection', totalCount: number } | null, s0EternumFragmentMineDiscoveredModels?: { __typename?: 's0_eternum_FragmentMineDiscoveredConnection', totalCount: number } | null };

export type HasGameEndedQueryVariables = Exact<{ [key: string]: never; }>;


export type HasGameEndedQuery = { __typename?: 'World__Query', s0EternumGameEndedModels?: { __typename?: 's0_eternum_GameEndedConnection', edges?: Array<{ __typename?: 's0_eternum_GameEndedEdge', node?: { __typename?: 's0_eternum_GameEnded', winner_address?: any | null } | null } | null> | null } | null };

export type HasPlayerRegisteredQueryVariables = Exact<{
accountAddress: Scalars['ContractAddress']['input'];
}>;


export type HasPlayerRegisteredQuery = { __typename?: 'World__Query', s0EternumOwnerModels?: { __typename?: 's0_eternum_OwnerConnection', totalCount: number } | null };

export type HasPlayerClaimedQueryVariables = Exact<{
accountAddress: Scalars['ContractAddress']['input'];
}>;


export type HasPlayerClaimedQuery = { __typename?: 'World__Query', s0EternumLeaderboardRewardClaimedModels?: { __typename?: 's0_eternum_LeaderboardRewardClaimedConnection', totalCount: number } | null };

export type GetLeaderboardEntryQueryVariables = Exact<{
accountAddress: Scalars['ContractAddress']['input'];
}>;


export type GetLeaderboardEntryQuery = { __typename?: 'World__Query', s0EternumLeaderboardEntryModels?: { __typename?: 's0_eternum_LeaderboardEntryConnection', edges?: Array<{ __typename?: 's0_eternum_LeaderboardEntryEdge', node?: { __typename?: 's0_eternum_LeaderboardEntry', address?: any | null, points?: any | null } | null } | null> | null } | null };

export type GetLeaderboardQueryVariables = Exact<{ [key: string]: never; }>;


export type GetLeaderboardQuery = { __typename?: 'World__Query', s0EternumLeaderboardModels?: { __typename?: 's0_eternum_LeaderboardConnection', edges?: Array<{ __typename?: 's0_eternum_LeaderboardEdge', node?: { __typename?: 's0_eternum_Leaderboard', total_points?: any | null, registration_end_timestamp?: any | null, distribution_started?: any | null, total_price_pool?: { __typename?: 's0_eternum_Optionu256', Some?: any | null, option?: any | null } | null } | null } | null> | null } | null };

export type GetHyperstructureContributionsQueryVariables = Exact<{
accountAddress: Scalars['ContractAddress']['input'];
}>;


export type GetHyperstructureContributionsQuery = { __typename?: 'World__Query', s0EternumContributionModels?: { __typename?: 's0_eternum_ContributionConnection', edges?: Array<{ __typename?: 's0_eternum_ContributionEdge', node?: { __typename?: 's0_eternum_Contribution', hyperstructure_entity_id?: any | null, amount?: any | null } | null } | null> | null } | null };

export type GetEpochsQueryVariables = Exact<{ [key: string]: never; }>;


export type GetEpochsQuery = { __typename?: 'World__Query', s0EternumEpochModels?: { __typename?: 's0_eternum_EpochConnection', edges?: Array<{ __typename?: 's0_eternum_EpochEdge', node?: { __typename?: 's0_eternum_Epoch', start_timestamp?: any | null, hyperstructure_entity_id?: any | null, index?: any | null, owners?: Array<{ __typename?: 's0_eternum_ContractAddressu16', _0?: any | null, _1?: any | null } | null> | null } | null } | null> | null } | null };

export type GetEntityPositionQueryVariables = Exact<{
entityIds: Array<Scalars['u32']['input']> | Scalars['u32']['input'];
}>;
Expand Down Expand Up @@ -7459,6 +7502,92 @@ export const EternumStatisticsDocument = new TypedDocumentString(`
}
}
`) as unknown as TypedDocumentString<EternumStatisticsQuery, EternumStatisticsQueryVariables>;
export const HasGameEndedDocument = new TypedDocumentString(`
query hasGameEnded {
s0EternumGameEndedModels {
edges {
node {
winner_address
}
}
}
}
`) as unknown as TypedDocumentString<HasGameEndedQuery, HasGameEndedQueryVariables>;
export const HasPlayerRegisteredDocument = new TypedDocumentString(`
query hasPlayerRegistered($accountAddress: ContractAddress!) {
s0EternumOwnerModels(where: {address: $accountAddress}) {
totalCount
}
}
`) as unknown as TypedDocumentString<HasPlayerRegisteredQuery, HasPlayerRegisteredQueryVariables>;
export const HasPlayerClaimedDocument = new TypedDocumentString(`
query hasPlayerClaimed($accountAddress: ContractAddress!) {
s0EternumLeaderboardRewardClaimedModels(where: {address: $accountAddress}) {
totalCount
}
}
`) as unknown as TypedDocumentString<HasPlayerClaimedQuery, HasPlayerClaimedQueryVariables>;
export const GetLeaderboardEntryDocument = new TypedDocumentString(`
query getLeaderboardEntry($accountAddress: ContractAddress!) {
s0EternumLeaderboardEntryModels(where: {address: $accountAddress}) {
edges {
node {
address
points
}
}
}
}
`) as unknown as TypedDocumentString<GetLeaderboardEntryQuery, GetLeaderboardEntryQueryVariables>;
export const GetLeaderboardDocument = new TypedDocumentString(`
query getLeaderboard {
s0EternumLeaderboardModels {
edges {
node {
total_points
registration_end_timestamp
total_price_pool {
Some
option
}
distribution_started
}
}
}
}
`) as unknown as TypedDocumentString<GetLeaderboardQuery, GetLeaderboardQueryVariables>;
export const GetHyperstructureContributionsDocument = new TypedDocumentString(`
query getHyperstructureContributions($accountAddress: ContractAddress!) {
s0EternumContributionModels(
where: {player_address: $accountAddress}
limit: 1000
) {
edges {
node {
hyperstructure_entity_id
amount
}
}
}
}
`) as unknown as TypedDocumentString<GetHyperstructureContributionsQuery, GetHyperstructureContributionsQueryVariables>;
export const GetEpochsDocument = new TypedDocumentString(`
query getEpochs {
s0EternumEpochModels(limit: 1000) {
edges {
node {
owners {
_0
_1
}
start_timestamp
hyperstructure_entity_id
index
}
}
}
}
`) as unknown as TypedDocumentString<GetEpochsQuery, GetEpochsQueryVariables>;
export const GetEntityPositionDocument = new TypedDocumentString(`
query getEntityPosition($entityIds: [u32!]!) {
s0EternumPositionModels(where: {entity_idIN: $entityIds}) {
Expand Down
91 changes: 91 additions & 0 deletions landing/src/hooks/query/leaderboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { graphql } from "../gql";

export const GET_GAME_WINNER = graphql(`
query hasGameEnded {
s0EternumGameEndedModels {
edges {
node {
winner_address
}
}
}
}
`);

export const GET_PLAYER_HAS_REGISTRED = graphql(`
query hasPlayerRegistered($accountAddress: ContractAddress!) {
s0EternumOwnerModels(where: { address: $accountAddress }) {
totalCount
}
}
`);

export const GET_PLAYER_HAS_CLAIMED = graphql(`
query hasPlayerClaimed($accountAddress: ContractAddress!) {
s0EternumLeaderboardRewardClaimedModels(where: { address: $accountAddress }) {
totalCount
}
}
`);

export const GET_LEADERBOARD_ENTRY = graphql(`
query getLeaderboardEntry($accountAddress: ContractAddress!) {
s0EternumLeaderboardEntryModels(where: { address: $accountAddress }) {
edges {
node {
address
points
}
}
}
}
`);

export const GET_LEADERBOARD = graphql(`
query getLeaderboard {
s0EternumLeaderboardModels {
edges {
node {
total_points
registration_end_timestamp
total_price_pool {
Some
option
}
distribution_started
}
}
}
}
`);

export const GET_PLAYER_HYPERSTRUCTURE_CONTRIBUTIONS = graphql(`
query getHyperstructureContributions($accountAddress: ContractAddress!) {
s0EternumContributionModels(where: { player_address: $accountAddress }, limit: 1000) {
edges {
node {
hyperstructure_entity_id
amount
}
}
}
}
`);

export const GET_HYPERSTRUCTURE_EPOCHS = graphql(`
query getEpochs {
s0EternumEpochModels(limit: 1000) {
edges {
node {
owners {
_0
_1
}
start_timestamp
hyperstructure_entity_id
index
}
}
}
}
`);
Loading
Loading