Skip to content

Commit

Permalink
Fix the rich list to work against updated (breaking) API
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Feb 13, 2022
1 parent b05440a commit 7cb44e4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export class InsightComponent implements OnInit, OnDestroy {
async updateRichlist() {
try {
const list = await this.api.getRichlist(0, 5);
list.reverse()
this.richlist = list;
this.errorRichlist = null;
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<div class="box">
<h3>Richlist</h3>

<app-progress class="centered" *ngIf="!blocks">Loading richlist...</app-progress>
<app-progress class="centered" *ngIf="!addresses">Loading richlist...</app-progress>

<div *ngIf="blocks">
<div *ngIf="addresses">
<div class="grid-header richlist">
<span>Rank</span>
<span>Address</span>
<span class="right">Balance</span>
</div>

<div class="scrollable" appDetectScroll (onScroll)="onScroll($event)" [bottomOffset]="400" [topOffset]="400">
<div class="grid grid-odd-line richlist" *ngFor="let item of blocks; index as i">
<div class="grid grid-odd-line richlist" *ngFor="let item of addresses; index as i">
<span class="center">{{i+1}}<!--<span><i class="fas fa-info-circle"></i></span>--></span>
<span class><a [routerLink]="['../../explorer/address/', item.address]">{{item.address}}</a>
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, HostBinding, HostListener } from '@angular/core';
import { SetupService } from 'src/app/services/setup.service';
import { ApiService } from 'src/app/services/api.service';
import { ScrollEvent } from 'src/app/shared/scroll.directive';
import { SetupService } from '../../services/setup.service';
import { ApiService } from '../../services/api.service';
import { ScrollEvent } from '../../shared/scroll.directive';

@Component({
selector: 'app-richlist',
Expand All @@ -18,8 +18,7 @@ export class RichlistComponent implements OnInit {
configuration: any;
consensus: any;
peers: any;
blocks: any = null;

addresses: any = null;
timerInfo: any;
timerBlocks: any;
count = 0;
Expand All @@ -38,12 +37,13 @@ export class RichlistComponent implements OnInit {

ngOnInit(): void {
this.subscription = this.setup.currentChain$.subscribe(async (chain) => {
await this.updateRichlist('/api/query/richlist?limit=' + this.limit);
// await this.api.getRichlist(0, this.limit);
// return this.downloadRelative('/insight/richlist?offset=' + offset + '&limit=' + limit);
await this.updateRichlist('/api/insight/richlist?limit=' + this.limit);
});
}

async updateRichlist(url) {

console.log('url: ', url);

if (!url) {
Expand All @@ -59,28 +59,15 @@ export class RichlistComponent implements OnInit {
const links = this.api.parseLinkHeader(linkHeader);

// This will be set to undefined/null when no more previous links is available.
this.link = links.previous;
this.link = links.next;

// When the offset is not set (0), we should reverse the order of items.
const list = await response.json();
list.reverse()
list.sort((b, a) => {
if (a.blockIndex === b.blockIndex) {
return 0;
}
if (a.blockIndex < b.blockIndex) {
return -1;
}
if (a.blockIndex > b.blockIndex) {
return 1;
}
});

if (!this.blocks) {
this.blocks = [];
if (!this.addresses) {
this.addresses = [];
}

this.blocks = [...this.blocks, ...list];
this.addresses = [...this.addresses, ...list];
this.count++;
}

Expand All @@ -93,6 +80,7 @@ export class RichlistComponent implements OnInit {
this.loading = true;

setTimeout(async () => {
console.log('UPDATE RICH LIST', this.link);
await this.updateRichlist(this.link);
this.loading = false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class ApiService {
}

async getRichlist(offset: number, limit: number) {
return this.downloadRelative('/query/richlist?offset=' + offset + '&limit=' + limit);
return this.downloadRelative('/insight/richlist?offset=' + offset + '&limit=' + limit);
}

async getSupply() {
Expand Down

0 comments on commit 7cb44e4

Please sign in to comment.