From 8e4d31f224619179073b39d6e88bdb58e1f3b792 Mon Sep 17 00:00:00 2001 From: LUCCA DUKIC <109136188+LuccaBitfly@users.noreply.github.com> Date: Thu, 19 Sep 2024 10:33:40 +0200 Subject: [PATCH 1/3] (BEDS-501) add enabled flag to all thresholds --- backend/pkg/api/types/notifications.go | 31 +++++++++++++++++--------- frontend/types/api/notifications.ts | 29 +++++++++++++++--------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/backend/pkg/api/types/notifications.go b/backend/pkg/api/types/notifications.go index f183988b1..62eda01dd 100644 --- a/backend/pkg/api/types/notifications.go +++ b/backend/pkg/api/types/notifications.go @@ -141,9 +141,12 @@ type InternalGetUserNotificationNetworksResponse ApiPagingResponse[NotificationN // ------------------------------------------------------------ // Notification Settings type NotificationSettingsNetwork struct { - GasAboveThreshold decimal.Decimal `json:"gas_above_threshold" faker:"eth"` // 0 is disabled - GasBelowThreshold decimal.Decimal `json:"gas_below_threshold" faker:"eth"` // 0 is disabled - ParticipationRateThreshold float64 `json:"participation_rate_threshold" faker:"boundary_start=0, boundary_end=1"` // 0 is disabled + IsGasAboveEnabled bool `json:"is_gas_above_threshold_enabled"` + GasAboveThreshold decimal.Decimal `json:"gas_above_threshold" faker:"eth"` + IsGasBelowEnabled bool `json:"is_gas_below_threshold_enabled"` + GasBelowThreshold decimal.Decimal `json:"gas_below_threshold" faker:"eth"` + IsParticipationRateEnabled bool `json:"is_participation_rate_threshold_enabled"` + ParticipationRateThreshold float64 `json:"participation_rate_threshold" faker:"boundary_start=0, boundary_end=1"` } type NotificationNetwork struct { ChainId uint64 `json:"chain_id"` @@ -164,15 +167,20 @@ type NotificationSettingsGeneral struct { IsEmailNotificationsEnabled bool `json:"is_email_notifications_enabled"` IsPushNotificationsEnabled bool `json:"is_push_notifications_enabled"` - IsMachineOfflineSubscribed bool `json:"is_machine_offline_subscribed"` - MachineStorageUsageThreshold float64 `json:"machine_storage_usage_threshold" faker:"boundary_start=0, boundary_end=1"` // 0 means disabled - MachineCpuUsageThreshold float64 `json:"machine_cpu_usage_threshold" faker:"boundary_start=0, boundary_end=1"` // 0 means disabled - MachineMemoryUsageThreshold float64 `json:"machine_memory_usage_threshold" faker:"boundary_start=0, boundary_end=1"` // 0 means disabled + IsMachineOfflineSubscribed bool `json:"is_machine_offline_subscribed"` + IsMachineStorageUsageSubscribed bool `json:"is_machine_storage_usage_subscribed"` + MachineStorageUsageThreshold float64 `json:"machine_storage_usage_threshold" faker:"boundary_start=0, boundary_end=1"` + IsMachineCpuUsageSubscribed bool `json:"is_machine_cpu_usage_subscribed"` + 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"` SubscribedClients []string `json:"subscribed_clients"` IsRocketPoolNewRewardRoundSubscribed bool `json:"is_rocket_pool_new_reward_round_subscribed"` - RocketPoolMaxCollateralThreshold float64 `json:"rocket_pool_max_collateral_threshold" faker:"boundary_start=0, boundary_end=1"` // 0 means disabled - RocketPoolMinCollateralThreshold float64 `json:"rocket_pool_min_collateral_threshold" faker:"boundary_start=0, boundary_end=1"` // 0 means disabled + 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 { @@ -188,7 +196,8 @@ type NotificationSettingsValidatorDashboard struct { IsRealTimeModeEnabled bool `json:"is_real_time_mode_enabled"` IsValidatorOfflineSubscribed bool `json:"is_validator_offline_subscribed"` - GroupOfflineThreshold float64 `json:"group_offline_threshold" faker:"boundary_start=0, boundary_end=1"` // 0 is disabled + IsGroupOfflineSubscribed bool `json:"is_group_offline_subscribed"` + GroupOfflineThreshold float64 `json:"group_offline_threshold" faker:"boundary_start=0, boundary_end=1"` IsAttestationsMissedSubscribed bool `json:"is_attestations_missed_subscribed"` IsBlockProposalSubscribed bool `json:"is_block_proposal_subscribed"` IsUpcomingBlockProposalSubscribed bool `json:"is_upcoming_block_proposal_subscribed"` @@ -208,7 +217,7 @@ type NotificationSettingsAccountDashboard struct { IsIncomingTransactionsSubscribed bool `json:"is_incoming_transactions_subscribed"` IsOutgoingTransactionsSubscribed bool `json:"is_outgoing_transactions_subscribed"` IsERC20TokenTransfersSubscribed bool `json:"is_erc20_token_transfers_subscribed"` - ERC20TokenTransfersValueThreshold float64 `json:"erc20_token_transfers_value_threshold" faker:"boundary_start=0, boundary_end=1000000"` // 0 does not disable, is_erc20_token_transfers_subscribed determines if it's enabled + ERC20TokenTransfersValueThreshold float64 `json:"erc20_token_transfers_value_threshold" faker:"boundary_start=0, boundary_end=1000000"` IsERC721TokenTransfersSubscribed bool `json:"is_erc721_token_transfers_subscribed"` IsERC1155TokenTransfersSubscribed bool `json:"is_erc1155_token_transfers_subscribed"` } diff --git a/frontend/types/api/notifications.ts b/frontend/types/api/notifications.ts index e22be1d6a..b3bbf0212 100644 --- a/frontend/types/api/notifications.ts +++ b/frontend/types/api/notifications.ts @@ -137,9 +137,12 @@ export type InternalGetUserNotificationNetworksResponse = ApiPagingResponse; export interface NotificationSettings { @@ -178,7 +186,8 @@ export interface NotificationSettingsValidatorDashboard { is_webhook_discord_enabled: boolean; is_real_time_mode_enabled: boolean; is_validator_offline_subscribed: boolean; - group_offline_threshold: number /* float64 */; // 0 is disabled + is_group_offline_subscribed: boolean; + group_offline_threshold: number /* float64 */; is_attestations_missed_subscribed: boolean; is_block_proposal_subscribed: boolean; is_upcoming_block_proposal_subscribed: boolean; @@ -195,7 +204,7 @@ export interface NotificationSettingsAccountDashboard { is_incoming_transactions_subscribed: boolean; is_outgoing_transactions_subscribed: boolean; is_erc20_token_transfers_subscribed: boolean; - erc20_token_transfers_value_threshold: number /* float64 */; // 0 does not disable, is_erc20_token_transfers_subscribed determines if it's enabled + erc20_token_transfers_value_threshold: number /* float64 */; is_erc721_token_transfers_subscribed: boolean; is_erc1155_token_transfers_subscribed: boolean; } From e77d032ad5cfd42dd7828bcbfdd580342de30a9d Mon Sep 17 00:00:00 2001 From: LUCCA DUKIC <109136188+LuccaBitfly@users.noreply.github.com> Date: Thu, 19 Sep 2024 10:36:21 +0200 Subject: [PATCH 2/3] (BEDS-501) better wording --- backend/pkg/api/types/notifications.go | 12 ++++++------ frontend/types/api/notifications.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/backend/pkg/api/types/notifications.go b/backend/pkg/api/types/notifications.go index 62eda01dd..27bf585be 100644 --- a/backend/pkg/api/types/notifications.go +++ b/backend/pkg/api/types/notifications.go @@ -141,12 +141,12 @@ type InternalGetUserNotificationNetworksResponse ApiPagingResponse[NotificationN // ------------------------------------------------------------ // Notification Settings type NotificationSettingsNetwork struct { - IsGasAboveEnabled bool `json:"is_gas_above_threshold_enabled"` - GasAboveThreshold decimal.Decimal `json:"gas_above_threshold" faker:"eth"` - IsGasBelowEnabled bool `json:"is_gas_below_threshold_enabled"` - GasBelowThreshold decimal.Decimal `json:"gas_below_threshold" faker:"eth"` - IsParticipationRateEnabled bool `json:"is_participation_rate_threshold_enabled"` - ParticipationRateThreshold float64 `json:"participation_rate_threshold" faker:"boundary_start=0, boundary_end=1"` + IsGasAboveSubscribed bool `json:"is_gas_above_subscribed"` + GasAboveThreshold decimal.Decimal `json:"gas_above_threshold" faker:"eth"` + IsGasBelowSubscribed bool `json:"is_gas_below_subscribed"` + 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"` } type NotificationNetwork struct { ChainId uint64 `json:"chain_id"` diff --git a/frontend/types/api/notifications.ts b/frontend/types/api/notifications.ts index b3bbf0212..0d9f53898 100644 --- a/frontend/types/api/notifications.ts +++ b/frontend/types/api/notifications.ts @@ -137,11 +137,11 @@ export type InternalGetUserNotificationNetworksResponse = ApiPagingResponse Date: Thu, 19 Sep 2024 10:43:33 +0200 Subject: [PATCH 3/3] (BEDS-501) defeat frontend typecheck --- backend/pkg/api/handlers/common.go | 7 ++----- frontend/components/playground/PlaygroundDialog.vue | 1 + frontend/utils/mock.ts | 5 +++++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/pkg/api/handlers/common.go b/backend/pkg/api/handlers/common.go index a2c68cf24..ca7c41bb1 100644 --- a/backend/pkg/api/handlers/common.go +++ b/backend/pkg/api/handlers/common.go @@ -2,6 +2,7 @@ package handlers import ( "bytes" + "cmp" "context" "encoding/base64" "encoding/json" @@ -477,11 +478,7 @@ func (v *validationError) checkValidatorDashboardPublicId(publicId string) types return types.VDBIdPublic(v.checkRegex(reValidatorDashboardPublicId, publicId, "public_dashboard_id")) } -type number interface { - uint64 | int64 | float64 -} - -func checkMinMax[T number](v *validationError, param T, min T, max T, paramName string) T { +func checkMinMax[T cmp.Ordered](v *validationError, param T, min T, max T, paramName string) T { if param < min { v.add(paramName, fmt.Sprintf("given value '%v' is too small, minimum value is %v", param, min)) } diff --git a/frontend/components/playground/PlaygroundDialog.vue b/frontend/components/playground/PlaygroundDialog.vue index 72c8d4082..b9d2c3c35 100644 --- a/frontend/components/playground/PlaygroundDialog.vue +++ b/frontend/components/playground/PlaygroundDialog.vue @@ -34,6 +34,7 @@ const validatorSub: NotificationSettingsValidatorDashboard = { group_offline_threshold: 0, // means "deactivated/unchecked" is_attestations_missed_subscribed: true, is_block_proposal_subscribed: true, + is_group_offline_subscribed: true, is_real_time_mode_enabled: false, is_slashed_subscribed: false, is_sync_subscribed: true, diff --git a/frontend/utils/mock.ts b/frontend/utils/mock.ts index e1c25fef2..f942d8fbb 100644 --- a/frontend/utils/mock.ts +++ b/frontend/utils/mock.ts @@ -446,8 +446,13 @@ export function mockManageNotificationsGeneral(): InternalGetUserNotificationSet general_settings: { do_not_disturb_timestamp: 9000, is_email_notifications_enabled: false, + is_machine_cpu_usage_subscribed: true, + is_machine_memory_usage_subscribed: true, is_machine_offline_subscribed: true, + is_machine_storage_usage_subscribed: true, is_push_notifications_enabled: true, + is_rocket_pool_max_collateral_subscribed: true, + is_rocket_pool_min_collateral_subscribed: true, is_rocket_pool_new_reward_round_subscribed: true, machine_cpu_usage_threshold: 40, machine_memory_usage_threshold: 50,