Skip to content

Commit

Permalink
add registration countdown and register claim button
Browse files Browse the repository at this point in the history
  • Loading branch information
aymericdelab committed Dec 26, 2024
1 parent 951c6d1 commit 77182e4
Show file tree
Hide file tree
Showing 8 changed files with 688 additions and 128 deletions.
1 change: 1 addition & 0 deletions landing/src/components/modules/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const items = [
url: "/season-passes",
icon: Gamepad2,
},
{ title: "Claim", url: "/claim", icon: Scale },
{
title: "Play",
url: "https://eternum.realms.world/",
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
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
}
}
}
}
`);
97 changes: 97 additions & 0 deletions landing/src/hooks/usePrizeClaim.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { useQuery } from "@tanstack/react-query";
import { useMemo } from "react";
import { execute } from "./gql/execute";
import {
GET_GAME_WINNER,
GET_HYPERSTRUCTURE_EPOCHS,
GET_LEADERBOARD,
GET_LEADERBOARD_ENTRY,
GET_PLAYER_HAS_CLAIMED,
GET_PLAYER_HYPERSTRUCTURE_CONTRIBUTIONS,
} from "./query/leaderboard";

export const useLeaderboardEntry = (playerAddress: string) => {
const { data, isLoading } = useQuery({
queryKey: ["address", playerAddress],
queryFn: () => execute(GET_LEADERBOARD_ENTRY, { accountAddress: playerAddress }),
refetchInterval: 10_000,
});

const points = data?.s0EternumLeaderboardEntryModels?.edges?.[0]?.node?.points ?? 0;

return { points, isLoading };
};

export const useLeaderboardStatus = () => {
const { data, isLoading } = useQuery({
queryKey: ["leaderboard"],
queryFn: () => execute(GET_LEADERBOARD),
refetchInterval: 10_000,
});

const leaderboard = data?.s0EternumLeaderboardModels?.edges?.[0]?.node ?? null;

return { leaderboard, isLoading };
};

export const useHasPlayerClaimed = (playerAddress: string) => {
const { data, isLoading } = useQuery({
queryKey: ["address", playerAddress],
queryFn: () => execute(GET_PLAYER_HAS_CLAIMED, { accountAddress: playerAddress }),
refetchInterval: 10_000,
});

const hasClaimed = (data?.s0EternumLeaderboardRewardClaimedModels?.totalCount || 0) > 0;

return { hasClaimed, isLoading };
};

export const useGameWinner = () => {
const { data, isLoading } = useQuery({
queryKey: ["gameEnded"],
queryFn: () => execute(GET_GAME_WINNER),
refetchInterval: 10_000,
});

const winnerAddress = data?.s0EternumGameEndedModels?.edges?.[0]?.node?.winner_address ?? null;

return { winnerAddress, isLoading };
};

export const useGetPlayerHyperstructureContributions = (playerAddress: string) => {
const { data, isLoading } = useQuery({
queryKey: ["player_address", playerAddress],
queryFn: () => execute(GET_PLAYER_HYPERSTRUCTURE_CONTRIBUTIONS, { accountAddress: playerAddress }),
refetchInterval: 10_000,
});

const hyperstructures =
data?.s0EternumContributionModels?.edges?.map((edge) => edge?.node?.hyperstructure_entity_id) ?? ([] as number[]);

return { hyperstructures: [...new Set(hyperstructures)], isLoading };
};

export const useGetEpochs = (playerAddress: string) => {
const { data, isLoading } = useQuery({
queryKey: ["epochs"],
queryFn: () => execute(GET_HYPERSTRUCTURE_EPOCHS),
refetchInterval: 10_000,
});

const epochs = useMemo(() => {
if (!data?.s0EternumEpochModels?.edges) return [];

return data?.s0EternumEpochModels?.edges
?.map((edge) => {
if (edge?.node?.owners?.find((owner) => owner?._0 === playerAddress)) {
return {
hyperstructure_entity_id: Number(edge?.node.hyperstructure_entity_id),
epoch: edge?.node.index,
};
}
})
.filter((epoch): epoch is { hyperstructure_entity_id: number; epoch: number } => epoch !== undefined);
}, [data, playerAddress]);

return { epochs, isLoading };
};
Loading

0 comments on commit 77182e4

Please sign in to comment.