fix(trading): use same epochs for all games/stats (#5834)
This commit is contained in:
parent
042919eca9
commit
546deb0e1c
8
apps/trading/lib/hooks/constants.ts
Normal file
8
apps/trading/lib/hooks/constants.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { ENV, Networks } from '@vegaprotocol/environment';
|
||||||
|
|
||||||
|
const TEAMS_STATS_EPOCHS_MAINNET = 30;
|
||||||
|
const TEAMS_STATS_EPOCHS_TESTNET = 192;
|
||||||
|
export const TEAMS_STATS_EPOCHS =
|
||||||
|
ENV.VEGA_ENV === Networks.MAINNET
|
||||||
|
? TEAMS_STATS_EPOCHS_MAINNET
|
||||||
|
: TEAMS_STATS_EPOCHS_TESTNET;
|
@ -7,8 +7,7 @@ import orderBy from 'lodash/orderBy';
|
|||||||
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
||||||
import { useEpochInfoQuery } from './__generated__/Epoch';
|
import { useEpochInfoQuery } from './__generated__/Epoch';
|
||||||
import { type ApolloError } from '@apollo/client';
|
import { type ApolloError } from '@apollo/client';
|
||||||
|
import { TEAMS_STATS_EPOCHS } from './constants';
|
||||||
const TAKE_EPOCHS = 30; // TODO: should this be DEFAULT_AGGREGATION_EPOCHS?
|
|
||||||
|
|
||||||
const findTeam = (entities: GameFieldsFragment['entities'], teamId: string) => {
|
const findTeam = (entities: GameFieldsFragment['entities'], teamId: string) => {
|
||||||
const team = entities.find(
|
const team = entities.find(
|
||||||
@ -45,7 +44,7 @@ export const useGames = (teamId?: string, epochFrom?: number): GamesData => {
|
|||||||
|
|
||||||
let from = epochFrom;
|
let from = epochFrom;
|
||||||
if (!from && epochData) {
|
if (!from && epochData) {
|
||||||
from = Number(epochData.epoch.id) - TAKE_EPOCHS;
|
from = Number(epochData.epoch.id) - TEAMS_STATS_EPOCHS;
|
||||||
if (from < 1) from = 1; // make sure it's not negative
|
if (from < 1) from = 1; // make sure it's not negative
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
type TeamRefereeFieldsFragment,
|
type TeamRefereeFieldsFragment,
|
||||||
type TeamMemberStatsFieldsFragment,
|
type TeamMemberStatsFieldsFragment,
|
||||||
} from './__generated__/Team';
|
} from './__generated__/Team';
|
||||||
import { DEFAULT_AGGREGATION_EPOCHS } from './use-teams';
|
import { TEAMS_STATS_EPOCHS } from './constants';
|
||||||
|
|
||||||
export type Team = TeamFieldsFragment;
|
export type Team = TeamFieldsFragment;
|
||||||
export type TeamStats = TeamStatsFieldsFragment;
|
export type TeamStats = TeamStatsFieldsFragment;
|
||||||
@ -22,7 +22,7 @@ export const useTeam = (teamId?: string, partyId?: string) => {
|
|||||||
variables: {
|
variables: {
|
||||||
teamId: teamId || '',
|
teamId: teamId || '',
|
||||||
partyId,
|
partyId,
|
||||||
aggregationEpochs: DEFAULT_AGGREGATION_EPOCHS,
|
aggregationEpochs: TEAMS_STATS_EPOCHS,
|
||||||
},
|
},
|
||||||
skip: !teamId,
|
skip: !teamId,
|
||||||
fetchPolicy: 'cache-and-network',
|
fetchPolicy: 'cache-and-network',
|
||||||
|
@ -4,9 +4,7 @@ import { useTeamsQuery } from './__generated__/Teams';
|
|||||||
import { useTeamsStatisticsQuery } from './__generated__/TeamsStatistics';
|
import { useTeamsStatisticsQuery } from './__generated__/TeamsStatistics';
|
||||||
import compact from 'lodash/compact';
|
import compact from 'lodash/compact';
|
||||||
import { type TeamStatsFieldsFragment } from './__generated__/Team';
|
import { type TeamStatsFieldsFragment } from './__generated__/Team';
|
||||||
|
import { TEAMS_STATS_EPOCHS } from './constants';
|
||||||
// 192
|
|
||||||
export const DEFAULT_AGGREGATION_EPOCHS = 192;
|
|
||||||
|
|
||||||
const EMPTY_STATS: Partial<TeamStatsFieldsFragment> = {
|
const EMPTY_STATS: Partial<TeamStatsFieldsFragment> = {
|
||||||
totalQuantumVolume: '0',
|
totalQuantumVolume: '0',
|
||||||
@ -16,7 +14,7 @@ const EMPTY_STATS: Partial<TeamStatsFieldsFragment> = {
|
|||||||
quantumRewards: [],
|
quantumRewards: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useTeams = (aggregationEpochs = DEFAULT_AGGREGATION_EPOCHS) => {
|
export const useTeams = (aggregationEpochs = TEAMS_STATS_EPOCHS) => {
|
||||||
const {
|
const {
|
||||||
data: teamsData,
|
data: teamsData,
|
||||||
loading: teamsLoading,
|
loading: teamsLoading,
|
||||||
|
Loading…
Reference in New Issue
Block a user