Skip to content

Commit c14c833

Browse files
committed
fix(notifications): using correct network prefix
1 parent 975e84b commit c14c833

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package dataaccess
2+
3+
import (
4+
"testing"
5+
6+
"github.com/gobitfly/beaconchain/pkg/api/types"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestGetAllNetworks(t *testing.T) {
11+
d := &DataAccessService{}
12+
t.Run("GetAllNetworks", func(t *testing.T) {
13+
networks, err := d.GetAllNetworks()
14+
assert.Nil(t, err)
15+
assert.Contains(t, networks, types.NetworkInfo{
16+
ChainId: 1,
17+
Name: "ethereum",
18+
NotificationsName: "mainnet",
19+
})
20+
assert.Contains(t, networks, types.NetworkInfo{
21+
ChainId: 100,
22+
Name: "gnosis",
23+
NotificationsName: "gnosis",
24+
})
25+
assert.Contains(t, networks, types.NetworkInfo{
26+
ChainId: 17000,
27+
Name: "holesky",
28+
NotificationsName: "holesky",
29+
})
30+
assert.Contains(t, networks, types.NetworkInfo{
31+
ChainId: 11155111,
32+
Name: "sepolia",
33+
NotificationsName: "sepolia",
34+
})
35+
})
36+
}

backend/pkg/api/data_access/notifications.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,10 +1541,22 @@ func (d *DataAccessService) GetNotificationSettingsDashboards(ctx context.Contex
15411541
Threshold float64 `db:"event_threshold"`
15421542
}{}
15431543

1544-
networkName := "mainnet"
1545-
if utils.Config.Chain.ClConfig.DepositChainID == 17000 {
1546-
networkName = "holesky"
1544+
networks, err := d.GetAllNetworks()
1545+
if err != nil {
1546+
return nil, nil, err
1547+
}
1548+
1549+
var networkName string
1550+
for _, network := range networks {
1551+
if network.ChainId == utils.Config.Chain.ClConfig.DepositChainID {
1552+
networkName = network.NotificationsName
1553+
break
1554+
}
15471555
}
1556+
if networkName == "" {
1557+
return nil, nil, fmt.Errorf("network with chain id %d to update general notification settings not found", utils.Config.Chain.ClConfig.DepositChainID)
1558+
}
1559+
15481560
wg.Go(func() error {
15491561
err := d.userReader.SelectContext(ctx, &events, `
15501562
SELECT

0 commit comments

Comments
 (0)