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

(BEDS-510) adapt structs to design #903

Merged
merged 3 commits into from
Oct 1, 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
2 changes: 1 addition & 1 deletion backend/pkg/api/data_access/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func (d *DummyService) GetClientNotifications(ctx context.Context, userId uint64
func (d *DummyService) GetRocketPoolNotifications(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationRocketPoolColumn], search string, limit uint64) ([]t.NotificationRocketPoolTableRow, *t.Paging, error) {
return getDummyWithPaging[t.NotificationRocketPoolTableRow]()
}
func (d *DummyService) GetNetworkNotifications(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationNetworksColumn], search string, limit uint64) ([]t.NotificationNetworksTableRow, *t.Paging, error) {
func (d *DummyService) GetNetworkNotifications(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationNetworksColumn], limit uint64) ([]t.NotificationNetworksTableRow, *t.Paging, error) {
return getDummyWithPaging[t.NotificationNetworksTableRow]()
}

Expand Down
6 changes: 3 additions & 3 deletions backend/pkg/api/data_access/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type NotificationsRepository interface {
GetMachineNotifications(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationMachinesColumn], search string, limit uint64) ([]t.NotificationMachinesTableRow, *t.Paging, error)
GetClientNotifications(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationClientsColumn], search string, limit uint64) ([]t.NotificationClientsTableRow, *t.Paging, error)
GetRocketPoolNotifications(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationRocketPoolColumn], search string, limit uint64) ([]t.NotificationRocketPoolTableRow, *t.Paging, error)
GetNetworkNotifications(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationNetworksColumn], search string, limit uint64) ([]t.NotificationNetworksTableRow, *t.Paging, error)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also removed search from network notifications table, since it was removed in the design

GetNetworkNotifications(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationNetworksColumn], limit uint64) ([]t.NotificationNetworksTableRow, *t.Paging, error)

