mirror of
https://github.com/mempool/mempool.git
synced 2024-12-28 01:04:28 +01:00
Add typeahead address prefix.
This commit is contained in:
parent
d2673281f9
commit
81d05e23b8
@ -39,6 +39,7 @@ import { AssetsComponent } from './assets/assets.component';
|
|||||||
import { StatusViewComponent } from './components/status-view/status-view.component';
|
import { StatusViewComponent } from './components/status-view/status-view.component';
|
||||||
import { MinerComponent } from './components/miner/miner.component';
|
import { MinerComponent } from './components/miner/miner.component';
|
||||||
import { SharedModule } from './shared/shared.module';
|
import { SharedModule } from './shared/shared.module';
|
||||||
|
import { NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@ -76,6 +77,7 @@ import { SharedModule } from './shared/shared.module';
|
|||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
BrowserAnimationsModule,
|
BrowserAnimationsModule,
|
||||||
InfiniteScrollModule,
|
InfiniteScrollModule,
|
||||||
|
NgbTypeaheadModule,
|
||||||
SharedModule,
|
SharedModule,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<form [formGroup]="searchForm" (submit)="searchForm.valid && search()" class="mr-4" novalidate>
|
<form [formGroup]="searchForm" (submit)="searchForm.valid && search()" class="mr-4" novalidate>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div style="width: 350px;" class="mr-2">
|
<div style="width: 350px;" class="mr-2">
|
||||||
<input formControlName="searchText" type="text" class="form-control" placeholder="Transaction, block height, hash or address">
|
<input #instance="ngbTypeahead" [ngbTypeahead]="typeaheadSearch" (focus)="focus$.next($any($event).target.value)" (click)="click$.next($any($event).target.value)" formControlName="searchText" type="text" class="form-control" placeholder="Transaction, block height, hash or address">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button type="submit" class="btn btn-block btn-primary">Search</button>
|
<button type="submit" class="btn btn-block btn-primary">Search</button>
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
import { Component, OnInit, ChangeDetectionStrategy, EventEmitter, Output } from '@angular/core';
|
import { Component, OnInit, ChangeDetectionStrategy, EventEmitter, Output, ViewChild } from '@angular/core';
|
||||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { AssetsService } from 'src/app/services/assets.service';
|
import { AssetsService } from 'src/app/services/assets.service';
|
||||||
import { StateService } from 'src/app/services/state.service';
|
import { StateService } from 'src/app/services/state.service';
|
||||||
|
import { Observable, of, Subject, merge } from 'rxjs';
|
||||||
|
import { debounceTime, distinctUntilChanged, switchMap, filter } from 'rxjs/operators';
|
||||||
|
import { ElectrsApiService } from 'src/app/services/electrs-api.service';
|
||||||
|
import { NgbTypeahead } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-search-form',
|
selector: 'app-search-form',
|
||||||
@ -22,11 +26,30 @@ export class SearchFormComponent implements OnInit {
|
|||||||
regexTransaction = /^[a-fA-F0-9]{64}$/;
|
regexTransaction = /^[a-fA-F0-9]{64}$/;
|
||||||
regexBlockheight = /^[0-9]+$/;
|
regexBlockheight = /^[0-9]+$/;
|
||||||
|
|
||||||
|
@ViewChild('instance', {static: true}) instance: NgbTypeahead;
|
||||||
|
focus$ = new Subject<string>();
|
||||||
|
click$ = new Subject<string>();
|
||||||
|
|
||||||
|
typeaheadSearch = (text$: Observable<string>) => {
|
||||||
|
const debouncedText$ = text$.pipe(debounceTime(200), distinctUntilChanged());
|
||||||
|
const clicksWithClosedPopup$ = this.click$.pipe(filter(() => !this.instance.isPopupOpen()));
|
||||||
|
const inputFocus$ = this.focus$;
|
||||||
|
|
||||||
|
return merge(debouncedText$, inputFocus$, clicksWithClosedPopup$)
|
||||||
|
.pipe(
|
||||||
|
switchMap((text) => {
|
||||||
|
if (!text.length) { return of([]); }
|
||||||
|
return this.electrsApiService.getAddressesByPrefix$(text);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private assetsService: AssetsService,
|
private assetsService: AssetsService,
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
|
private electrsApiService: ElectrsApiService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
@ -81,4 +81,7 @@ export class ElectrsApiService {
|
|||||||
return this.httpClient.get<Transaction[]>(this.apiBaseUrl + '/asset/' + assetId + '/txs/chain/' + txid);
|
return this.httpClient.get<Transaction[]>(this.apiBaseUrl + '/asset/' + assetId + '/txs/chain/' + txid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAddressesByPrefix$(prefix: string): Observable<string[]> {
|
||||||
|
return this.httpClient.get<string[]>(this.apiBaseUrl + '/address-prefix/' + prefix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user