-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(dashboard): better overview and slotviz data fetching
- Creates composables for Overview and SlotViz, which will eventually replace their respective stores - Overview and SlotViz data is now fetched in `index.vue` and propped down - SlotViz updates are handled through update emits - Introduces proper SSR fetching See: BEDS-914
- Loading branch information
1 parent
1db1b7c
commit 3cbdf1c
Showing
5 changed files
with
199 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type { | ||
GetValidatorDashboardResponse, | ||
VDBOverviewData, | ||
} from '~/types/api/validator_dashboard' | ||
import type { DashboardKey } from '~/types/dashboard' | ||
import { API_PATH } from '~/types/customFetch' | ||
|
||
export function useValidatorDashboardOverview() { | ||
const { fetch } = useCustomFetch() | ||
|
||
const overviewData = ref<VDBOverviewData>() | ||
async function fetchOverviewData(key: DashboardKey) { | ||
if (!key) { | ||
throw new Error('No key provided when fetching overview') | ||
} | ||
const res = await fetch<GetValidatorDashboardResponse>( | ||
API_PATH.DASHBOARD_OVERVIEW, | ||
undefined, | ||
{ dashboardKey: key }, | ||
) | ||
return res.data | ||
} | ||
/* const hasValidators = computed<boolean>(() => { | ||
if (!overviewData.value?.validators) { | ||
return false | ||
} | ||
return ( | ||
!!overviewData.value.validators.online | ||
|| !!overviewData.value.validators.exited | ||
|| !!overviewData.value.validators.offline | ||
|| !!overviewData.value.validators.pending | ||
|| !!overviewData.value.validators.slashed | ||
) | ||
}) | ||
const validatorCount = computed(() => { | ||
if (!overviewData.value) { | ||
return undefined | ||
} | ||
if (!overviewData.value.validators) { | ||
return 0 | ||
} | ||
return ( | ||
overviewData.value.validators.exited | ||
+ overviewData.value.validators.offline | ||
+ overviewData.value.validators.online | ||
+ overviewData.value.validators.pending | ||
+ overviewData.value.validators.slashed | ||
) | ||
}) | ||
const hasAbilityCharthistory = computed(() => ({ | ||
daily: (overviewData.value?.chart_history_seconds?.daily ?? 0) > 0, | ||
epoch: (overviewData.value?.chart_history_seconds?.epoch ?? 0) > 0, | ||
hourly: (overviewData.value?.chart_history_seconds?.hourly ?? 0) > 0, | ||
weekly: (overviewData.value?.chart_history_seconds?.weekly ?? 0) > 0, | ||
})) */ | ||
|
||
return { | ||
fetchOverviewData, | ||
overviewData, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { | ||
GetValidatorDashboardSlotVizResponse, | ||
SlotVizEpoch, | ||
} from '~/types/api/slot_viz' | ||
import type { DashboardKey } from '~/types/dashboard' | ||
import { API_PATH } from '~/types/customFetch' | ||
|
||
export function useValidatorSlotViz() { | ||
const { fetch } = useCustomFetch() | ||
|
||
// State | ||
const slotVizData = ref<SlotVizEpoch[]>() // Renamed `data` to `slotVizData` for clarity | ||
|
||
// Actions | ||
async function fetchSlotVizData(dashboardKey: DashboardKey, groupIds?: number[]) { | ||
const query = groupIds?.length ? { group_ids: groupIds.join(',') } : undefined | ||
|
||
const res = await fetch<GetValidatorDashboardSlotVizResponse>( | ||
API_PATH.DASHBOARD_SLOTVIZ, | ||
{ | ||
headers: {}, | ||
query, | ||
}, | ||
{ dashboardKey: dashboardKey || 'MQ' }, // If guest dashboard has no validators yet (= empty dashboardKey), load small guest dashboard with 1 validator (MQ) | ||
) | ||
const data = res.data | ||
if (!dashboardKey) { | ||
data.forEach((epoch) => { | ||
epoch.slots?.forEach((slot) => { | ||
Object.assign(slot, { | ||
attestations: undefined, proposal: undefined, slashing: undefined, sync: undefined, | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
return data | ||
} | ||
|
||
return { | ||
fetchSlotVizData, | ||
slotVizData, | ||
} | ||
} |
Oops, something went wrong.