From 693bf658464a3f5e683751aa6f5714d31b2381a5 Mon Sep 17 00:00:00 2001 From: Manuel <5877862+manuelsc@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:58:07 +0100 Subject: [PATCH] fix: gracefully handle rocket pool not available on network feat: add el-cl price to widget response, use elclvalue for reward widget responses --- backend/pkg/api/data_access/data_access.go | 2 ++ backend/pkg/api/data_access/mobile.go | 15 ++++++++++++--- backend/pkg/api/data_access/vdb_rocket_pool.go | 4 ++++ backend/pkg/api/types/mobile.go | 17 +++++++++-------- frontend/types/api/mobile.ts | 7 ++++--- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/backend/pkg/api/data_access/data_access.go b/backend/pkg/api/data_access/data_access.go index 6e665ff41..6315293c7 100644 --- a/backend/pkg/api/data_access/data_access.go +++ b/backend/pkg/api/data_access/data_access.go @@ -60,6 +60,7 @@ type DataAccessService struct { persistentRedisDbClient *redis.Client services *services.Services + config *types.Config skipServiceInitWait bool } @@ -91,6 +92,7 @@ func createDataAccessService(cfg *types.Config) *DataAccessService { dataAccessService := DataAccessService{ dummy: NewDummyService(), skipServiceInitWait: cfg.SkipDataAccessServiceInitWait, + config: cfg, } // Initialize the database diff --git a/backend/pkg/api/data_access/mobile.go b/backend/pkg/api/data_access/mobile.go index 66eb0b6e3..8eaef10a1 100644 --- a/backend/pkg/api/data_access/mobile.go +++ b/backend/pkg/api/data_access/mobile.go @@ -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" @@ -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 @@ -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 }) } @@ -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) } diff --git a/backend/pkg/api/data_access/vdb_rocket_pool.go b/backend/pkg/api/data_access/vdb_rocket_pool.go index 42fd5f873..983280ef7 100644 --- a/backend/pkg/api/data_access/vdb_rocket_pool.go +++ b/backend/pkg/api/data_access/vdb_rocket_pool.go @@ -2,6 +2,7 @@ package dataaccess import ( "context" + "database/sql" "encoding/hex" "fmt" "slices" @@ -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 diff --git a/backend/pkg/api/types/mobile.go b/backend/pkg/api/types/mobile.go index 059239f62..65326ad90 100644 --- a/backend/pkg/api/types/mobile.go +++ b/backend/pkg/api/types/mobile.go @@ -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] diff --git a/frontend/types/api/mobile.ts b/frontend/types/api/mobile.ts index 3b7bfc484..a0c81b89f 100644 --- a/frontend/types/api/mobile.ts +++ b/frontend/types/api/mobile.ts @@ -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 @@ -12,13 +12,14 @@ export interface MobileBundleData { export type GetMobileLatestBundleResponse = ApiDataResponse; export interface MobileWidgetData { validator_state_counts: ValidatorStateCounts; - last_24h_income: string /* decimal.Decimal */; - last_7d_income: string /* decimal.Decimal */; + last_24h_income: ClElValue; + last_7d_income: ClElValue; 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; export interface MobileValidatorDashboardValidatorsRocketPool {