Skip to content

Commit

Permalink
fix: gracefully handle rocket pool not available on network
Browse files Browse the repository at this point in the history
feat: add el-cl price to widget response, use elclvalue for reward widget response
  • Loading branch information
manuelsc committed Jan 14, 2025
1 parent c4b4eba commit 0a77f43
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
9 changes: 4 additions & 5 deletions backend/pkg/api/data_access/data_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ type DataAccessService struct {
persistentRedisDbClient *redis.Client

services *services.Services

skipServiceInitWait bool
config *types.Config
}

// ensure DataAccessService pointer implements DataAccessor
Expand Down Expand Up @@ -89,8 +88,8 @@ func NewDataAccessService(cfg *types.Config) *DataAccessService {

func createDataAccessService(cfg *types.Config) *DataAccessService {
dataAccessService := DataAccessService{
dummy: NewDummyService(),
skipServiceInitWait: cfg.SkipDataAccessServiceInitWait,
dummy: NewDummyService(),
config: cfg,
}

// Initialize the database
Expand Down Expand Up @@ -175,7 +174,7 @@ func (d *DataAccessService) StartDataAccessServices() {
d.registerNotificationInterfaceTypes()
// Initialize the services

if d.skipServiceInitWait {
if d.config.SkipDataAccessServiceInitWait {
go d.services.InitServices()
} else {
d.services.InitServices()
Expand Down
15 changes: 12 additions & 3 deletions backend/pkg/api/data_access/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gobitfly/beaconchain/pkg/api/enums"
t "github.com/gobitfly/beaconchain/pkg/api/types"
"github.com/gobitfly/beaconchain/pkg/commons/cache"
"github.com/gobitfly/beaconchain/pkg/commons/price"
"github.com/gobitfly/beaconchain/pkg/commons/utils"
constypes "github.com/gobitfly/beaconchain/pkg/consapi/types"
"github.com/gobitfly/beaconchain/pkg/userservice"
Expand Down Expand Up @@ -212,6 +213,9 @@ func (d *DataAccessService) GetValidatorDashboardMobileWidget(ctx context.Contex
eg.Go(func() error {
rpNetworkStats, err := d.getInternalRpNetworkStats(ctx)
if err != nil {
if err == sql.ErrNoRows { // no rocket pool deployment on network
return nil
}
return fmt.Errorf("error retrieving rocketpool network stats: %w", err)
}
data.RplPrice = rpNetworkStats.RPLPrice
Expand Down Expand Up @@ -268,13 +272,16 @@ func (d *DataAccessService) GetValidatorDashboardMobileWidget(ctx context.Contex
})
}

retrieveRewards := func(hours int, rewards *decimal.Decimal) {
retrieveRewards := func(hours int, rewards *t.ClElValue[decimal.Decimal]) {
eg.Go(func() error {
clRewards, _, elRewards, _, err := d.internal_getElClAPR(ctx, wrappedDashboardId, -1, hours)
elRewards, _, clRewards, _, err := d.internal_getElClAPR(ctx, wrappedDashboardId, -1, hours)
if err != nil {
return err
}
*rewards = clRewards.Add(elRewards)
*rewards = t.ClElValue[decimal.Decimal]{
El: elRewards,
Cl: clRewards,
}
return nil
})
}
Expand Down Expand Up @@ -340,6 +347,8 @@ func (d *DataAccessService) GetValidatorDashboardMobileWidget(ctx context.Contex

err = eg.Wait()

data.ELCLPrice = price.GetPrice(d.config.Frontend.ClCurrency, d.config.Frontend.ElCurrency)

if err != nil {
return nil, fmt.Errorf("error retrieving validator dashboard overview data: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions backend/pkg/api/data_access/vdb_rocket_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dataaccess

import (
"context"
"database/sql"
"encoding/hex"
"fmt"
"slices"
Expand Down Expand Up @@ -174,6 +175,9 @@ func (d *DataAccessService) GetValidatorDashboardRocketPool(ctx context.Context,
var err error
rpNetworkStats, err = d.getInternalRpNetworkStats(ctx)
if err != nil {
if err == sql.ErrNoRows { // no rocket pool deployment on network
return fmt.Errorf("rocketpool not deployed on current network")
}
return fmt.Errorf("error retrieving rocketpool network stats: %w", err)
}
return nil
Expand Down
17 changes: 9 additions & 8 deletions backend/pkg/api/types/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ type MobileBundleData struct {
type GetMobileLatestBundleResponse ApiDataResponse[MobileBundleData]

type MobileWidgetData struct {
ValidatorStateCounts ValidatorStateCounts `json:"validator_state_counts"`
Last24hIncome decimal.Decimal `json:"last_24h_income" faker:"eth"`
Last7dIncome decimal.Decimal `json:"last_7d_income" faker:"eth"`
Last30dApr float64 `json:"last_30d_apr"`
Last30dEfficiency float64 `json:"last_30d_efficiency"`
NetworkEfficiency float64 `json:"network_efficiency"`
RplPrice decimal.Decimal `json:"rpl_price" faker:"eth"`
RplApr float64 `json:"rpl_apr"`
ValidatorStateCounts ValidatorStateCounts `json:"validator_state_counts"`
Last24hIncome ClElValue[decimal.Decimal] `json:"last_24h_income" faker:"eth"`
Last7dIncome ClElValue[decimal.Decimal] `json:"last_7d_income" faker:"eth"`
Last30dApr float64 `json:"last_30d_apr"`
Last30dEfficiency float64 `json:"last_30d_efficiency"`
NetworkEfficiency float64 `json:"network_efficiency"`
RplPrice decimal.Decimal `json:"rpl_price" faker:"eth"`
RplApr float64 `json:"rpl_apr"`
ELCLPrice float64 `json:"el_cl_price"`
}

type InternalGetValidatorDashboardMobileWidgetResponse ApiDataResponse[MobileWidgetData]
Expand Down
7 changes: 4 additions & 3 deletions frontend/types/api/mobile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by tygo. DO NOT EDIT.
/* eslint-disable */
import type { ApiDataResponse, ValidatorStateCounts, PubKey, Hash, ApiPagingResponse } from './common'
import type { ApiDataResponse, ValidatorStateCounts, ClElValue, PubKey, Hash, ApiPagingResponse } from './common'

//////////
// source: mobile.go
Expand All @@ -12,13 +12,14 @@ export interface MobileBundleData {
export type GetMobileLatestBundleResponse = ApiDataResponse<MobileBundleData>;
export interface MobileWidgetData {
validator_state_counts: ValidatorStateCounts;
last_24h_income: string /* decimal.Decimal */;
last_7d_income: string /* decimal.Decimal */;
last_24h_income: ClElValue<string /* decimal.Decimal */>;
last_7d_income: ClElValue<string /* decimal.Decimal */>;
last_30d_apr: number /* float64 */;
last_30d_efficiency: number /* float64 */;
network_efficiency: number /* float64 */;
rpl_price: string /* decimal.Decimal */;
rpl_apr: number /* float64 */;
el_cl_price: number /* float64 */;
}
export type InternalGetValidatorDashboardMobileWidgetResponse = ApiDataResponse<MobileWidgetData>;
export interface MobileValidatorDashboardValidatorsRocketPool {
Expand Down

0 comments on commit 0a77f43

Please sign in to comment.