GetNotificationSettings(ctx context.Context, userId uint64) (*t.NotificationSettings, error)
UpdateNotificationSettingsGeneral(ctx context.Context, userId uint64, settings t.NotificationSettingsGeneral) error
Expand Down Expand Up @@ -55,8 +55,8 @@ func (d *DataAccessService) GetClientNotifications(ctx context.Context, userId u
func (d *DataAccessService) GetRocketPoolNotifications(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationRocketPoolColumn], search string, limit uint64) ([]t.NotificationRocketPoolTableRow, *t.Paging, error) {
return d.dummy.GetRocketPoolNotifications(ctx, userId, cursor, colSort, search, limit)
}
func (d *DataAccessService) GetNetworkNotifications(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationNetworksColumn], search string, limit uint64) ([]t.NotificationNetworksTableRow, *t.Paging, error) {
return d.dummy.GetNetworkNotifications(ctx, userId, cursor, colSort, search, limit)
func (d *DataAccessService) GetNetworkNotifications(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationNetworksColumn], limit uint64) ([]t.NotificationNetworksTableRow, *t.Paging, error) {
return d.dummy.GetNetworkNotifications(ctx, userId, cursor, colSort, limit)
}
func (d *DataAccessService) GetNotificationSettings(ctx context.Context, userId uint64) (*t.NotificationSettings, error) {
return d.dummy.GetNotificationSettings(ctx, userId)
Expand Down
14 changes: 8 additions & 6 deletions backend/pkg/api/handlers/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ func (h *HandlerService) PublicGetUserNotificationClients(w http.ResponseWriter,
// @Param cursor query string false "Return data for the given cursor value. Pass the `paging.next_cursor`` value of the previous response to navigate to forward, or pass the `paging.prev_cursor`` value of the previous response to navigate to backward."
// @Param limit query integer false "The maximum number of results that may be returned."
// @Param sort query string false "The field you want to sort by. Append with `:desc` for descending order." Enums(timestamp, event_type, node_address)
// @Param search query string false "Search for TODO"
// @Param search query string false "Search for Node Address"
// @Success 200 {object} types.InternalGetUserNotificationRocketPoolResponse
// @Failure 400 {object} types.ApiErrorResponse
// @Router /users/me/notifications/rocket-pool [get]
Expand Down Expand Up @@ -2138,7 +2138,6 @@ func (h *HandlerService) PublicGetUserNotificationRocketPool(w http.ResponseWrit
// @Param cursor query string false "Return data for the given cursor value. Pass the `paging.next_cursor`` value of the previous response to navigate to forward, or pass the `paging.prev_cursor`` value of the previous response to navigate to backward."
// @Param limit query integer false "The maximum number of results that may be returned."
// @Param sort query string false "The field you want to sort by. Append with `:desc` for descending order." Enums(timestamp, event_type)
// @Param search query string false "Search for TODO"
// @Success 200 {object} types.InternalGetUserNotificationNetworksResponse
// @Failure 400 {object} types.ApiErrorResponse
// @Router /users/me/notifications/networks [get]
Expand All @@ -2156,7 +2155,7 @@ func (h *HandlerService) PublicGetUserNotificationNetworks(w http.ResponseWriter
handleErr(w, r, v)
return
}
data, paging, err := h.dai.GetNetworkNotifications(r.Context(), userId, pagingParams.cursor, *sort, pagingParams.search, pagingParams.limit)
data, paging, err := h.dai.GetNetworkNotifications(r.Context(), userId, pagingParams.cursor, *sort, pagingParams.limit)
if err != nil {
handleErr(w, r, err)
return
Expand Down Expand Up @@ -2219,8 +2218,6 @@ func (h *HandlerService) PublicPutUserNotificationSettingsGeneral(w http.Respons
checkMinMax(&v, req.MachineStorageUsageThreshold, 0, 1, "machine_storage_usage_threshold")
checkMinMax(&v, req.MachineCpuUsageThreshold, 0, 1, "machine_cpu_usage_threshold")
checkMinMax(&v, req.MachineMemoryUsageThreshold, 0, 1, "machine_memory_usage_threshold")
checkMinMax(&v, req.RocketPoolMaxCollateralThreshold, 0, 1, "rocket_pool_max_collateral_threshold")
checkMinMax(&v, req.RocketPoolMinCollateralThreshold, 0, 1, "rocket_pool_min_collateral_threshold")
if v.hasErrors() {
handleErr(w, r, v)
return
Expand Down Expand Up @@ -2261,7 +2258,8 @@ func (h *HandlerService) PublicPutUserNotificationSettingsNetworks(w http.Respon
IsGasBelowSubscribed bool `json:"is_gas_below_subscribed"`
GasBelowThreshold string `json:"gas_below_threshold" `
IsParticipationRateSubscribed bool `json:"is_participation_rate_subscribed"`
ParticipationRateThreshold float64 `json:"participation_rate_threshold" faker:"boundary_start=0, boundary_end=1"`
ParticipationRateThreshold float64 `json:"participation_rate_threshold"`
IsNewRewardRoundSubscribed bool `json:"is_new_reward_round_subscribed"`
}
var req request
if err := v.checkBody(&req, r); err != nil {
Expand All @@ -2286,6 +2284,7 @@ func (h *HandlerService) PublicPutUserNotificationSettingsNetworks(w http.Respon
GasBelowThreshold: gasBelowThreshold,
IsParticipationRateSubscribed: req.IsParticipationRateSubscribed,
ParticipationRateThreshold: req.ParticipationRateThreshold,
IsNewRewardRoundSubscribed: req.IsNewRewardRoundSubscribed,
}

err = h.dai.UpdateNotificationSettingsNetworks(r.Context(), userId, chainId, settings)
Expand Down Expand Up @@ -2491,6 +2490,9 @@ func (h *HandlerService) PublicPutUserNotificationSettingsValidatorDashboard(w h
vars := mux.Vars(r)
dashboardId := v.checkPrimaryDashboardId(vars["dashboard_id"])
groupId := v.checkExistingGroupId(vars["group_id"])

checkMinMax(&v, req.MaxCollateralThreshold, 0, 1, "max_collateral_threshold")
checkMinMax(&v, req.MinCollateralThreshold, 0, 1, "min_collateral_threshold")
if v.hasErrors() {
handleErr(w, r, v)
return
Expand Down
44 changes: 22 additions & 22 deletions backend/pkg/api/types/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ type NotificationOverviewData struct {
Last24hWebhookCount uint64 `json:"last_24h_webhook_count"`

// counts are shown in their respective tables
VDBSubscriptionsCount uint64 `json:"vdb_subscriptions_count"`
ADBSubscriptionsCount uint64 `json:"adb_subscriptions_count"`
MachinesSubscriptionCount uint64 `json:"machines_subscription_count"`
ClientsSubscriptionCount uint64 `json:"clients_subscription_count"`
RocketPoolSubscriptionCount uint64 `json:"rocket_pool_subscription_count"`
NetworksSubscriptionCount uint64 `json:"networks_subscription_count"`
VDBSubscriptionsCount uint64 `json:"vdb_subscriptions_count"`
ADBSubscriptionsCount uint64 `json:"adb_subscriptions_count"`
MachinesSubscriptionCount uint64 `json:"machines_subscription_count"`
ClientsSubscriptionCount uint64 `json:"clients_subscription_count"`
NetworksSubscriptionCount uint64 `json:"networks_subscription_count"`
}

type InternalGetUserNotificationsResponse ApiDataResponse[NotificationOverviewData]
Expand All @@ -37,7 +36,7 @@ type NotificationDashboardsTableRow struct {
GroupName string `json:"group_name"`
NotificationId uint64 `json:"notification_id"` // may be string? db schema is not defined afaik
EntityCount uint64 `json:"entity_count"`
EventTypes []string `json:"event_types" tstype:"('validator_online' | 'validator_offline' | 'group_online' | 'group_offline' | 'attestation_missed' | 'proposal_success' | 'proposal_missed' | 'proposal_upcoming' | 'sync' | 'withdrawal' | 'got_slashed' | 'has_slashed' | 'incoming_tx' | 'outgoing_tx' | 'transfer_erc20' | 'transfer_erc721' | 'transfer_erc1155')[]" faker:"oneof: validator_offline, group_offline, attestation_missed, proposal_success, proposal_missed, proposal_upcoming, sync, withdrawal, slashed_own, incoming_tx, outgoing_tx, transfer_erc20, transfer_erc721, transfer_erc1155"`
EventTypes []string `json:"event_types" tstype:"('validator_online' | 'validator_offline' | 'group_online' | 'group_offline' | 'attestation_missed' | 'proposal_success' | 'proposal_missed' | 'proposal_upcoming' | 'max_collateral' | 'min_collateral' | 'sync' | 'withdrawal' | 'got_slashed' | 'has_slashed' | 'incoming_tx' | 'outgoing_tx' | 'transfer_erc20' | 'transfer_erc721' | 'transfer_erc1155')[]" faker:"oneof: validator_offline, group_offline, attestation_missed, proposal_success, proposal_missed, proposal_upcoming, max_collateral, min_collateral, sync, withdrawal, slashed_own, incoming_tx, outgoing_tx, transfer_erc20, transfer_erc721, transfer_erc1155"`
}

type InternalGetUserNotificationDashboardsResponse ApiPagingResponse[NotificationDashboardsTableRow]
Expand Down Expand Up @@ -74,6 +73,7 @@ type NotificationValidatorDashboardDetail struct {
GroupOfflineReminder []NotificationEventGroup `json:"group_offline_reminder"`
ValidatorBackOnline []NotificationEventValidatorBackOnline `json:"validator_back_online"`
GroupBackOnline []NotificationEventGroupBackOnline `json:"group_back_online"`
// TODO min and max collateral events
}

type InternalGetUserNotificationsValidatorDashboardResponse ApiDataResponse[NotificationValidatorDashboardDetail]
Expand All @@ -99,7 +99,7 @@ type InternalGetUserNotificationsAccountDashboardResponse ApiDataResponse[Notifi
// Machines Table
type NotificationMachinesTableRow struct {
MachineName string `json:"machine_name"`
Threshold float64 `json:"threshold" faker:"boundary_start=0, boundary_end=1"`
Threshold float64 `json:"threshold,omitempty" faker:"boundary_start=0, boundary_end=1"`
EventType string `json:"event_type" tstype:"'offline' | 'storage' | 'cpu' | 'memory'" faker:"oneof: offline, storage, cpu, memory"`
Timestamp int64 `json:"timestamp"`
}
Expand All @@ -120,21 +120,21 @@ type InternalGetUserNotificationClientsResponse ApiPagingResponse[NotificationCl
// ------------------------------------------------------------
// Rocket Pool Table
type NotificationRocketPoolTableRow struct {
Timestamp int64 `json:"timestamp"`
EventType string `json:"event_type" tstype:"'reward_round' | 'collateral_max' | 'collateral_min'" faker:"oneof: reward_round, collateral_max, collateral_min"`
AlertValue float64 `json:"alert_value,omitempty"` // only for some notification types, e.g. max collateral
Node Address `json:"node"`
Timestamp int64 `json:"timestamp"`
EventType string `json:"event_type" tstype:"'reward_round' | 'collateral_max' | 'collateral_min'" faker:"oneof: reward_round, collateral_max, collateral_min"`
Threshold float64 `json:"threshold,omitempty"` // only for some notification types, e.g. max collateral
Node Address `json:"node"`
}

type InternalGetUserNotificationRocketPoolResponse ApiPagingResponse[NotificationRocketPoolTableRow]

// ------------------------------------------------------------
// Networks Table
type NotificationNetworksTableRow struct {
ChainId uint64 `json:"chain_id"`
Timestamp int64 `json:"timestamp"`
EventType string `json:"event_type" tstype:"'gas_above' | 'gas_below' | 'participation_rate'" faker:"oneof: gas_above, gas_below, participation_rate"`
AlertValue decimal.Decimal `json:"alert_value"` // wei string for gas alerts, otherwise percentage (0-1) for participation rate
ChainId uint64 `json:"chain_id"`
Timestamp int64 `json:"timestamp"`
EventType string `json:"event_type" tstype:"'new_reward_round' | 'gas_above' | 'gas_below' | 'participation_rate'" faker:"oneof: new_reward_round, gas_above, gas_below, participation_rate"`
Threshold decimal.Decimal `json:"threshold,omitempty"` // participation rate threshold should also be passed as decimal string
}

type InternalGetUserNotificationNetworksResponse ApiPagingResponse[NotificationNetworksTableRow]
Expand All @@ -148,6 +148,7 @@ type NotificationSettingsNetwork struct {
GasBelowThreshold decimal.Decimal `json:"gas_below_threshold" faker:"eth"`
IsParticipationRateSubscribed bool `json:"is_participation_rate_subscribed"`
ParticipationRateThreshold float64 `json:"participation_rate_threshold" faker:"boundary_start=0, boundary_end=1"`
IsNewRewardRoundSubscribed bool `json:"is_new_reward_round_subscribed"`
}
type NotificationNetwork struct {
ChainId uint64 `json:"chain_id"`
Expand Down Expand Up @@ -184,12 +185,6 @@ type NotificationSettingsGeneral struct {
MachineCpuUsageThreshold float64 `json:"machine_cpu_usage_threshold" faker:"boundary_start=0, boundary_end=1"`
IsMachineMemoryUsageSubscribed bool `json:"is_machine_memory_usage_subscribed"`
MachineMemoryUsageThreshold float64 `json:"machine_memory_usage_threshold" faker:"boundary_start=0, boundary_end=1"`

IsRocketPoolNewRewardRoundSubscribed bool `json:"is_rocket_pool_new_reward_round_subscribed"`
IsRocketPoolMaxCollateralSubscribed bool `json:"is_rocket_pool_max_collateral_subscribed"`
RocketPoolMaxCollateralThreshold float64 `json:"rocket_pool_max_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
IsRocketPoolMinCollateralSubscribed bool `json:"is_rocket_pool_min_collateral_subscribed"`
RocketPoolMinCollateralThreshold float64 `json:"rocket_pool_min_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
}
type InternalPutUserNotificationSettingsGeneralResponse ApiDataResponse[NotificationSettingsGeneral]
type NotificationSettings struct {
Expand All @@ -215,6 +210,11 @@ type NotificationSettingsValidatorDashboard struct {
IsSyncSubscribed bool `json:"is_sync_subscribed"`
IsWithdrawalProcessedSubscribed bool `json:"is_withdrawal_processed_subscribed"`
IsSlashedSubscribed bool `json:"is_slashed_subscribed"`

IsMaxCollateralSubscribed bool `json:"is_max_collateral_subscribed"`
MaxCollateralThreshold float64 `json:"max_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
IsMinCollateralSubscribed bool `json:"is_min_collateral_subscribed"`
MinCollateralThreshold float64 `json:"min_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
}

type InternalPutUserNotificationSettingsValidatorDashboardResponse ApiDataResponse[NotificationSettingsValidatorDashboard]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const {
setSearch,
} = useNotificationsRocketpoolStore()
const { overview } = useNotificationsDashboardOverviewStore()
const { width } = useWindowSize()
const colsVisible = computed(() => {
return {
Expand Down Expand Up @@ -118,12 +116,6 @@ const getEventTypeName = (eventType: NotificationRocketPoolTableRow['event_type'
@open-dialog="$emit('openDialog')"
/>
</template>
<template
v-if="overview?.rocket_pool_subscription_count ?? 0"
#bc-table-footer-right
>
{{ $t('notifications.rocketpool.col.rocketpool_subscription', { count: overview?.rocket_pool_subscription_count }) }}
</template>
</BcTable>
</ClientOnly>
</template>
Expand Down
4 changes: 4 additions & 0 deletions frontend/components/playground/PlaygroundDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ const validatorSub: NotificationSettingsValidatorDashboard = {
is_attestations_missed_subscribed: true,
is_block_proposal_subscribed: true,
is_group_offline_subscribed: true,
is_max_collateral_subscribed: false,
is_min_collateral_subscribed: false,
is_real_time_mode_enabled: false,
is_slashed_subscribed: false,
is_sync_subscribed: true,
is_upcoming_block_proposal_subscribed: false,
is_validator_offline_subscribed: true,
is_webhook_discord_enabled: true,
is_withdrawal_processed_subscribed: true,
max_collateral_threshold: 0,
min_collateral_threshold: 0,
webhook_url: 'http://bablabla',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ export const useNotificationsManagementStore = defineStore('notifications-manage
is_machine_offline_subscribed: false,
is_machine_storage_usage_subscribed: false,
is_push_notifications_enabled: false,
is_rocket_pool_max_collateral_subscribed: false,
is_rocket_pool_min_collateral_subscribed: false,
is_rocket_pool_new_reward_round_subscribed: false,
machine_cpu_usage_threshold: 0.0,
machine_memory_usage_threshold: 0.0,
machine_storage_usage_threshold: 0.0,
rocket_pool_max_collateral_threshold: 0,
rocket_pool_min_collateral_threshold: 0,
},
has_machines: true,
networks: [],
Expand Down
Loading
Loading