2024-03-01 14:25:56 +00:00
|
|
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
2024-02-02 18:07:06 +00:00
|
|
|
import compact from 'lodash/compact';
|
|
|
|
import first from 'lodash/first';
|
|
|
|
import { useTeamsQuery } from './__generated__/Teams';
|
|
|
|
import { useTeam } from './use-team';
|
|
|
|
import { useTeams } from './use-teams';
|
2024-02-12 14:03:21 +00:00
|
|
|
import { areTeamGames, useGames } from './use-games';
|
2024-02-02 18:07:06 +00:00
|
|
|
|
|
|
|
export const useMyTeam = () => {
|
|
|
|
const { pubKey } = useVegaWallet();
|
|
|
|
const { data: teams } = useTeams();
|
|
|
|
|
|
|
|
const { data: maybeMyTeam } = useTeamsQuery({
|
|
|
|
variables: {
|
|
|
|
partyId: pubKey,
|
|
|
|
},
|
|
|
|
skip: !pubKey,
|
|
|
|
fetchPolicy: 'cache-and-network',
|
|
|
|
});
|
|
|
|
|
|
|
|
const team = first(compact(maybeMyTeam?.teams?.edges.map((n) => n.node)));
|
|
|
|
const rank = teams.findIndex((t) => t.teamId === team?.teamId) + 1;
|
2024-02-12 14:03:21 +00:00
|
|
|
const { stats } = useTeam(team?.teamId);
|
|
|
|
const { data: games } = useGames(team?.teamId);
|
2024-02-02 18:07:06 +00:00
|
|
|
|
2024-02-12 14:03:21 +00:00
|
|
|
return { team, stats, games: areTeamGames(games) ? games : undefined, rank };
|
2024-02-02 18:07:06 +00:00
|
|
|
};
|