mempool/frontend/src/app/app.component.ts

53 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-07-21 16:59:47 +02:00
import { Component, OnInit } from '@angular/core';
import { MemPoolService } from './services/mem-pool.service';
import { Router } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
navCollapsed = false;
isOffline = false;
searchForm: FormGroup;
constructor(
private memPoolService: MemPoolService,
private router: Router,
private formBuilder: FormBuilder,
) { }
ngOnInit() {
this.searchForm = this.formBuilder.group({
txId: ['', Validators.pattern('^[a-fA-F0-9]{64}$')],
});
2019-07-24 22:08:28 +02:00
this.memPoolService.isOffline$
2019-07-21 16:59:47 +02:00
.subscribe((state) => {
this.isOffline = state;
});
}
collapse(): void {
this.navCollapsed = !this.navCollapsed;
}
search() {
const txId = this.searchForm.value.txId;
if (txId) {
if (window.location.pathname === '/' || window.location.pathname.substr(0, 4) === '/tx/') {
window.history.pushState({}, '', `/tx/${txId}`);
} else {
this.router.navigate(['/tx/', txId]);
}
2019-07-24 22:08:28 +02:00
this.memPoolService.txIdSearch$.next(txId);
2019-07-21 16:59:47 +02:00
this.searchForm.setValue({
txId: '',
});
this.collapse();
}
}
}