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 902379552..a99dc084e 100644 --- a/frontend/src/app/components/search-form/search-form.component.ts +++ b/frontend/src/app/components/search-form/search-form.component.ts @@ -40,6 +40,8 @@ export class SearchFormComponent implements OnInit { regexBlockhash = /^[0]{8}[a-fA-F0-9]{56}$/; regexTransaction = /^([a-fA-F0-9]{64})(:\d+)?$/; 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(); click$ = new Subject(); @@ -173,6 +175,8 @@ export class SearchFormComponent implements OnInit { const lightningResults = result[1]; 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 matchesBlockHash = this.regexBlockhash.test(searchText); const matchesAddress = !matchesTxId && this.regexAddress.test(searchText); @@ -181,10 +185,16 @@ export class SearchFormComponent implements OnInit { searchText = 'B' + searchText; } + if (matchesDateTime && searchText.indexOf('/') !== -1) { + searchText = searchText.replace(/\//g, '-'); + } + return { searchText: searchText, - hashQuickMatch: +(matchesBlockHeight || matchesBlockHash || matchesTxId || matchesAddress), + hashQuickMatch: +(matchesBlockHeight || matchesBlockHash || matchesTxId || matchesAddress || matchesUnixTimestamp || matchesDateTime), blockHeight: matchesBlockHeight, + dateTime: matchesDateTime, + unixTimestamp: matchesUnixTimestamp, txId: matchesTxId, blockHash: matchesBlockHash, address: matchesAddress, @@ -243,6 +253,13 @@ export class SearchFormComponent implements OnInit { } else { 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 { this.searchResults.searchButtonClick(); this.isSearching = false; 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 b0d043f53..d4f68edbd 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 @@ -5,6 +5,18 @@ + +
Date
+ +
+ +
Timestamp
+ +
Bitcoin Transaction