Merge pull request #4943 from mempool/nymkappa/fix-missing-qr-code

[accelerator] fix missing qr code
This commit is contained in:
softsimon 2024-04-10 19:15:04 +09:00 committed by GitHub
commit affeb0a169
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 12 deletions

View File

@ -14,6 +14,7 @@
</div> </div>
</div> </div>
@if (!processingPayment) {
<div class="accelerate-cols"> <div class="accelerate-cols">
<ng-container *ngIf="!isMobile"> <ng-container *ngIf="!isMobile">
<app-accelerate-fee-graph <app-accelerate-fee-graph
@ -26,7 +27,7 @@
</ng-container> </ng-container>
<ng-container *ngIf="estimate else loadingEstimate"> <ng-container *ngIf="estimate else loadingEstimate">
<div [class]="{estimateDisabled: error || processing || showSuccess }"> <div [class]="{estimateDisabled: error}">
<div *ngIf="user && !estimate.hasAccess"> <div *ngIf="user && !estimate.hasAccess">
<div class="alert alert-mempool">You are currently on the waitlist</div> <div class="alert alert-mempool">You are currently on the waitlist</div>
@ -286,7 +287,7 @@
</div> </div>
</div> </div>
@if (!hideCashApp && !(error || processing || showSuccess) && paymentType === 'cashapp') { @if (!hideCashApp && paymentType === 'cashapp') {
<div #cashappCTA class="cashapp-placeholder {{ stickyCTA }}"></div> <div #cashappCTA class="cashapp-placeholder {{ stickyCTA }}"></div>
<div class="d-flex justify-content-center align-items-center cashapp-cta {{ stickyCTA }}" (click)="submitCashappPay()"> <div class="d-flex justify-content-center align-items-center cashapp-cta {{ stickyCTA }}" (click)="submitCashappPay()">
<div [style]="showSpinner ? 'opacity: 0' : 'opacity: 1'" class="p-2">Accelerate for <app-fiat [value]="maxCost" [colorClass]="estimate.userBalance < maxCost ? 'red-color' : 'green-color'"></app-fiat> with</div> <div [style]="showSpinner ? 'opacity: 0' : 'opacity: 1'" class="p-2">Accelerate for <app-fiat [value]="maxCost" [colorClass]="estimate.userBalance < maxCost ? 'red-color' : 'green-color'"></app-fiat> with</div>
@ -306,5 +307,9 @@
<div class="skeleton-loader"></div> <div class="skeleton-loader"></div>
<br> <br>
</ng-template> </ng-template>
}
@else if (!showSuccess && !error) {
<div class="alert alert-info">Processing payment...</div>
}
<ng-template #acceleratedTo let-i i18n="accelerator.accelerated-to-description">If your tx is accelerated to ~{{ i | number : '1.0-0' }} sat/vB</ng-template> <ng-template #acceleratedTo let-i i18n="accelerator.accelerated-to-description">If your tx is accelerated to ~{{ i | number : '1.0-0' }} sat/vB</ng-template>

View File

@ -48,7 +48,6 @@ export class AcceleratePreviewComponent implements OnInit, OnDestroy, OnChanges
math = Math; math = Math;
error = ''; error = '';
processing = false;
showSuccess = false; showSuccess = false;
estimateSubscription: Subscription; estimateSubscription: Subscription;
accelerationSubscription: Subscription; accelerationSubscription: Subscription;
@ -78,6 +77,7 @@ export class AcceleratePreviewComponent implements OnInit, OnDestroy, OnChanges
square: any; square: any;
cashAppPay: any; cashAppPay: any;
hideCashApp = false; hideCashApp = false;
processingPayment = false;
constructor( constructor(
public stateService: StateService, public stateService: StateService,
@ -86,6 +86,12 @@ export class AcceleratePreviewComponent implements OnInit, OnDestroy, OnChanges
private audioService: AudioService, private audioService: AudioService,
private cd: ChangeDetectorRef private cd: ChangeDetectorRef
) { ) {
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('cash_request_id')) {
this.processingPayment = true;
this.scrollToPreviewWithTimeout('successAlert', 'center');
}
if (this.stateService.ref === 'https://cash.app/') { if (this.stateService.ref === 'https://cash.app/') {
this.paymentType = 'cashapp'; this.paymentType = 'cashapp';
this.insertSquare(); this.insertSquare();
@ -246,21 +252,18 @@ export class AcceleratePreviewComponent implements OnInit, OnDestroy, OnChanges
if (this.accelerationSubscription) { if (this.accelerationSubscription) {
this.accelerationSubscription.unsubscribe(); this.accelerationSubscription.unsubscribe();
} }
this.processing = true;
this.accelerationSubscription = this.servicesApiService.accelerate$( this.accelerationSubscription = this.servicesApiService.accelerate$(
this.tx.txid, this.tx.txid,
this.userBid, this.userBid,
this.accelerationUUID this.accelerationUUID
).subscribe({ ).subscribe({
next: () => { next: () => {
this.processing = false;
this.audioService.playSound('ascend-chime-cartoon'); this.audioService.playSound('ascend-chime-cartoon');
this.showSuccess = true; this.showSuccess = true;
this.scrollToPreviewWithTimeout('successAlert', 'center'); this.scrollToPreviewWithTimeout('successAlert', 'center');
this.estimateSubscription.unsubscribe(); this.estimateSubscription.unsubscribe();
}, },
error: (response) => { error: (response) => {
this.processing = false;
if (response.status === 403 && response.error === 'not_available') { if (response.status === 403 && response.error === 'not_available') {
this.error = 'waitlisted'; this.error = 'waitlisted';
} else { } else {
@ -326,6 +329,7 @@ export class AcceleratePreviewComponent implements OnInit, OnDestroy, OnChanges
this.cashAppPay.destroy(); this.cashAppPay.destroy();
} }
const redirectHostname = document.location.hostname === 'localhost' ? 'http://localhost:4200': 'https://mempool.space';
const maxCostUsd = this.maxCost / 100_000_000 * conversions.USD; const maxCostUsd = this.maxCost / 100_000_000 * conversions.USD;
const paymentRequest = this.payments.paymentRequest({ const paymentRequest = this.payments.paymentRequest({
countryCode: 'US', countryCode: 'US',
@ -334,12 +338,12 @@ export class AcceleratePreviewComponent implements OnInit, OnDestroy, OnChanges
amount: maxCostUsd.toString(), amount: maxCostUsd.toString(),
label: 'Total', label: 'Total',
pending: true, pending: true,
productUrl: `https://mempool.space/tx/${this.tx.txid}`, productUrl: `${redirectHostname}/tx/${this.tx.txid}`,
}, },
button: { shape: 'semiround', size: 'small', theme: 'light'} button: { shape: 'semiround', size: 'small', theme: 'light'}
}); });
this.cashAppPay = await this.payments.cashAppPay(paymentRequest, { this.cashAppPay = await this.payments.cashAppPay(paymentRequest, {
redirectURL: `https://mempool.space/tx/${this.tx.txid}`, redirectURL: `${redirectHostname}/tx/${this.tx.txid}?acceleration=false`,
referenceId: `accelerator-${this.tx.txid.substring(0, 15)}-${Math.round(new Date().getTime() / 1000)}`, referenceId: `accelerator-${this.tx.txid.substring(0, 15)}-${Math.round(new Date().getTime() / 1000)}`,
button: { shape: 'semiround', size: 'small', theme: 'light'} button: { shape: 'semiround', size: 'small', theme: 'light'}
}); });
@ -348,6 +352,8 @@ export class AcceleratePreviewComponent implements OnInit, OnDestroy, OnChanges
const that = this; const that = this;
this.cashAppPay.addEventListener('ontokenization', function (event) { this.cashAppPay.addEventListener('ontokenization', function (event) {
that.processingPayment = true;
that.scrollToPreviewWithTimeout('successAlert', 'center');
const { tokenResult, error } = event.detail; const { tokenResult, error } = event.detail;
if (error) { if (error) {
this.error = error; this.error = error;
@ -363,14 +369,11 @@ export class AcceleratePreviewComponent implements OnInit, OnDestroy, OnChanges
that.accelerationUUID that.accelerationUUID
).subscribe({ ).subscribe({
next: () => { next: () => {
this.processing = false;
that.audioService.playSound('ascend-chime-cartoon'); that.audioService.playSound('ascend-chime-cartoon');
that.showSuccess = true; that.showSuccess = true;
that.scrollToPreviewWithTimeout('successAlert', 'center');
that.estimateSubscription.unsubscribe(); that.estimateSubscription.unsubscribe();
}, },
error: (response) => { error: (response) => {
this.processing = false;
if (response.status === 403 && response.error === 'not_available') { if (response.status === 403 && response.error === 'not_available') {
that.error = 'waitlisted'; that.error = 'waitlisted';
} else { } else {
@ -407,7 +410,6 @@ export class AcceleratePreviewComponent implements OnInit, OnDestroy, OnChanges
submitCashappPay(): void { submitCashappPay(): void {
if (this.cashappSubmit) { if (this.cashappSubmit) {
this.cashappSubmit?.begin(); this.cashappSubmit?.begin();
this.processing = true;
} }
} }