Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: match dashboard notification detail to notification event name #1105

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions backend/pkg/api/data_access/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,16 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
notificationDetails := t.NotificationValidatorDashboardDetail{
ValidatorOffline: []uint64{},
ProposalMissed: []t.IndexSlots{},
ProposalDone: []t.IndexBlocks{},
UpcomingProposals: []t.IndexSlots{},
ProposalSuccess: []t.IndexBlocks{},
ProposalUpcoming: []t.IndexSlots{},
Slashed: []uint64{},
SyncCommittee: []uint64{},
Sync: []uint64{},
AttestationMissed: []t.IndexEpoch{},
Withdrawal: []t.NotificationEventWithdrawal{},
ValidatorOfflineReminder: []uint64{},
ValidatorBackOnline: []t.NotificationEventValidatorBackOnline{},
MinimumCollateralReached: []t.Address{},
MaximumCollateralReached: []t.Address{},
ValidatorOnline: []t.NotificationEventValidatorBackOnline{},
MinCollateral: []t.Address{},
MaxCollateral: []t.Address{},
}

var searchIndices []uint64
Expand Down Expand Up @@ -554,7 +554,7 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
if searchEnabled && !searchIndexSet[curNotification.ValidatorIndex] {
continue
}
notificationDetails.UpcomingProposals = append(notificationDetails.UpcomingProposals, t.IndexSlots{Index: curNotification.ValidatorIndex, Slots: []uint64{curNotification.Slot}})
notificationDetails.ProposalUpcoming = append(notificationDetails.ProposalUpcoming, t.IndexSlots{Index: curNotification.ValidatorIndex, Slots: []uint64{curNotification.Slot}})
case types.ValidatorGotSlashedEventName:
curNotification, ok := notification.(*n.ValidatorGotSlashedNotification)
if !ok {
Expand Down Expand Up @@ -583,7 +583,7 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
if searchEnabled && !searchIndexSet[curNotification.ValidatorIndex] {
continue
}
notificationDetails.ValidatorBackOnline = append(notificationDetails.ValidatorBackOnline, t.NotificationEventValidatorBackOnline{Index: curNotification.ValidatorIndex, EpochCount: curNotification.Epoch})
notificationDetails.ValidatorOnline = append(notificationDetails.ValidatorOnline, t.NotificationEventValidatorBackOnline{Index: curNotification.ValidatorIndex, EpochCount: curNotification.Epoch})
case types.ValidatorReceivedWithdrawalEventName:
curNotification, ok := notification.(*n.ValidatorWithdrawalNotification)
if !ok {
Expand Down Expand Up @@ -630,9 +630,9 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
addr := t.Address{Hash: t.Hash(nodeAddress), IsContract: true}
addressMapping[nodeAddress] = &addr
if notification.GetEventName() == types.RocketpoolCollateralMinReachedEventName {
notificationDetails.MinimumCollateralReached = append(notificationDetails.MinimumCollateralReached, addr)
notificationDetails.MinCollateral = append(notificationDetails.MinCollateral, addr)
} else {
notificationDetails.MaximumCollateralReached = append(notificationDetails.MaximumCollateralReached, addr)
notificationDetails.MaxCollateral = append(notificationDetails.MaxCollateral, addr)
}
case types.SyncCommitteeSoonEventName:
curNotification, ok := notification.(*n.SyncCommitteeSoonNotification)
Expand All @@ -642,7 +642,7 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
if searchEnabled && !searchIndexSet[curNotification.ValidatorIndex] {
continue
}
notificationDetails.SyncCommittee = append(notificationDetails.SyncCommittee, curNotification.ValidatorIndex)
notificationDetails.Sync = append(notificationDetails.Sync, curNotification.ValidatorIndex)
default:
log.Debugf("Unhandled notification type: %s", notification.GetEventName())
}
Expand All @@ -652,10 +652,10 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
// fill proposals
for validatorIndex, proposalInfo := range proposalsInfo {
if len(proposalInfo.Proposed) > 0 {
notificationDetails.ProposalDone = append(notificationDetails.ProposalDone, t.IndexBlocks{Index: validatorIndex, Blocks: proposalInfo.Proposed})
notificationDetails.ProposalSuccess = append(notificationDetails.ProposalSuccess, t.IndexBlocks{Index: validatorIndex, Blocks: proposalInfo.Proposed})
}
if len(proposalInfo.Scheduled) > 0 {
notificationDetails.UpcomingProposals = append(notificationDetails.UpcomingProposals, t.IndexSlots{Index: validatorIndex, Slots: proposalInfo.Scheduled})
notificationDetails.ProposalUpcoming = append(notificationDetails.ProposalUpcoming, t.IndexSlots{Index: validatorIndex, Slots: proposalInfo.Scheduled})
}
if len(proposalInfo.Missed) > 0 {
notificationDetails.ProposalMissed = append(notificationDetails.ProposalMissed, t.IndexSlots{Index: validatorIndex, Slots: proposalInfo.Missed})
Expand All @@ -674,14 +674,14 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
for i, contractStatus := range contractStatusRequests {
contractStatusPerAddress["0x"+contractStatus.Address] = i
}
for i := range notificationDetails.MinimumCollateralReached {
if address, ok := addressMapping[string(notificationDetails.MinimumCollateralReached[i].Hash)]; ok {
notificationDetails.MinimumCollateralReached[i] = *address
for i := range notificationDetails.MinCollateral {
if address, ok := addressMapping[string(notificationDetails.MinCollateral[i].Hash)]; ok {
notificationDetails.MinCollateral[i] = *address
}
}
for i := range notificationDetails.MaximumCollateralReached {
if address, ok := addressMapping[string(notificationDetails.MaximumCollateralReached[i].Hash)]; ok {
notificationDetails.MaximumCollateralReached[i] = *address
for i := range notificationDetails.MaxCollateral {
if address, ok := addressMapping[string(notificationDetails.MaxCollateral[i].Hash)]; ok {
notificationDetails.MaxCollateral[i] = *address
}
}
for i := range notificationDetails.Withdrawal {
Expand Down
16 changes: 8 additions & 8 deletions backend/pkg/api/types/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ type NotificationEventWithdrawal struct {
type NotificationValidatorDashboardDetail struct {
DashboardName string `db:"dashboard_name" json:"dashboard_name"`
GroupName string `db:"group_name" json:"group_name"`
ValidatorOffline []uint64 `json:"validator_offline"` // validator indices
ValidatorOffline []uint64 `json:"validator_offline"` // validator indices
ValidatorOfflineReminder []uint64 `json:"validator_offline_reminder"` // validator indices; TODO not filled yet
ValidatorOnline []NotificationEventValidatorBackOnline `json:"validator_online"`
GroupEfficiencyBelow float64 `json:"group_efficiency_below,omitempty"` // fill with the `group_efficiency_below` threshold if event is present
ProposalMissed []IndexSlots `json:"proposal_missed"`
ProposalDone []IndexBlocks `json:"proposal_done"`
UpcomingProposals []IndexSlots `json:"upcoming_proposals"`
ProposalSuccess []IndexBlocks `json:"proposal_success"`
ProposalUpcoming []IndexSlots `json:"proposal_upcoming"`
Slashed []uint64 `json:"slashed"` // validator indices
SyncCommittee []uint64 `json:"sync_committee"` // validator indices
Sync []uint64 `json:"sync"` // validator indices
AttestationMissed []IndexEpoch `json:"attestation_missed"` // index (epoch)
Withdrawal []NotificationEventWithdrawal `json:"withdrawal"`
ValidatorOfflineReminder []uint64 `json:"validator_offline_reminder"` // validator indices; TODO not filled yet
ValidatorBackOnline []NotificationEventValidatorBackOnline `json:"validator_back_online"`
MinimumCollateralReached []Address `json:"min_collateral_reached"` // node addresses
MaximumCollateralReached []Address `json:"max_collateral_reached"` // node addresses
MinCollateral []Address `json:"min_collateral"` // node addresses
MaxCollateral []Address `json:"max_collateral"` // node addresses
}

type InternalGetUserNotificationsValidatorDashboardResponse ApiDataResponse[NotificationValidatorDashboardDetail]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.proposal_done?.length"
:items="details?.proposal_done"
v-if="details?.proposal_success?.length"
:items="details?.proposal_success"
:info-copy="$t('notifications.dashboards.dialog.entity.proposal_done')"
>
<template #headingIcon>
Expand All @@ -140,7 +140,7 @@ const formatValueWei = (value: string) => {
/>
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.proposal_done') }} ({{ details?.proposal_done?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.proposal_done') }} ({{ details?.proposal_success?.length ?? 0 }})
</template>
<template #item="{ item: proposalDone }">
<BcLink
Expand Down Expand Up @@ -182,15 +182,15 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.sync_committee?.length"
:items="details?.sync_committee"
v-if="details?.sync?.length"
:items="details?.sync"
:info-copy="$t('notifications.dashboards.dialog.entity.sync_committee')"
>
<template #headingIcon>
<FontAwesomeIcon :icon="faArrowsRotate" class="notifications-dashboard-dialog-entity__icon__green" />
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.sync_committee') }} ({{ details?.sync_committee?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.sync_committee') }} ({{ details?.sync?.length ?? 0 }})
</template>
<template #item="{ item: syncCommitteIndex }">
<BcLink
Expand Down Expand Up @@ -256,8 +256,8 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.validator_back_online?.length"
:items="details?.validator_back_online"
v-if="details?.validator_online?.length"
:items="details?.validator_online"
:info-copy="$t('notifications.dashboards.dialog.entity.validator_back_online')"
>
<template #headingIcon>
Expand All @@ -267,7 +267,7 @@ const formatValueWei = (value: string) => {
/>
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.validator_back_online') }} ({{ details?.validator_back_online?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.validator_back_online') }} ({{ details?.validator_online?.length ?? 0 }})
</template>
<template #item="{ item: validator }">
<BcLink
Expand Down Expand Up @@ -328,8 +328,8 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.upcoming_proposals?.length"
:items="details?.upcoming_proposals"
v-if="details?.proposal_upcoming?.length"
:items="details?.proposal_upcoming"
:info-copy="$t('notifications.dashboards.dialog.entity.upcoming_proposal')"
>
<template #headingIcon>
Expand All @@ -339,7 +339,7 @@ const formatValueWei = (value: string) => {
/>
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.upcoming_proposal') }} ({{ details?.upcoming_proposals?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.upcoming_proposal') }} ({{ details?.proposal_upcoming?.length ?? 0 }})
</template>
<template #item="{ item: upcomingProposal }">
<BcLink
Expand All @@ -361,8 +361,8 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.min_collateral_reached?.length"
:items="details?.min_collateral_reached"
v-if="details?.min_collateral?.length"
:items="details?.min_collateral"
:info-copy="$t('notifications.dashboards.dialog.entity.min_collateral')"
>
<template #headingIcon>
Expand All @@ -372,7 +372,7 @@ const formatValueWei = (value: string) => {
/>
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.min_collateral') }} ({{ details?.min_collateral_reached?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.min_collateral') }} ({{ details?.min_collateral?.length ?? 0 }})
</template>
<template #item="{ item: minCollateral }">
<BcFormatHash
Expand All @@ -387,8 +387,8 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.max_collateral_reached?.length"
:items="details?.max_collateral_reached"
v-if="details?.max_collateral?.length"
:items="details?.max_collateral"
:info-copy="$t('notifications.dashboards.dialog.entity.max_collateral')"
>
<template #headingIcon>
Expand All @@ -398,7 +398,7 @@ const formatValueWei = (value: string) => {
/>
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.max_collateral') }} ({{ details?.max_collateral_reached?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.max_collateral') }} ({{ details?.max_collateral?.length ?? 0 }})
</template>
<template #item="{ item: maxCollateral }">
<BcFormatHash
Expand Down
14 changes: 7 additions & 7 deletions frontend/types/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ export interface NotificationValidatorDashboardDetail {
dashboard_name: string;
group_name: string;
validator_offline: number /* uint64 */[]; // validator indices
validator_offline_reminder: number /* uint64 */[]; // validator indices; TODO not filled yet
validator_online: NotificationEventValidatorBackOnline[];
group_efficiency_below?: number /* float64 */; // fill with the `group_efficiency_below` threshold if event is present
proposal_missed: IndexSlots[];
proposal_done: IndexBlocks[];
upcoming_proposals: IndexSlots[];
proposal_success: IndexBlocks[];
proposal_upcoming: IndexSlots[];
slashed: number /* uint64 */[]; // validator indices
sync_committee: number /* uint64 */[]; // validator indices
sync: number /* uint64 */[]; // validator indices
attestation_missed: IndexEpoch[]; // index (epoch)
withdrawal: NotificationEventWithdrawal[];
validator_offline_reminder: number /* uint64 */[]; // validator indices; TODO not filled yet
validator_back_online: NotificationEventValidatorBackOnline[];
min_collateral_reached: Address[]; // node addresses
max_collateral_reached: Address[]; // node addresses
min_collateral: Address[]; // node addresses
max_collateral: Address[]; // node addresses
}
export type InternalGetUserNotificationsValidatorDashboardResponse = ApiDataResponse<NotificationValidatorDashboardDetail>;
export interface NotificationEventExecution {
Expand Down
Loading