Search box for explorer.
This commit is contained in:
parent
480016ef07
commit
9e212ab176
@ -96,7 +96,11 @@ class Routes {
|
|||||||
const result = await bitcoinApi.getRawTransaction(req.params.id);
|
const result = await bitcoinApi.getRawTransaction(req.params.id);
|
||||||
res.send(result);
|
res.send(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(500).send(e.message);
|
if (e.response) {
|
||||||
|
res.status(e.response.status).send(e.response.data);
|
||||||
|
} else {
|
||||||
|
e.status(500, e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +109,11 @@ class Routes {
|
|||||||
const result = await bitcoinApi.getBlock(req.params.hash);
|
const result = await bitcoinApi.getBlock(req.params.hash);
|
||||||
res.send(result);
|
res.send(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(500).send(e.message);
|
if (e.response) {
|
||||||
|
res.status(e.response.status).send(e.response.data);
|
||||||
|
} else {
|
||||||
|
e.status(500, e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +122,15 @@ class Routes {
|
|||||||
const result = await bitcoinApi.getBlockTransactions(req.params.hash);
|
const result = await bitcoinApi.getBlockTransactions(req.params.hash);
|
||||||
res.send(result);
|
res.send(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(500).send(e.message);
|
if (e.response) {
|
||||||
|
res.status(e.response.status).send(e.response.data);
|
||||||
|
} else {
|
||||||
|
if (e.response) {
|
||||||
|
res.status(e.response.status).send(e.response.data);
|
||||||
|
} else {
|
||||||
|
e.status(500, e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +139,15 @@ class Routes {
|
|||||||
const result = await bitcoinApi.getBlockTransactionsFromIndex(req.params.hash, req.params.index);
|
const result = await bitcoinApi.getBlockTransactionsFromIndex(req.params.hash, req.params.index);
|
||||||
res.send(result);
|
res.send(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(500).send(e.message);
|
if (e.response) {
|
||||||
|
res.status(e.response.status).send(e.response.data);
|
||||||
|
} else {
|
||||||
|
if (e.response) {
|
||||||
|
res.status(e.response.status).send(e.response.data);
|
||||||
|
} else {
|
||||||
|
e.status(500, e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +156,15 @@ class Routes {
|
|||||||
const result = await bitcoinApi.getAddress(req.params.address);
|
const result = await bitcoinApi.getAddress(req.params.address);
|
||||||
res.send(result);
|
res.send(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(500).send(e.message);
|
if (e.response) {
|
||||||
|
res.status(e.response.status).send(e.response.data);
|
||||||
|
} else {
|
||||||
|
if (e.response) {
|
||||||
|
res.status(e.response.status).send(e.response.data);
|
||||||
|
} else {
|
||||||
|
e.status(500, e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +173,11 @@ class Routes {
|
|||||||
const result = await bitcoinApi.getAddressTransactions(req.params.address);
|
const result = await bitcoinApi.getAddressTransactions(req.params.address);
|
||||||
res.send(result);
|
res.send(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(500).send(e.message);
|
if (e.response) {
|
||||||
|
res.status(e.response.status).send(e.response.data);
|
||||||
|
} else {
|
||||||
|
e.status(500, e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +186,11 @@ class Routes {
|
|||||||
const result = await bitcoinApi.getAddressTransactionsFromLastSeenTxid(req.params.address, req.params.txid);
|
const result = await bitcoinApi.getAddressTransactionsFromLastSeenTxid(req.params.address, req.params.txid);
|
||||||
res.send(result);
|
res.send(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(500).send(e.message);
|
if (e.response) {
|
||||||
|
res.status(e.response.status).send(e.response.data);
|
||||||
|
} else {
|
||||||
|
e.status(500, e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="col text-center">
|
<div class="col text-right">
|
||||||
<div class="qr-wrapper">
|
<div class="qr-wrapper">
|
||||||
<qrcode id="qrCode" [qrdata]="address.address" [size]="128" [level]="'M'"></qrcode>
|
<qrcode id="qrCode" [qrdata]="address.address" [size]="128" [level]="'M'"></qrcode>
|
||||||
</div>
|
</div>
|
||||||
@ -72,7 +72,7 @@
|
|||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
Error loading address data.
|
Error loading address data.
|
||||||
<br>
|
<br>
|
||||||
<i>{{ error.message }}</i>
|
<i>{{ error.error }}</i>
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
|
@ -11,4 +11,5 @@
|
|||||||
background-color: #FFF;
|
background-color: #FFF;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
margin-right: 25px;
|
||||||
}
|
}
|
@ -38,6 +38,7 @@ export class AddressComponent implements OnInit {
|
|||||||
this.ref.markForCheck();
|
this.ref.markForCheck();
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
console.log(error);
|
||||||
this.error = error;
|
this.error = error;
|
||||||
this.isLoadingAddress = false;
|
this.isLoadingAddress = false;
|
||||||
});
|
});
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
Error loading block data.
|
Error loading block data.
|
||||||
<br>
|
<br>
|
||||||
<i>{{ error.message }}</i>
|
<i>{{ error.error }}</i>
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
Error loading transaction data.
|
Error loading transaction data.
|
||||||
<br>
|
<br>
|
||||||
<i>{{ error.message }}</i>
|
<i>{{ error.error }}</i>
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</div>
|
</div>
|
||||||
|
@ -26,8 +26,16 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<form [formGroup]="searchForm" class="form-inline mt-2 mt-md-0 mr-4" (submit)="searchForm.valid && search()" novalidate>
|
<form [formGroup]="searchForm" class="form-inline mt-2 mt-md-0 mr-4" (submit)="searchForm.valid && search()" novalidate>
|
||||||
<input formControlName="txId" required style="width: 300px;" class="form-control mr-sm-2" type="text" placeholder="Search transaction ID" aria-label="Search">
|
|
||||||
<button class="btn btn-primary my-2 my-sm-0" type="submit">Track</button>
|
<ng-template [ngIf]="currentBaseRoot === 'explorer'" [ngIfElse]="defaultSearchBar">
|
||||||
|
<input formControlName="txId" required style="width: 310px;" class="form-control mr-sm-2" type="text" placeholder="Search transaction id or address..." aria-label="Search">
|
||||||
|
<button class="btn btn-primary my-2 my-sm-0" type="submit" style="width: 78px;">Search</button>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<ng-template #defaultSearchBar>
|
||||||
|
<input formControlName="txId" required style="width: 310px;" class="form-control mr-sm-2" type="text" placeholder="Track transaction (txid)" aria-label="Search">
|
||||||
|
<button class="btn btn-primary my-2 my-sm-0" type="submit" style="width: 78px;">Track</button>
|
||||||
|
</ng-template>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { MemPoolService } from '../services/mem-pool.service';
|
import { MemPoolService } from '../services/mem-pool.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router, NavigationEnd } from '@angular/router';
|
||||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
import { environment } from '../../environments/environment';
|
import { environment } from '../../environments/environment';
|
||||||
|
|
||||||
@ -10,11 +10,13 @@ import { environment } from '../../environments/environment';
|
|||||||
styleUrls: ['./master-page.component.scss']
|
styleUrls: ['./master-page.component.scss']
|
||||||
})
|
})
|
||||||
export class MasterPageComponent implements OnInit {
|
export class MasterPageComponent implements OnInit {
|
||||||
|
|
||||||
navCollapsed = false;
|
navCollapsed = false;
|
||||||
isOffline = false;
|
isOffline = false;
|
||||||
searchForm: FormGroup;
|
searchForm: FormGroup;
|
||||||
isEsploraEnabled = !!environment.esplora;
|
isEsploraEnabled = !!environment.esplora;
|
||||||
|
currentBaseRoot = '';
|
||||||
|
|
||||||
|
regexAddr = /^([a-km-zA-HJ-NP-Z1-9]{26,35}|[a-km-zA-HJ-NP-Z1-9]{80}|[a-z]{2,5}1[ac-hj-np-z02-9]{8,87})$/;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private memPoolService: MemPoolService,
|
private memPoolService: MemPoolService,
|
||||||
@ -24,13 +26,20 @@ export class MasterPageComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.searchForm = this.formBuilder.group({
|
this.searchForm = this.formBuilder.group({
|
||||||
txId: ['', Validators.pattern('^[a-fA-F0-9]{64}$')],
|
txId: [''],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.memPoolService.isOffline$
|
this.memPoolService.isOffline$
|
||||||
.subscribe((state) => {
|
.subscribe((state) => {
|
||||||
this.isOffline = state;
|
this.isOffline = state;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.currentBaseRoot = this.router.url.split('/')[1];
|
||||||
|
this.router.events.subscribe((event) => {
|
||||||
|
if (event instanceof NavigationEnd ) {
|
||||||
|
this.currentBaseRoot = event.url.split('/')[1];
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
collapse(): void {
|
collapse(): void {
|
||||||
@ -38,14 +47,22 @@ export class MasterPageComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
search() {
|
search() {
|
||||||
const txId = this.searchForm.value.txId;
|
const searchText = this.searchForm.value.txId;
|
||||||
if (txId) {
|
if (searchText) {
|
||||||
if (window.location.pathname === '/' || window.location.pathname.substr(0, 4) === '/tx/') {
|
if (this.currentBaseRoot === 'explorer') {
|
||||||
window.history.pushState({}, '', `/tx/${txId}`);
|
if (this.regexAddr.test(searchText)) {
|
||||||
|
this.router.navigate(['/explorer/address/', searchText]);
|
||||||
|
} else {
|
||||||
|
this.router.navigate(['/explorer/tx/', searchText]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(['/tx/', txId]);
|
if (window.location.pathname === '/' || window.location.pathname.substr(0, 4) === '/tx/') {
|
||||||
|
window.history.pushState({}, '', `/tx/${searchText}`);
|
||||||
|
} else {
|
||||||
|
this.router.navigate(['/tx/', searchText]);
|
||||||
|
}
|
||||||
|
this.memPoolService.txIdSearch$.next(searchText);
|
||||||
}
|
}
|
||||||
this.memPoolService.txIdSearch$.next(txId);
|
|
||||||
this.searchForm.setValue({
|
this.searchForm.setValue({
|
||||||
txId: '',
|
txId: '',
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user