Add date and timestamp search option
This commit is contained in:
parent
1c92394563
commit
2584a1f2b0
@ -40,6 +40,8 @@ export class SearchFormComponent implements OnInit {
|
|||||||
regexBlockhash = /^[0]{8}[a-fA-F0-9]{56}$/;
|
regexBlockhash = /^[0]{8}[a-fA-F0-9]{56}$/;
|
||||||
regexTransaction = /^([a-fA-F0-9]{64})(:\d+)?$/;
|
regexTransaction = /^([a-fA-F0-9]{64})(:\d+)?$/;
|
||||||
regexBlockheight = /^[0-9]{1,9}$/;
|
regexBlockheight = /^[0-9]{1,9}$/;
|
||||||
|
regexDate = /^(?:\d{4}[-/]\d{1,2}[-/]\d{1,2}(?: \d{1,2}:\d{2})?)$/;
|
||||||
|
regexUnixTimestamp = /^\d{10}$/;
|
||||||
focus$ = new Subject<string>();
|
focus$ = new Subject<string>();
|
||||||
click$ = new Subject<string>();
|
click$ = new Subject<string>();
|
||||||
|
|
||||||
@ -173,6 +175,8 @@ export class SearchFormComponent implements OnInit {
|
|||||||
const lightningResults = result[1];
|
const lightningResults = result[1];
|
||||||
|
|
||||||
const matchesBlockHeight = this.regexBlockheight.test(searchText);
|
const matchesBlockHeight = this.regexBlockheight.test(searchText);
|
||||||
|
const matchesDateTime = this.regexDate.test(searchText) && new Date(searchText).toString() !== 'Invalid Date';
|
||||||
|
const matchesUnixTimestamp = this.regexUnixTimestamp.test(searchText);
|
||||||
const matchesTxId = this.regexTransaction.test(searchText) && !this.regexBlockhash.test(searchText);
|
const matchesTxId = this.regexTransaction.test(searchText) && !this.regexBlockhash.test(searchText);
|
||||||
const matchesBlockHash = this.regexBlockhash.test(searchText);
|
const matchesBlockHash = this.regexBlockhash.test(searchText);
|
||||||
const matchesAddress = !matchesTxId && this.regexAddress.test(searchText);
|
const matchesAddress = !matchesTxId && this.regexAddress.test(searchText);
|
||||||
@ -181,10 +185,16 @@ export class SearchFormComponent implements OnInit {
|
|||||||
searchText = 'B' + searchText;
|
searchText = 'B' + searchText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (matchesDateTime && searchText.indexOf('/') !== -1) {
|
||||||
|
searchText = searchText.replace(/\//g, '-');
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
searchText: searchText,
|
searchText: searchText,
|
||||||
hashQuickMatch: +(matchesBlockHeight || matchesBlockHash || matchesTxId || matchesAddress),
|
hashQuickMatch: +(matchesBlockHeight || matchesBlockHash || matchesTxId || matchesAddress || matchesUnixTimestamp || matchesDateTime),
|
||||||
blockHeight: matchesBlockHeight,
|
blockHeight: matchesBlockHeight,
|
||||||
|
dateTime: matchesDateTime,
|
||||||
|
unixTimestamp: matchesUnixTimestamp,
|
||||||
txId: matchesTxId,
|
txId: matchesTxId,
|
||||||
blockHash: matchesBlockHash,
|
blockHash: matchesBlockHash,
|
||||||
address: matchesAddress,
|
address: matchesAddress,
|
||||||
@ -243,6 +253,13 @@ export class SearchFormComponent implements OnInit {
|
|||||||
} else {
|
} else {
|
||||||
this.navigate('/tx/', matches[0]);
|
this.navigate('/tx/', matches[0]);
|
||||||
}
|
}
|
||||||
|
} else if (this.regexDate.test(searchText) || this.regexUnixTimestamp.test(searchText)) {
|
||||||
|
let timestamp: number;
|
||||||
|
this.regexDate.test(searchText) ? timestamp = Math.floor(new Date(searchText).getTime() / 1000) : timestamp = searchText;
|
||||||
|
this.apiService.getBlockDataFromTimestamp$(timestamp).subscribe(
|
||||||
|
(data) => { this.navigate('/block/', data.hash); },
|
||||||
|
(error) => { console.log(error); this.isSearching = false; }
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
this.searchResults.searchButtonClick();
|
this.searchResults.searchButtonClick();
|
||||||
this.isSearching = false;
|
this.isSearching = false;
|
||||||
|
@ -5,6 +5,18 @@
|
|||||||
<ng-container *ngTemplateOutlet="goTo; context: { $implicit: results.searchText }"></ng-container>
|
<ng-container *ngTemplateOutlet="goTo; context: { $implicit: results.searchText }"></ng-container>
|
||||||
</button>
|
</button>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
<ng-template [ngIf]="results.dateTime">
|
||||||
|
<div class="card-title" i18n="search.bitcoin-block-date">Date</div>
|
||||||
|
<button (click)="clickItem(0)" [class.active]="0 === activeIdx" type="button" role="option" class="dropdown-item">
|
||||||
|
<ng-container *ngTemplateOutlet="goTo; context: { $implicit: results.searchText }"></ng-container>
|
||||||
|
</button>
|
||||||
|
</ng-template>
|
||||||
|
<ng-template [ngIf]="results.unixTimestamp">
|
||||||
|
<div class="card-title" i18n="search.bitcoin-block-timestamp">Timestamp</div>
|
||||||
|
<button (click)="clickItem(0)" [class.active]="0 === activeIdx" type="button" role="option" class="dropdown-item">
|
||||||
|
<ng-container *ngTemplateOutlet="goTo; context: { $implicit: results.searchText }"></ng-container>
|
||||||
|
</button>
|
||||||
|
</ng-template>
|
||||||
<ng-template [ngIf]="results.txId">
|
<ng-template [ngIf]="results.txId">
|
||||||
<div class="card-title" i18n="search.bitcoin-transaction">Bitcoin Transaction</div>
|
<div class="card-title" i18n="search.bitcoin-transaction">Bitcoin Transaction</div>
|
||||||
<button (click)="clickItem(0)" [class.active]="0 === activeIdx" type="button" role="option" class="dropdown-item">
|
<button (click)="clickItem(0)" [class.active]="0 === activeIdx" type="button" role="option" class="dropdown-item">
|
||||||
|
@ -227,6 +227,10 @@ export class ApiService {
|
|||||||
return this.httpClient.get<BlockExtended>(this.apiBaseUrl + this.apiBasePath + '/api/v1/block/' + hash);
|
return this.httpClient.get<BlockExtended>(this.apiBaseUrl + this.apiBasePath + '/api/v1/block/' + hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBlockDataFromTimestamp$(timestamp: number): Observable<any> {
|
||||||
|
return this.httpClient.get<number>(this.apiBaseUrl + this.apiBasePath + '/api/v1/mining/blocks/timestamp/' + timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
getStrippedBlockTransactions$(hash: string): Observable<TransactionStripped[]> {
|
getStrippedBlockTransactions$(hash: string): Observable<TransactionStripped[]> {
|
||||||
return this.httpClient.get<TransactionStripped[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/block/' + hash + '/summary');
|
return this.httpClient.get<TransactionStripped[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/block/' + hash + '/summary');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user