From b6296fcbeb7780be963ad4acd7b10cb5080bbdbd Mon Sep 17 00:00:00 2001 From: softsimon Date: Mon, 12 Sep 2022 19:20:22 +0200 Subject: [PATCH] Suggest block height in search result --- .../search-form/search-form.component.html | 2 +- .../search-form/search-form.component.ts | 18 ++++++++++++----- .../search-results.component.html | 20 ++++++++++++------- .../search-results.component.ts | 9 +++++---- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/frontend/src/app/components/search-form/search-form.component.html b/frontend/src/app/components/search-form/search-form.component.html index 8badcc3cf..f8cb05d1c 100644 --- a/frontend/src/app/components/search-form/search-form.component.html +++ b/frontend/src/app/components/search-form/search-form.component.html @@ -3,7 +3,7 @@
- +
diff --git a/frontend/src/app/components/search-form/search-form.component.ts b/frontend/src/app/components/search-form/search-form.component.ts index 712f7438c..abddc3b6e 100644 --- a/frontend/src/app/components/search-form/search-form.component.ts +++ b/frontend/src/app/components/search-form/search-form.component.ts @@ -74,6 +74,7 @@ export class SearchFormComponent implements OnInit { switchMap((text) => { if (!text.length) { return of([ + '', [], { nodes: [], @@ -84,11 +85,14 @@ export class SearchFormComponent implements OnInit { this.isTypeaheading$.next(true); if (!this.stateService.env.LIGHTNING) { return zip( + of(text), this.electrsApiService.getAddressesByPrefix$(text).pipe(catchError(() => of([]))), - [{ nodes: [], channels: [] }] + [{ nodes: [], channels: [] }], + of(this.regexBlockheight.test(text)), ); } return zip( + of(text), this.electrsApiService.getAddressesByPrefix$(text).pipe(catchError(() => of([]))), this.apiService.lightningSearch$(text).pipe(catchError(() => of({ nodes: [], @@ -102,10 +106,12 @@ export class SearchFormComponent implements OnInit { return result[0].map((address: string) => 'B' + address); } return { - addresses: result[0], - nodes: result[1].nodes, - channels: result[1].channels, - totalResults: result[0].length + result[1].nodes.length + result[1].channels.length, + searchText: result[0], + blockHeight: this.regexBlockheight.test(result[0]) ? [parseInt(result[0], 10)] : [], + addresses: result[1], + nodes: result[2].nodes, + channels: result[2].channels, + totalResults: result[1].length + result[2].nodes.length + result[2].channels.length, }; }) ); @@ -121,6 +127,8 @@ export class SearchFormComponent implements OnInit { selectedResult(result: any) { if (typeof result === 'string') { this.search(result); + } else if (typeof result === 'number') { + this.navigate('/block/', result.toString()); } else if (result.alias) { this.navigate('/lightning/node/', result.public_key); } else if (result.short_id) { diff --git a/frontend/src/app/components/search-form/search-results/search-results.component.html b/frontend/src/app/components/search-form/search-results/search-results.component.html index cc289ddac..9ed829aff 100644 --- a/frontend/src/app/components/search-form/search-results/search-results.component.html +++ b/frontend/src/app/components/search-form/search-results/search-results.component.html @@ -1,25 +1,31 @@ -