Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

refactor: use the activeDelegates number provided by the network #336

Merged
merged 5 commits into from May 31, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/models/stored-network.ts
Expand Up @@ -19,5 +19,6 @@ export class StoredNetwork extends Network {
public peerList: Peer[];
public feeStatistics: FeeStatistic[];
public epoch: Date;
public activeDelegates: number;
public vendorFieldLength?: number;
}
14 changes: 10 additions & 4 deletions src/providers/ark-api/ark-api.ts
Expand Up @@ -34,6 +34,7 @@ interface NodeFeesResponse {

interface NodeConfigurationConstants {
vendorFieldLength?: number;
activeDelegates: number;
}

interface NodeConfigurationResponse {
Expand Down Expand Up @@ -97,7 +98,7 @@ export class ArkApiProvider {
public get delegates(): Observable<arkts.Delegate[]> {
if (!lodash.isEmpty(this._delegates)) { return Observable.of(this._delegates); }

return this.fetchDelegates(constants.NUM_ACTIVE_DELEGATES * 2);
return this.fetchDelegates(this._network.activeDelegates * 2);
}

public get topWallets(): Observable<Wallet[]> {
Expand Down Expand Up @@ -126,6 +127,8 @@ export class ArkApiProvider {

// Fallback if the fetchEpoch fail
this._network.epoch = arktsConfig.blockchain.date;
// Fallback if the fetchNodeConfiguration fail
this._network.activeDelegates = constants.NUM_ACTIVE_DELEGATES;
this.userDataProvider.onUpdateNetwork$.next(this._network);

this.fetchFees().subscribe();
Expand Down Expand Up @@ -274,7 +277,7 @@ export class ArkApiProvider {

public fetchDelegates(numberDelegatesToGet: number, getAllDelegates = false): Observable<arkts.Delegate[]> {
if (!this._api) { return; }
const limit = 51;
const limit = this._network.activeDelegates;

const totalCount = limit;
let offset, currentPage;
Expand Down Expand Up @@ -462,17 +465,20 @@ export class ArkApiProvider {
this.userDataProvider.addOrUpdateNetwork(this._network, this.userDataProvider.currentProfile.networkId);
this._api = new arkts.Client(this._network);

this.fetchDelegates(constants.NUM_ACTIVE_DELEGATES * 2).subscribe((data) => {
this.fetchDelegates(this._network.activeDelegates * 2).subscribe((data) => {
this._delegates = data;
});

this.fetchFees().subscribe();
this.fetchFeeStatistics().subscribe();
this.fetchNodeConfiguration().subscribe((response: NodeConfigurationResponse) => {
const vendorFieldLength = response.data.constants.vendorFieldLength;
const { vendorFieldLength, activeDelegates } = (response.data && response.data.constants) || {};
if (vendorFieldLength) {
this._network.vendorFieldLength = vendorFieldLength;
}
if (activeDelegates) {
this._network.activeDelegates = activeDelegates;
}
});
}

Expand Down