Skip to content

Commit

Permalink
Merge pull request #218 from DAOmasons/parralelLoad
Browse files Browse the repository at this point in the history
allows parrelel loading for contest state (fixes banner)
  • Loading branch information
jordanlesich authored Jun 14, 2024
2 parents 894db96 + 132a8a5 commit 19f5f81
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/voting/ShipVotingPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const ShipVotingPanel = ({
choicesAddress={contest?.contest?.choicesModule_id}
/>
)}
{shipChoiceId && (
{shipChoiceId && isConnected && (
<VotingFooter
form={form}
index={index}
Expand Down
8 changes: 3 additions & 5 deletions src/contexts/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { GameManager, getGameManger } from '../queries/getGameManger';
import { useAccount } from 'wagmi';
import { UserData, getUserData } from '../queries/getUserData';
import { ADDR } from '../constants/addresses';
import { VoteData, getGsVoting } from '../queries/getGsVoting';
import { Address } from 'viem';
import { VoteData, fetchGsVoting } from '../queries/getGsVoting';

type GlobalStateContext = {
gameManager?: GameManager;
Expand Down Expand Up @@ -70,11 +69,10 @@ export const GlobalStateProvider = ({
} = useQuery({
queryKey: ['gsVoting', ADDR.VOTE_CONTEST, address],
queryFn: () =>
getGsVoting({
fetchGsVoting({
contestId: ADDR.VOTE_CONTEST,
userAddress: address as Address,
userAddress: address as string | undefined,
}),
enabled: !!address,
});

return (
Expand Down
33 changes: 30 additions & 3 deletions src/queries/getGsVoting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,47 @@ const getVoteTokenUserData = async ({
};
};

export const getGsVoting = async ({
export const fetchGsVoting = async ({
contestId,
userAddress,
}: {
contestId: Address;
userAddress: Address;
userAddress: string | undefined;
}): Promise<VoteData> => {
if (!contestId || !userAddress) {
if (!contestId && !userAddress) {
return {
contest: null,
userVotes: null,
userTokenData: null,
};
}

if (!userAddress) {
const { getGsVoting } = getBuiltGraphSDK();
const contestRes = await getGsVoting({ id: contestId });
const currentContest = contestRes?.GrantShipsVoting?.[0];

if (!currentContest) {
return {
contest: null,
userVotes: null,
userTokenData: null,
};
}

return {
contest:
({
...currentContest,
choices: handleShipIds(
currentContest.choices as RawChoice[]
) as (RawChoice & { shipId: string })[],
} as GsVoting) || null,
userVotes: null,
userTokenData: null,
};
}

const { getGsVoting, getUserVotes } = getBuiltGraphSDK();

const contestRes = await getGsVoting({ id: contestId });
Expand Down

0 comments on commit 19f5f81

Please sign in to comment.