diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index 75b6857be..69f478fb2 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -178,6 +178,15 @@ class WebsocketHandler { }); if (foundTransactions.length) { + foundTransactions.forEach((tx) => { + tx.status = { + confirmed: true, + block_height: block.height, + block_hash: block.id, + block_time: block.timestamp, + }; + }); + response['address-block-transactions'] = foundTransactions; } } diff --git a/frontend/src/app/components/address/address.component.ts b/frontend/src/app/components/address/address.component.ts index d42569194..5d12e0d9c 100644 --- a/frontend/src/app/components/address/address.component.ts +++ b/frontend/src/app/components/address/address.component.ts @@ -35,29 +35,16 @@ export class AddressComponent implements OnInit, OnDestroy { ngOnInit() { this.websocketService.want(['blocks', 'stats', 'mempool-blocks']); - this.route.paramMap.pipe( - switchMap((params: ParamMap) => { + this.route.paramMap + .subscribe((params: ParamMap) => { this.error = undefined; this.isLoadingAddress = true; this.isLoadingTransactions = true; this.transactions = null; document.body.scrollTo(0, 0); this.addressString = params.get('id') || ''; - return this.electrsApiService.getAddress$(this.addressString); - }) - ) - .subscribe((address) => { - this.address = address; - this.updateChainStats(); - this.websocketService.startTrackAddress(address.address); - this.isLoadingAddress = false; - this.reloadAddressTransactions(address.address); - }, - (error) => { - console.log(error); - this.error = error; - this.isLoadingAddress = false; - }); + this.loadAddress(this.addressString); + }); this.stateService.mempoolTransactions$ .subscribe((transaction) => { @@ -100,12 +87,27 @@ export class AddressComponent implements OnInit, OnDestroy { this.stateService.isOffline$ .subscribe((state) => { if (!state && this.transactions && this.transactions.length) { - this.isLoadingTransactions = true; - this.reloadAddressTransactions(this.address.address); + this.loadAddress(this.addressString); } }); } + loadAddress(addressStr?: string) { + this.electrsApiService.getAddress$(addressStr) + .subscribe((address) => { + this.address = address; + this.updateChainStats(); + this.websocketService.startTrackAddress(address.address); + this.isLoadingAddress = false; + this.reloadAddressTransactions(address.address); + }, + (error) => { + console.log(error); + this.error = error; + this.isLoadingAddress = false; + }); + } + updateChainStats() { this.receieved = this.address.chain_stats.funded_txo_sum + this.address.mempool_stats.funded_txo_sum; this.sent = this.address.chain_stats.spent_txo_sum + this.address.mempool_stats.spent_txo_sum; @@ -118,7 +120,6 @@ export class AddressComponent implements OnInit, OnDestroy { this.electrsApiService.getAddressTransactions$(address) .subscribe((transactions: any) => { this.transactions = transactions; - this.updateChainStats(); this.isLoadingTransactions = false; }); } diff --git a/frontend/src/app/components/qrcode/qrcode.component.ts b/frontend/src/app/components/qrcode/qrcode.component.ts index 9559fc367..ca8601b5f 100644 --- a/frontend/src/app/components/qrcode/qrcode.component.ts +++ b/frontend/src/app/components/qrcode/qrcode.component.ts @@ -35,7 +35,7 @@ export class QrcodeComponent implements AfterViewInit { address.toUpperCase(); } - QRCode.toCanvas(this.canvas.nativeElement, address, opts, (error: any) => { + QRCode.toCanvas(this.canvas.nativeElement, 'bitcoin:' + address, opts, (error: any) => { if (error) { console.error(error); } diff --git a/frontend/src/app/services/websocket.service.ts b/frontend/src/app/services/websocket.service.ts index fbf4faed0..a89d09ce0 100644 --- a/frontend/src/app/services/websocket.service.ts +++ b/frontend/src/app/services/websocket.service.ts @@ -27,18 +27,6 @@ export class WebsocketService { startSubscription() { this.websocketSubject.next({'action': 'init'}); this.websocketSubject - .pipe( - retryWhen((errors: any) => errors - .pipe( - tap(() => { - this.goneOffline = true; - this.websocketSubject.next({'action': 'init'}); - this.stateService.isOffline$.next(true); - }), - delay(5000), - ) - ), - ) .subscribe((response: WebsocketResponse) => { if (response.blocks && response.blocks.length) { const blocks = response.blocks; @@ -110,6 +98,7 @@ export class WebsocketService { (err: Error) => { console.log(err); this.goneOffline = true; + this.stateService.isOffline$.next(true); console.log('Error, retrying in 10 sec'); window.setTimeout(() => this.startSubscription(), 10000); });