[accelerator] rerefactor bitcoin-payment component

This commit is contained in:
Mononaut
2024-06-30 08:39:32 +00:00
parent f114a8ca75
commit 35d0e7fae7
3 changed files with 16 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
import { Component, OnInit, OnDestroy, Output, EventEmitter, Input, ChangeDetectorRef, SimpleChanges, HostListener } from '@angular/core';
import { Subscription, tap, of, catchError, Observable } from 'rxjs';
import { Subscription, tap, of, catchError, Observable, switchMap } from 'rxjs';
import { ServicesApiServices } from '../../services/services-api.service';
import { nextRoundNumber } from '../../shared/common.utils';
import { StateService } from '../../services/state.service';
@@ -443,15 +443,20 @@ export class AccelerateCheckout implements OnInit, OnDestroy {
* BTCPay
*/
async requestBTCPayInvoice() {
this.servicesApiService.generateBTCPayAcceleratorInvoice$(this.tx.txid, this.userBid).subscribe({
next: (response) => {
this.invoice = response;
this.servicesApiService.generateBTCPayAcceleratorInvoice$(this.tx.txid, this.userBid).pipe(
switchMap(response => {
return this.servicesApiService.retreiveInvoice$(response.btcpayInvoiceId);
}),
catchError(error => {
console.log(error);
return of(null);
})
).subscribe((invoice) => {
this.invoice = invoice;
this.cd.markForCheck();
this.scrollToElementWithTimeout('acceleratePreviewAnchor', 'start', 500);
},
error: (response) => {
console.log(response);
}
if (invoice) {
this.scrollToElementWithTimeout('acceleratePreviewAnchor', 'start', 500);
}
});
}