diff --git a/src/components/voting/ShipVotingPanel.tsx b/src/components/voting/ShipVotingPanel.tsx index 75279ec3..c9dd83e8 100644 --- a/src/components/voting/ShipVotingPanel.tsx +++ b/src/components/voting/ShipVotingPanel.tsx @@ -109,7 +109,7 @@ export const ShipVotingPanel = ({ choicesAddress={contest?.contest?.choicesModule_id} /> )} - {shipChoiceId && ( + {shipChoiceId && isConnected && ( - getGsVoting({ + fetchGsVoting({ contestId: ADDR.VOTE_CONTEST, - userAddress: address as Address, + userAddress: address as string | undefined, }), - enabled: !!address, }); return ( diff --git a/src/queries/getGsVoting.ts b/src/queries/getGsVoting.ts index b7e27806..d31e37d2 100644 --- a/src/queries/getGsVoting.ts +++ b/src/queries/getGsVoting.ts @@ -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 => { - 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 });