Skip to content

Commit

Permalink
(BEDS-501) add enabled flag to all thresholds (#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuccaBitfly authored Sep 19, 2024
1 parent b261d85 commit 62d7b22
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
7 changes: 2 additions & 5 deletions backend/pkg/api/handlers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handlers

import (
"bytes"
"cmp"
"context"
"encoding/base64"
"encoding/json"
Expand Down Expand Up @@ -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))
}
Expand Down
31 changes: 20 additions & 11 deletions backend/pkg/api/types/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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"`
Expand All @@ -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 {
Expand All @@ -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"`
Expand All @@ -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"`
}
Expand Down
1 change: 1 addition & 0 deletions frontend/components/playground/PlaygroundDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 19 additions & 10 deletions frontend/types/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ export type InternalGetUserNotificationNetworksResponse = ApiPagingResponse<Noti
* Notification Settings
*/
export interface NotificationSettingsNetwork {
gas_above_threshold: string /* decimal.Decimal */; // 0 is disabled
gas_below_threshold: string /* decimal.Decimal */; // 0 is disabled
participation_rate_threshold: number /* float64 */; // 0 is disabled
is_gas_above_subscribed: boolean;
gas_above_threshold: string /* decimal.Decimal */;
is_gas_below_subscribed: boolean;
gas_below_threshold: string /* decimal.Decimal */;
is_participation_rate_subscribed: boolean;
participation_rate_threshold: number /* float64 */;
}
export interface NotificationNetwork {
chain_id: number /* uint64 */;
Expand All @@ -158,13 +161,18 @@ export interface NotificationSettingsGeneral {
is_email_notifications_enabled: boolean;
is_push_notifications_enabled: boolean;
is_machine_offline_subscribed: boolean;
machine_storage_usage_threshold: number /* float64 */; // 0 means disabled
machine_cpu_usage_threshold: number /* float64 */; // 0 means disabled
machine_memory_usage_threshold: number /* float64 */; // 0 means disabled
is_machine_storage_usage_subscribed: boolean;
machine_storage_usage_threshold: number /* float64 */;
is_machine_cpu_usage_subscribed: boolean;
machine_cpu_usage_threshold: number /* float64 */;
is_machine_memory_usage_subscribed: boolean;
machine_memory_usage_threshold: number /* float64 */;
subscribed_clients: string[];
is_rocket_pool_new_reward_round_subscribed: boolean;
rocket_pool_max_collateral_threshold: number /* float64 */; // 0 means disabled
rocket_pool_min_collateral_threshold: number /* float64 */; // 0 means disabled
is_rocket_pool_max_collateral_subscribed: boolean;
rocket_pool_max_collateral_threshold: number /* float64 */;
is_rocket_pool_min_collateral_subscribed: boolean;
rocket_pool_min_collateral_threshold: number /* float64 */;
}
export type InternalPutUserNotificationSettingsGeneralResponse = ApiDataResponse<NotificationSettingsGeneral>;
export interface NotificationSettings {
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions frontend/utils/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 62d7b22

Please sign in to comment.