Skip to content

Commit

Permalink
Merge pull request #147 from gobitfly/NOBIDS/add-validator-count-to-o…
Browse files Browse the repository at this point in the history
…verview

Add validator count per group to VDB overview
  • Loading branch information
remoterami authored Mar 25, 2024
2 parents d7038ca + 5ba6665 commit 236011f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
24 changes: 17 additions & 7 deletions backend/pkg/api/data_access/data_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type DataAccessor interface {

GetValidatorDashboardOverview(dashboardId t.VDBId) (*t.VDBOverviewData, error)

CreateValidatorDashboardGroup(dashboardId t.VDBIdPrimary, name string) (*t.VDBOverviewGroup, error)
CreateValidatorDashboardGroup(dashboardId t.VDBIdPrimary, name string) (*t.VDBPostCreateGroupData, error)
RemoveValidatorDashboardGroup(dashboardId t.VDBIdPrimary, groupId uint64) error

GetValidatorDashboardGroupExists(dashboardId t.VDBIdPrimary, groupId uint64) (bool, error)
Expand Down Expand Up @@ -463,14 +463,24 @@ func (d *DataAccessService) GetValidatorDashboardOverview(dashboardId t.VDBId) (
// should have valid primary id
wg.Go(func() error {
var queryResult []struct {
Id uint32 `db:"id"`
Name string `db:"name"`
Id uint32 `db:"id"`
Name string `db:"name"`
Count uint64 `db:"count"`
}
if err := d.alloyReader.Select(&queryResult, `SELECT id, name FROM users_val_dashboards_groups WHERE dashboard_id = $1`, dashboardId.Id); err != nil {
query := `SELECT id, name, COUNT(validator_index)
FROM
users_val_dashboards_groups groups
LEFT JOIN users_val_dashboards_validators validators
ON groups.dashboard_id = validators.dashboard_id AND groups.id = validators.group_id
WHERE
groups.dashboard_id = $1
GROUP BY
groups.id, groups.name`
if err := d.alloyReader.Select(&queryResult, query, dashboardId.Id); err != nil {
return err
}
for _, res := range queryResult {
data.Groups = append(data.Groups, t.VDBOverviewGroup{Id: uint64(res.Id), Name: res.Name})
data.Groups = append(data.Groups, t.VDBOverviewGroup{Id: uint64(res.Id), Name: res.Name, Count: res.Count})
}
return nil
})
Expand Down Expand Up @@ -588,8 +598,8 @@ func (d *DataAccessService) GetValidatorDashboardOverview(dashboardId t.VDBId) (
return &data, nil
}

func (d *DataAccessService) CreateValidatorDashboardGroup(dashboardId t.VDBIdPrimary, name string) (*t.VDBOverviewGroup, error) {
result := &t.VDBOverviewGroup{}
func (d *DataAccessService) CreateValidatorDashboardGroup(dashboardId t.VDBIdPrimary, name string) (*t.VDBPostCreateGroupData, error) {
result := &t.VDBPostCreateGroupData{}

// Create a new group that has the smallest unique id possible
err := d.alloyWriter.Get(result, `
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/api/data_access/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (d *DummyService) RemoveValidatorDashboard(dashboardId t.VDBIdPrimary) erro
return nil
}

func (d *DummyService) CreateValidatorDashboardGroup(dashboardId t.VDBIdPrimary, name string) (*t.VDBOverviewGroup, error) {
r := t.VDBOverviewGroup{}
func (d *DummyService) CreateValidatorDashboardGroup(dashboardId t.VDBIdPrimary, name string) (*t.VDBPostCreateGroupData, error) {
r := t.VDBPostCreateGroupData{}
err := commonFakeData(&r)
return &r, err
}
Expand Down
10 changes: 8 additions & 2 deletions backend/pkg/api/types/validator_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ type VDBOverviewValidators struct {
}

type VDBOverviewGroup struct {
Id uint64 `db:"id" json:"id"`
Name string `db:"name" json:"name"`
Id uint64 `json:"id"`
Name string `json:"name"`
Count uint64 `json:"count"`
}

type VDBOverviewData struct {
Expand Down Expand Up @@ -235,6 +236,11 @@ type VDBPostReturnData struct {
CreatedAt time.Time `db:"created_at" json:"created_at"`
}

type VDBPostCreateGroupData struct {
Id uint64 `db:"id" json:"id"`
Name string `db:"name" json:"name"`
}

type VDBPostValidatorsData struct {
PublicKey string `json:"public_key"`
GroupId uint64 `json:"group_id"`
Expand Down
6 changes: 6 additions & 0 deletions frontend/types/api/validator_dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface VDBOverviewValidators {
export interface VDBOverviewGroup {
id: number /* uint64 */;
name: string;
count: number /* uint64 */;
}
export interface VDBOverviewData {
groups: VDBOverviewGroup[];
Expand Down Expand Up @@ -64,6 +65,7 @@ export interface VDBGroupSummaryData {
}
export type InternalGetValidatorDashboardGroupSummaryResponse = ApiDataResponse<VDBGroupSummaryData>;
export type InternalGetValidatorDashboardSummaryChartResponse = ApiDataResponse<ChartData<number /* int */>>; // line chart, series id is group id, no stack
export type InternalGetValidatorDashboardValidatorIndicesResponse = ApiDataResponse<number /* uint64 */[]>;
/**
* ------------------------------------------------------------
* Rewards Tab
Expand Down Expand Up @@ -224,6 +226,10 @@ export interface VDBPostReturnData {
network: number /* uint64 */;
created_at: string /* time.Time */;
}
export interface VDBPostCreateGroupData {
id: number /* uint64 */;
name: string;
}
export interface VDBPostValidatorsData {
public_key: string;
group_id: number /* uint64 */;
Expand Down

0 comments on commit 236011f

Please sign in to comment.