2020-07-13 15:16:12 +07:00
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
2020-07-16 16:18:35 +07:00
|
|
|
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
|
2020-07-13 15:16:12 +07:00
|
|
|
import { BisqTransaction } from 'src/app/bisq/bisq.interfaces';
|
2020-07-16 16:18:35 +07:00
|
|
|
import { switchMap, map, catchError } from 'rxjs/operators';
|
2020-07-13 15:16:12 +07:00
|
|
|
import { of, Observable, Subscription } from 'rxjs';
|
|
|
|
import { StateService } from 'src/app/services/state.service';
|
2020-07-19 15:28:27 +07:00
|
|
|
import { Block, Transaction } from 'src/app/interfaces/electrs.interface';
|
2020-07-13 15:16:12 +07:00
|
|
|
import { BisqApiService } from '../bisq-api.service';
|
2020-07-13 21:46:25 +07:00
|
|
|
import { SeoService } from 'src/app/services/seo.service';
|
2020-07-16 16:18:35 +07:00
|
|
|
import { ElectrsApiService } from 'src/app/services/electrs-api.service';
|
|
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
2020-07-11 00:17:13 +07:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-bisq-transaction',
|
|
|
|
templateUrl: './bisq-transaction.component.html',
|
|
|
|
styleUrls: ['./bisq-transaction.component.scss']
|
|
|
|
})
|
2020-07-13 15:16:12 +07:00
|
|
|
export class BisqTransactionComponent implements OnInit, OnDestroy {
|
2020-07-11 00:17:13 +07:00
|
|
|
bisqTx: BisqTransaction;
|
2020-07-19 15:28:27 +07:00
|
|
|
tx: Transaction;
|
2020-07-13 15:16:12 +07:00
|
|
|
latestBlock$: Observable<Block>;
|
2020-07-11 00:17:13 +07:00
|
|
|
txId: string;
|
2020-07-14 21:26:02 +07:00
|
|
|
price: number;
|
2020-07-13 15:16:12 +07:00
|
|
|
isLoading = true;
|
2020-07-19 15:28:27 +07:00
|
|
|
isLoadingTx = true;
|
2020-07-16 16:18:35 +07:00
|
|
|
error = null;
|
2020-07-13 15:16:12 +07:00
|
|
|
subscription: Subscription;
|
2020-07-11 00:17:13 +07:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
2020-07-13 15:16:12 +07:00
|
|
|
private bisqApiService: BisqApiService,
|
2020-07-16 16:18:35 +07:00
|
|
|
private electrsApiService: ElectrsApiService,
|
2020-07-13 15:16:12 +07:00
|
|
|
private stateService: StateService,
|
2020-07-13 21:46:25 +07:00
|
|
|
private seoService: SeoService,
|
2020-07-16 16:18:35 +07:00
|
|
|
private router: Router,
|
2020-07-11 00:17:13 +07:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-07-13 15:16:12 +07:00
|
|
|
this.subscription = this.route.paramMap.pipe(
|
2020-07-11 00:17:13 +07:00
|
|
|
switchMap((params: ParamMap) => {
|
2020-07-13 15:16:12 +07:00
|
|
|
this.isLoading = true;
|
2020-07-19 15:28:27 +07:00
|
|
|
this.isLoadingTx = true;
|
2020-07-16 16:18:35 +07:00
|
|
|
this.error = null;
|
2020-07-13 21:46:25 +07:00
|
|
|
document.body.scrollTo(0, 0);
|
2020-07-11 00:17:13 +07:00
|
|
|
this.txId = params.get('id') || '';
|
2020-08-12 14:04:04 +07:00
|
|
|
this.seoService.setTitle('Transaction: ' + this.txId);
|
2020-07-13 15:16:12 +07:00
|
|
|
if (history.state.data) {
|
|
|
|
return of(history.state.data);
|
2020-07-11 00:17:13 +07:00
|
|
|
}
|
2020-07-16 16:18:35 +07:00
|
|
|
return this.bisqApiService.getTransaction$(this.txId)
|
|
|
|
.pipe(
|
|
|
|
catchError((bisqTxError: HttpErrorResponse) => {
|
|
|
|
if (bisqTxError.status === 404) {
|
|
|
|
return this.electrsApiService.getTransaction$(this.txId)
|
|
|
|
.pipe(
|
2020-07-18 13:09:57 +07:00
|
|
|
map((tx) => {
|
|
|
|
if (tx.status.confirmed) {
|
|
|
|
this.error = {
|
|
|
|
status: 200,
|
|
|
|
statusText: 'Transaction is confirmed but not available in the Bisq database, please try reloading this page.'
|
|
|
|
};
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return tx;
|
|
|
|
}),
|
2020-07-16 16:18:35 +07:00
|
|
|
catchError((txError: HttpErrorResponse) => {
|
|
|
|
console.log(txError);
|
|
|
|
this.error = txError;
|
|
|
|
return of(null);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
this.error = bisqTxError;
|
|
|
|
return of(null);
|
|
|
|
})
|
|
|
|
);
|
2020-07-19 15:28:27 +07:00
|
|
|
}),
|
|
|
|
switchMap((tx) => {
|
|
|
|
if (!tx) {
|
|
|
|
return of(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tx.version) {
|
|
|
|
this.router.navigate(['/tx/', this.txId], { state: { data: tx, bsqTx: true }});
|
|
|
|
return of(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.bisqTx = tx;
|
|
|
|
this.isLoading = false;
|
|
|
|
|
|
|
|
return this.electrsApiService.getTransaction$(this.txId);
|
|
|
|
}),
|
2020-07-11 00:17:13 +07:00
|
|
|
)
|
|
|
|
.subscribe((tx) => {
|
2020-07-19 15:28:27 +07:00
|
|
|
this.isLoadingTx = false;
|
2020-07-16 16:18:35 +07:00
|
|
|
|
|
|
|
if (!tx) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-19 15:28:27 +07:00
|
|
|
this.tx = tx;
|
2020-07-16 16:18:35 +07:00
|
|
|
},
|
|
|
|
(error) => {
|
|
|
|
this.error = error;
|
2020-07-11 00:17:13 +07:00
|
|
|
});
|
2020-07-13 15:16:12 +07:00
|
|
|
|
|
|
|
this.latestBlock$ = this.stateService.blocks$.pipe(map((([block]) => block)));
|
2020-07-14 21:26:02 +07:00
|
|
|
|
|
|
|
this.stateService.bsqPrice$
|
|
|
|
.subscribe((bsqPrice) => {
|
|
|
|
this.price = bsqPrice;
|
|
|
|
});
|
2020-07-13 15:16:12 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscription.unsubscribe();
|
2020-07-11 00:17:13 +07:00
|
|
|
}
|
|
|
|
}
|