From 479f63575475c64da75ae2251de056a68a5bcccd Mon Sep 17 00:00:00 2001 From: nymkappa Date: Sun, 24 Jul 2022 11:51:05 +0200 Subject: [PATCH 1/3] [Node page] Update channels count when switching between open/closed --- backend/src/api/explorer/nodes.api.ts | 7 +++++-- .../lightning/channels-list/channels-list.component.ts | 9 +++++++-- frontend/src/app/lightning/node/node.component.html | 7 ++++--- frontend/src/app/lightning/node/node.component.ts | 5 +++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/backend/src/api/explorer/nodes.api.ts b/backend/src/api/explorer/nodes.api.ts index 3791b4c9d..ec8ee35fb 100644 --- a/backend/src/api/explorer/nodes.api.ts +++ b/backend/src/api/explorer/nodes.api.ts @@ -9,7 +9,10 @@ class NodesApi { geo_names_country.names as country, geo_names_subdivision.names as subdivision, (SELECT Count(*) FROM channels - WHERE channels.status < 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS channel_count, + WHERE channels.status = 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS channel_closed_count, + (SELECT Count(*) + FROM channels + WHERE channels.status < 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS channel_active_count, (SELECT Sum(capacity) FROM channels WHERE channels.status < 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS capacity, @@ -23,7 +26,7 @@ class NodesApi { LEFT JOIN geo_names geo_names_country on geo_names_country.id = country_id WHERE public_key = ? `; - const [rows]: any = await DB.query(query, [public_key, public_key, public_key, public_key, public_key, public_key, public_key]); + const [rows]: any = await DB.query(query, [public_key, public_key, public_key, public_key, public_key, public_key, public_key, public_key, public_key]); if (rows.length > 0) { rows[0].as_organization = JSON.parse(rows[0].as_organization); rows[0].subdivision = JSON.parse(rows[0].subdivision); diff --git a/frontend/src/app/lightning/channels-list/channels-list.component.ts b/frontend/src/app/lightning/channels-list/channels-list.component.ts index 0ac7da578..4060d36da 100644 --- a/frontend/src/app/lightning/channels-list/channels-list.component.ts +++ b/frontend/src/app/lightning/channels-list/channels-list.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, Input, OnChanges, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; import { BehaviorSubject, combineLatest, merge, Observable, of } from 'rxjs'; import { map, startWith, switchMap } from 'rxjs/operators'; @@ -12,6 +12,7 @@ import { LightningApiService } from '../lightning-api.service'; }) export class ChannelsListComponent implements OnInit, OnChanges { @Input() publicKey: string; + @Output() channelsStatusChangedEvent = new EventEmitter(); channels$: Observable; // @ts-ignore @@ -41,13 +42,17 @@ export class ChannelsListComponent implements OnInit, OnChanges { ngOnChanges(): void { this.channelStatusForm.get('status').setValue(this.defaultStatus, { emitEvent: false }) + this.channelsStatusChangedEvent.emit(this.defaultStatus); this.channels$ = combineLatest([ this.channelsPage$, this.channelStatusForm.get('status').valueChanges.pipe(startWith(this.defaultStatus)) ]) .pipe( - switchMap(([page, status]) =>this.lightningApiService.getChannelsByNodeId$(this.publicKey, (page -1) * this.itemsPerPage, status)), + switchMap(([page, status]) => { + this.channelsStatusChangedEvent.emit(status); + return this.lightningApiService.getChannelsByNodeId$(this.publicKey, (page -1) * this.itemsPerPage, status); + }), map((response) => { return { channels: response.body, diff --git a/frontend/src/app/lightning/node/node.component.html b/frontend/src/app/lightning/node/node.component.html index 68f5b31e0..d25ca569c 100644 --- a/frontend/src/app/lightning/node/node.component.html +++ b/frontend/src/app/lightning/node/node.component.html @@ -24,7 +24,7 @@ Total channels - {{ node.channel_count }} + {{ node.channel_active_count }} @@ -108,7 +108,7 @@
-

Channels ({{ node.channel_count }})

+

Channels ({{ channelsListStatus === 'open' ? node.channel_active_count : node.channel_closed_count }})

List 
- +
diff --git a/frontend/src/app/lightning/node/node.component.ts b/frontend/src/app/lightning/node/node.component.ts index a286aa987..f75ab6c95 100644 --- a/frontend/src/app/lightning/node/node.component.ts +++ b/frontend/src/app/lightning/node/node.component.ts @@ -18,6 +18,7 @@ export class NodeComponent implements OnInit { selectedSocketIndex = 0; qrCodeVisible = false; channelsListMode = 'list'; + channelsListStatus: string; constructor( private lightningApiService: LightningApiService, @@ -69,4 +70,8 @@ export class NodeComponent implements OnInit { this.channelsListMode = 'list'; } } + + onChannelsListStatusChanged(e) { + this.channelsListStatus = e; + } } From 886e7e663878722806dc0e91dfa36a53cc4dac6c Mon Sep 17 00:00:00 2001 From: nymkappa Date: Sun, 24 Jul 2022 12:05:09 +0200 Subject: [PATCH 2/3] [Node page] Show message if there is no channels in the list to display --- .../lightning/channels-list/channels-list.component.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/lightning/channels-list/channels-list.component.html b/frontend/src/app/lightning/channels-list/channels-list.component.html index ff67788e1..82283f689 100644 --- a/frontend/src/app/lightning/channels-list/channels-list.component.html +++ b/frontend/src/app/lightning/channels-list/channels-list.component.html @@ -10,7 +10,7 @@ - +
@@ -19,7 +19,11 @@
- + + + +
No channels to display
+
From d9e85fdcb6af8ee90ea24ecb62f3f24dcf9c06e2 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Sun, 24 Jul 2022 12:34:50 +0200 Subject: [PATCH 3/3] Show error message when the node public key does not exist --- .../app/lightning/node/node.component.html | 232 ++++++++++-------- .../src/app/lightning/node/node.component.ts | 12 +- 2 files changed, 136 insertions(+), 108 deletions(-) diff --git a/frontend/src/app/lightning/node/node.component.html b/frontend/src/app/lightning/node/node.component.html index d25ca569c..e2132bca5 100644 --- a/frontend/src/app/lightning/node/node.component.html +++ b/frontend/src/app/lightning/node/node.component.html @@ -1,128 +1,146 @@
-
+
-
+
+ No node found for public key "{{ node.public_key | shortenString : 12}}" + Back to the lightning dashboard +
-
-
- - - - - - - - - - - - - - - - - - - - - - - -
Total capacity - -
Total channels - {{ node.channel_active_count }} -
Average channel size - -
Location{{ node.city.en }}, {{ node.subdivision.en }}
{{ node.country.en }}
Location{{ node.country.en }}
-
-
-
- - - - - - - - - - - - - - - - - - - -
First seen - -
Last update - -
Color
{{ node.color }}
ISP - {{ node.as_organization }} [ASN {{node.as_number}}] -
-
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
Total capacity + + +
Total channels + {{ node.channel_active_count }} +
Average channel size + + +
Location{{ node.city.en }}, {{ node.subdivision.en }}
{{ node.country.en }}
Location{{ node.country.en }}
+
+
+
+ + + + + + + + + + + + + + + + + + + +
First seen + +
Last update + +
Color +
{{ node.color }}
+
ISP + {{ node.as_organization }} [ASN {{node.as_number}}] +
-
-
+
-
-
- -
- -
+
+ +
+
+ +
+
- - {{ node.socketsObject[selectedSocketIndex].label }} - - - -
+ + {{ node.socketsObject[selectedSocketIndex].label }} + + + + +
-
+
- + + +
+ +
+

Channels ({{ channelsListStatus === 'open' ? node.channel_active_count : node.channel_closed_count }})

+
+ List  + +  Map +
+
+ + + + -
- -
-

Channels ({{ channelsListStatus === 'open' ? node.channel_active_count : node.channel_closed_count }})

-
- List  - -  Map -
-
- - - -
-
+
\ No newline at end of file diff --git a/frontend/src/app/lightning/node/node.component.ts b/frontend/src/app/lightning/node/node.component.ts index f75ab6c95..c70983b54 100644 --- a/frontend/src/app/lightning/node/node.component.ts +++ b/frontend/src/app/lightning/node/node.component.ts @@ -1,7 +1,7 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; import { ActivatedRoute, ParamMap } from '@angular/router'; import { Observable } from 'rxjs'; -import { map, switchMap } from 'rxjs/operators'; +import { catchError, map, switchMap } from 'rxjs/operators'; import { SeoService } from 'src/app/services/seo.service'; import { LightningApiService } from '../lightning-api.service'; @@ -19,6 +19,8 @@ export class NodeComponent implements OnInit { qrCodeVisible = false; channelsListMode = 'list'; channelsListStatus: string; + error: Error; + publicKey: string; constructor( private lightningApiService: LightningApiService, @@ -30,6 +32,7 @@ export class NodeComponent implements OnInit { this.node$ = this.activatedRoute.paramMap .pipe( switchMap((params: ParamMap) => { + this.publicKey = params.get('public_key'); return this.lightningApiService.getNode$(params.get('public_key')); }), map((node) => { @@ -56,6 +59,13 @@ export class NodeComponent implements OnInit { node.socketsObject = socketsObject; return node; }), + catchError(err => { + this.error = err; + return [{ + alias: this.publicKey, + public_key: this.publicKey, + }]; + }) ); }