-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add registration countdown and register claim button
- Loading branch information
1 parent
951c6d1
commit 77182e4
Showing
8 changed files
with
688 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
}; |
Oops, something went wrong.