diff --git a/backend/src/routes.ts b/backend/src/routes.ts index 59afcfd59..a9d59b89c 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -96,7 +96,11 @@ class Routes { const result = await bitcoinApi.getRawTransaction(req.params.id); res.send(result); } 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); res.send(result); } 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); res.send(result); } 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); res.send(result); } 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); res.send(result); } 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); res.send(result); } 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); res.send(result); } 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); + } } } } diff --git a/frontend/src/app/explorer/address/address.component.html b/frontend/src/app/explorer/address/address.component.html index f2d462bc1..2f821d1d3 100644 --- a/frontend/src/app/explorer/address/address.component.html +++ b/frontend/src/app/explorer/address/address.component.html @@ -36,7 +36,7 @@ -
+
@@ -72,7 +72,7 @@
Error loading address data.
- {{ error.message }} + {{ error.error }}
diff --git a/frontend/src/app/explorer/address/address.component.scss b/frontend/src/app/explorer/address/address.component.scss index dd52f25df..4c671d3b8 100644 --- a/frontend/src/app/explorer/address/address.component.scss +++ b/frontend/src/app/explorer/address/address.component.scss @@ -11,4 +11,5 @@ background-color: #FFF; padding: 10px; display: inline-block; + margin-right: 25px; } \ No newline at end of file diff --git a/frontend/src/app/explorer/address/address.component.ts b/frontend/src/app/explorer/address/address.component.ts index 323381e94..f81a759a3 100644 --- a/frontend/src/app/explorer/address/address.component.ts +++ b/frontend/src/app/explorer/address/address.component.ts @@ -38,6 +38,7 @@ export class AddressComponent implements OnInit { this.ref.markForCheck(); }, (error) => { + console.log(error); this.error = error; this.isLoadingAddress = false; }); diff --git a/frontend/src/app/explorer/block/block.component.html b/frontend/src/app/explorer/block/block.component.html index 33a89e0f3..6b71666de 100644 --- a/frontend/src/app/explorer/block/block.component.html +++ b/frontend/src/app/explorer/block/block.component.html @@ -77,7 +77,7 @@
Error loading block data.
- {{ error.message }} + {{ error.error }}
diff --git a/frontend/src/app/explorer/transaction/transaction.component.html b/frontend/src/app/explorer/transaction/transaction.component.html index beaff5d09..9248afd08 100644 --- a/frontend/src/app/explorer/transaction/transaction.component.html +++ b/frontend/src/app/explorer/transaction/transaction.component.html @@ -61,7 +61,7 @@
Error loading transaction data.
- {{ error.message }} + {{ error.error }}
diff --git a/frontend/src/app/master-page/master-page.component.html b/frontend/src/app/master-page/master-page.component.html index acaf151e2..1df7876bb 100644 --- a/frontend/src/app/master-page/master-page.component.html +++ b/frontend/src/app/master-page/master-page.component.html @@ -26,8 +26,16 @@
- - + + + + + + + + + +
diff --git a/frontend/src/app/master-page/master-page.component.ts b/frontend/src/app/master-page/master-page.component.ts index fbde49166..1bb3dcf50 100644 --- a/frontend/src/app/master-page/master-page.component.ts +++ b/frontend/src/app/master-page/master-page.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; 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 { environment } from '../../environments/environment'; @@ -10,11 +10,13 @@ import { environment } from '../../environments/environment'; styleUrls: ['./master-page.component.scss'] }) export class MasterPageComponent implements OnInit { - navCollapsed = false; isOffline = false; searchForm: FormGroup; 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( private memPoolService: MemPoolService, @@ -24,13 +26,20 @@ export class MasterPageComponent implements OnInit { ngOnInit() { this.searchForm = this.formBuilder.group({ - txId: ['', Validators.pattern('^[a-fA-F0-9]{64}$')], + txId: [''], }); this.memPoolService.isOffline$ .subscribe((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 { @@ -38,14 +47,22 @@ export class MasterPageComponent implements OnInit { } 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}`); + const searchText = this.searchForm.value.txId; + if (searchText) { + if (this.currentBaseRoot === 'explorer') { + if (this.regexAddr.test(searchText)) { + this.router.navigate(['/explorer/address/', searchText]); + } else { + this.router.navigate(['/explorer/tx/', searchText]); + } } 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({ txId: '', });