@@ -1339,20 +1339,9 @@ func (d *DataAccessService) UpdateNotificationSettingsGeneral(ctx context.Contex
13391339func (d * DataAccessService ) UpdateNotificationSettingsNetworks (ctx context.Context , userId uint64 , chainId uint64 , settings t.NotificationSettingsNetwork ) error {
13401340 epoch := utils .TimeToEpoch (time .Now ())
13411341
1342- networks , err := d .GetAllNetworks ( )
1342+ networkName , err := d .getNetworkName ( chainId )
13431343 if err != nil {
1344- return err
1345- }
1346-
1347- networkName := ""
1348- for _ , network := range networks {
1349- if network .ChainId == chainId {
1350- networkName = network .NotificationsName
1351- break
1352- }
1353- }
1354- if networkName == "" {
1355- return fmt .Errorf ("network with chain id %d to update general notification settings not found" , chainId )
1344+ return fmt .Errorf ("error getting network name: %w" , err )
13561345 }
13571346
13581347 var eventsToInsert []goqu.Record
@@ -1534,20 +1523,9 @@ func (d *DataAccessService) GetNotificationSettingsDashboards(ctx context.Contex
15341523 Threshold float64 `db:"event_threshold"`
15351524 }{}
15361525
1537- networks , err := d .GetAllNetworks ( )
1526+ networkName , err := d .getNetworkName ( d . config . Chain . ClConfig . DepositChainID )
15381527 if err != nil {
1539- return nil , nil , err
1540- }
1541-
1542- var networkName string
1543- for _ , network := range networks {
1544- if network .ChainId == utils .Config .Chain .ClConfig .DepositChainID {
1545- networkName = network .NotificationsName
1546- break
1547- }
1548- }
1549- if networkName == "" {
1550- return nil , nil , fmt .Errorf ("network with chain id %d to update general notification settings not found" , utils .Config .Chain .ClConfig .DepositChainID )
1528+ return nil , nil , fmt .Errorf ("error getting network name: %w" , err )
15511529 }
15521530
15531531 wg .Go (func () error {
@@ -1895,20 +1873,9 @@ func (d *DataAccessService) UpdateNotificationSettingsValidatorDashboard(ctx con
18951873 return fmt .Errorf ("error getting network for validator dashboard: %w" , err )
18961874 }
18971875
1898- networks , err := d .GetAllNetworks ( )
1876+ networkName , err := d .getNetworkName ( chainId )
18991877 if err != nil {
1900- return err
1901- }
1902-
1903- networkName := ""
1904- for _ , network := range networks {
1905- if network .ChainId == chainId {
1906- networkName = network .NotificationsName
1907- break
1908- }
1909- }
1910- if networkName == "" {
1911- return fmt .Errorf ("network with chain id %d to update general notification settings not found" , chainId )
1878+ return fmt .Errorf ("error getting networ name: %w" , err )
19121879 }
19131880
19141881 // Add and remove the events in users_subscriptions
@@ -2116,14 +2083,49 @@ func (d *DataAccessService) QueueTestWebhookNotification(ctx context.Context, us
21162083// hasUserV1NotificationSubscriptions checks if a user has any v1 notification subscriptions.
21172084// Since some notification events are indistinguishable from v1 and v2, only validator-related that are not v2 are checked.
21182085func (d * DataAccessService ) hasUserV1NotificationSubscriptions (ctx context.Context , userId uint64 ) (bool , error ) {
2086+ // event_name is always prefixed with the network name
2087+ networkName , err := d .getNetworkName (utils .Config .Chain .ClConfig .DepositChainID )
2088+ if err != nil {
2089+ return false , fmt .Errorf ("error getting network name: %w" , err )
2090+ }
2091+ events := []types.EventName {
2092+ types .ValidatorIsOfflineEventName ,
2093+ types .ValidatorIsOnlineEventName ,
2094+ types .ValidatorMissedProposalEventName ,
2095+ types .ValidatorUpcomingProposalEventName ,
2096+ types .ValidatorExecutedProposalEventName ,
2097+ types .ValidatorMissedAttestationEventName ,
2098+ types .ValidatorReceivedWithdrawalEventName ,
2099+ types .ValidatorGotSlashedEventName ,
2100+ types .ValidatorDidSlashEventName ,
2101+ types .SyncCommitteeSoonEventName ,
2102+ types .ValidatorReceivedDepositEventName ,
2103+ }
2104+ for i , event := range events {
2105+ events [i ] = types .EventName (fmt .Sprintf ("%s:%s" , networkName , event ))
2106+ }
21192107 ds := goqu .Dialect ("postgres" ).
21202108 Select (goqu .COUNT (goqu .I ("id" ))).
21212109 From (goqu .T ("users_subscriptions" )).
21222110 Where (
21232111 goqu .I ("user_id" ).Eq (userId ),
2124- goqu .I ("event_name" ). Like ( "validator%" ),
2112+ goqu .L ("event_name IN ?" , events ),
21252113 goqu .I ("event_filter" ).NotLike ("vdb:%" ),
21262114 )
21272115 count , err := runQuery [int ](ctx , d .userReader , ds )
21282116 return count > 0 , err
21292117}
2118+
2119+ func (d * DataAccessService ) getNetworkName (chainId uint64 ) (string , error ) {
2120+ networks , err := d .GetAllNetworks ()
2121+ if err != nil {
2122+ return "" , fmt .Errorf ("error fetching networks: %w" , err )
2123+ }
2124+
2125+ for _ , network := range networks {
2126+ if network .ChainId == chainId {
2127+ return network .NotificationsName , nil
2128+ }
2129+ }
2130+ return "" , fmt .Errorf ("network with chain id %d not found" , chainId )
2131+ }
0 commit comments