Skip to content

Commit

Permalink
Improve the behavior when indexers are all offline (or user is offline)
Browse files Browse the repository at this point in the history
- Related to #148
  • Loading branch information
sondreb committed Jun 7, 2022
1 parent b753896 commit ba68591
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
13 changes: 0 additions & 13 deletions angular/src/app/settings/network/network.component.html
Expand Up @@ -12,22 +12,9 @@ <h1>{{ 'Settings.NetworkStatus' | translate }}</h1>
<strong class="network-type">{{status.type}}</strong><br>
<span *ngIf="status.networks?.length == 0">No servers online for this network.<br></span>
<div mat-line *ngFor="let network of status.networks">

<!-- <div class="network-status-widget"> -->
<app-network-status [value]="network.availability"></app-network-status>
<!-- </div> -->

{{network.domain}}<br><span class="dimmed">{{network.status}}</span><br><br>
</div>
</div>

<!-- <mat-nav-list>
<div mat-subheader>Networks for accounts in your wallets:</div>
<a mat-list-item *ngFor="let status of networkStatus.getActive(); let i = index">
<mat-icon mat-list-icon>travel_explore</mat-icon>
<div mat-line>{{status.type}}</div>
<div mat-line *ngIf="status.networks.length == 0">No servers online for this network.</div>
<div mat-line *ngFor="let network of status.networks">{{network.domain}}<br><span class="dimmed">{{network.status}}</span><br><br></div>
</a>
</mat-nav-list> -->
</div>
5 changes: 1 addition & 4 deletions angular/src/app/settings/network/network.component.ts
@@ -1,7 +1,6 @@
import { Location } from '@angular/common';
import { Component, OnDestroy, ViewEncapsulation } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { UIState, CommunicationService, FeatureService, NetworkStatusService } from '../../services';
import { UIState, FeatureService, NetworkStatusService } from '../../services';

@Component({
selector: 'app-network',
Expand All @@ -13,8 +12,6 @@ export class NetworkComponent implements OnDestroy {
constructor(
public uiState: UIState,
public location: Location,
private snackBar: MatSnackBar,
private communication: CommunicationService,
public networkStatus: NetworkStatusService,
public feature: FeatureService,
) {
Expand Down
Expand Up @@ -21,7 +21,12 @@ export class NetworkStatusComponent {
if (!this.status || this.status.length === 0) {
return `network-status-offline`;
} else {
return `network-status-online`;
const availableCount = this.status.filter(s => s.availability == 1).length;
if (availableCount == 0) {
return `network-status-offline`;
} else {
return `network-status-online`;
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions angular/src/shared/background-manager.ts
Expand Up @@ -74,7 +74,7 @@ export class BackgroundManager {
await this.updateAll(accounts, networkLoader, settingStore);
}
catch (err) {

console.error('Failure during update all network status:', err);
}
}

Expand Down Expand Up @@ -233,8 +233,6 @@ export class BackgroundManager {
}
}



async runWatcher(runState: RunState) {
this.watcherState = runState;

Expand Down
21 changes: 21 additions & 0 deletions angular/src/shared/indexer.ts
Expand Up @@ -259,6 +259,27 @@ export class IndexerBackgroundService {
}

// console.debug('Looping wallets', wallets);
// Check if there is any indexers online for any of the accounts in all of the wallets.
// If there are no indexers online, we'll simply return "completed: true" to avoid
// the loop.
const allAccountTypes = wallets.flatMap(w => w.accounts).flatMap(a => a.networkType);
const uniqueAccountTypes = Array.from([...new Set(allAccountTypes)]);;
let anyIndexerOnline = false;

for (let i = 0; i < uniqueAccountTypes.length; i++) {
const indexerUrl = this.addressManager.networkLoader.getServer(uniqueAccountTypes[i], settings.server, settings.indexer);

if (indexerUrl == null || indexerUrl == '') {
continue;
}

anyIndexerOnline = true;
}

if (!anyIndexerOnline) {
console.warn('There are no indexers for the current accounts that are online.');
return { cancelled: true, completed: true };
}

for (let i = 0; i < wallets.length; i++) {
if (this.runState.cancel) {
Expand Down

0 comments on commit ba68591

Please sign in to comment.