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' ;
2022-09-21 17:23:45 +02:00
import { BisqTransaction } from '../../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' ;
2022-09-21 17:23:45 +02:00
import { StateService } from '../../services/state.service' ;
import { Block , Transaction } from '../../interfaces/electrs.interface' ;
2020-07-13 15:16:12 +07:00
import { BisqApiService } from '../bisq-api.service' ;
2022-09-21 17:23:45 +02:00
import { SeoService } from '../../services/seo.service' ;
import { ElectrsApiService } from '../../services/electrs-api.service' ;
2020-07-16 16:18:35 +07:00
import { HttpErrorResponse } from '@angular/common/http' ;
2022-09-21 17:23:45 +02:00
import { WebsocketService } from '../../services/websocket.service' ;
2020-07-11 00:17:13 +07:00
@Component ( {
selector : 'app-bisq-transaction' ,
templateUrl : './bisq-transaction.component.html' ,
2024-03-17 17:08:07 +09:00
styleUrls : [ './../../components/transaction/transaction.component.scss' ]
2020-07-11 00:17:13 +07:00
} )
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 (
2021-03-05 15:38:46 +07:00
private websocketService : WebsocketService ,
2020-07-11 00:17:13 +07:00
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 {
2021-03-05 15:38:46 +07:00
this . websocketService . want ( [ 'blocks' ] ) ;
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-12-04 21:29:31 +07:00
this . seoService . setTitle ( $localize ` :@@bisq.transaction.browser-title:Transaction: ${ this . txId } :INTERPOLATION: ` ) ;
2023-08-28 13:10:08 +09:00
this . seoService . setDescription ( $localize ` :@@meta.description.bisq.transaction:See inputs, outputs, transaction type, burnt amount, and more for transaction with txid ${ this . txId } :INTERPOLATION:. ` ) ;
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 ;
2023-03-09 02:34:21 -06:00
this . seoService . logSoft404 ( ) ;
2020-07-16 16:18:35 +07:00
return of ( null ) ;
} )
) ;
}
this . error = bisqTxError ;
2023-03-09 02:34:21 -06:00
this . seoService . logSoft404 ( ) ;
2020-07-16 16:18:35 +07:00
return of ( null ) ;
} )
) ;
2020-07-19 15:28:27 +07:00
} ) ,
switchMap ( ( tx ) = > {
if ( ! tx ) {
return of ( null ) ;
}
if ( tx . version ) {
2021-08-20 14:56:12 +03:00
if ( this . stateService . env . BASE_MODULE === 'bisq' ) {
window . location . replace ( 'https://mempool.space/tx/' + this . txId ) ;
} else {
this . router . navigate ( [ '/tx/' , this . txId ] , { state : { data : tx , bsqTx : true } } ) ;
}
2020-07-19 15:28:27 +07:00
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 ) {
2023-03-09 02:34:21 -06:00
this . seoService . logSoft404 ( ) ;
2020-07-16 16:18:35 +07:00
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
2023-07-08 01:07:06 -04:00
this . latestBlock $ = this . stateService . blocks $ . pipe ( map ( ( blocks ) = > blocks [ 0 ] ) ) ;
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
}
}