Skip to content

Commit

Permalink
points hook
Browse files Browse the repository at this point in the history
  • Loading branch information
benisgold committed Nov 2, 2023
1 parent 274b5b1 commit f644b23
Show file tree
Hide file tree
Showing 4 changed files with 515 additions and 299 deletions.
29 changes: 29 additions & 0 deletions src/graphql/queries/metadata.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,32 @@ query getdApp($shortName: String!, $url: String!, $status: Boolean!) {
shortName
}
}

query getPointsDataForWallet($address: String!) {
points(address: $address) {
meta {
distribution {
next
}
status
}
leaderboard {
accounts {
address
earnings {
total
}
ens
avatarURL
}
}
earnings {
total
}
stats {
position {
current
}
}
}
}
10 changes: 9 additions & 1 deletion src/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,15 @@
"longest_yet": "Longest yet",
"day": "day",
"days": "days",
"leaderboard": "Leaderboard"
"leaderboard": "Leaderboard",
"sunday": "Sunday",
"monday": "Monday",
"tuesday": "Tuesday",
"wednesday": "Wednesday",
"thursday": "Thursday",
"friday": "Friday",
"saturday": "Saturday",
"error": "Failed to fetch data"
},
"pools": {
"deposit": "Deposit",
Expand Down
33 changes: 33 additions & 0 deletions src/resources/points.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { POINTS, useExperimentalFlag } from '@/config';
import { metadataClient } from '@/graphql';
import { GetPointsDataForWalletQuery } from '@/graphql/__generated__/metadata';
import config from '@/model/config';
import { createQueryKey } from '@/react-query';
import { useQuery } from '@tanstack/react-query';

export function pointsQueryKey({ address }: { address: string }) {
return createQueryKey('points', { address }, { persisterVersion: 1 });
}

export function usePoints({ walletAddress }: { walletAddress: string }) {
const pointsEnabled =
(useExperimentalFlag(POINTS) || config.points_fully_enabled) &&
config.points_enabled;
const queryKey = pointsQueryKey({
address: walletAddress,
});

const query = useQuery<GetPointsDataForWalletQuery>(
queryKey,
async () =>
await metadataClient.getPointsDataForWallet({
address: walletAddress,
}),
{
enabled: pointsEnabled && !!walletAddress,
cacheTime: Infinity,
}
);

return query;
}
Loading

0 comments on commit f644b23

Please sign in to comment.