Confirmed address transactions fix. QR Code fix. (take 2)

This commit is contained in:
softsimon 2020-02-26 23:21:16 +07:00
parent 37166e230d
commit 23a61a37fd
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
4 changed files with 32 additions and 33 deletions

View File

@ -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;
}
}

View File

@ -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;
});
}

View File

@ -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);
}

View File

@ -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);
});