Merge pull request #5311 from mempool/natsoni/accel-tx-fee-update

Update tx acceleration state on confirmation
This commit is contained in:
wiz 2024-07-11 14:50:06 +09:00 committed by GitHub
commit 1a5613bf65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 6 deletions

View File

@ -639,7 +639,7 @@
} }
<td> <td>
<div class="effective-fee-container"> <div class="effective-fee-container">
@if (accelerationInfo?.acceleratedFeeRate && (!tx.effectiveFeePerVsize || accelerationInfo.acceleratedFeeRate >= tx.effectiveFeePerVsize)) { @if (accelerationInfo?.acceleratedFeeRate && (!tx.effectiveFeePerVsize || accelerationInfo.acceleratedFeeRate >= tx.effectiveFeePerVsize || tx.acceleration)) {
<app-fee-rate [fee]="accelerationInfo.acceleratedFeeRate"></app-fee-rate> <app-fee-rate [fee]="accelerationInfo.acceleratedFeeRate"></app-fee-rate>
} @else { } @else {
<app-fee-rate [fee]="tx.effectiveFeePerVsize"></app-fee-rate> <app-fee-rate [fee]="tx.effectiveFeePerVsize"></app-fee-rate>

View File

@ -132,6 +132,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
tooltipPosition: { x: number, y: number }; tooltipPosition: { x: number, y: number };
isMobile: boolean; isMobile: boolean;
firstLoad = true; firstLoad = true;
waitingForAccelerationInfo: boolean = false;
featuresEnabled: boolean; featuresEnabled: boolean;
segwitEnabled: boolean; segwitEnabled: boolean;
@ -317,11 +318,19 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
this.setIsAccelerated(); this.setIsAccelerated();
}), }),
switchMap((blockHeight: number) => { switchMap((blockHeight: number) => {
return this.servicesApiService.getAccelerationHistory$({ blockHeight }); return this.servicesApiService.getAccelerationHistory$({ blockHeight }).pipe(
switchMap((accelerationHistory: Acceleration[]) => {
if (this.tx.acceleration && !accelerationHistory.length) { // If the just mined transaction was accelerated, but services backend did not return any acceleration data, retry
return throwError('retry');
}
return of(accelerationHistory);
}), }),
retry({ count: 3, delay: 2000 }),
catchError(() => { catchError(() => {
return of([]); return of([]);
}) })
);
}),
).subscribe((accelerationHistory) => { ).subscribe((accelerationHistory) => {
for (const acceleration of accelerationHistory) { for (const acceleration of accelerationHistory) {
if (acceleration.txid === this.txId && (acceleration.status === 'completed' || acceleration.status === 'completed_provisional')) { if (acceleration.txid === this.txId && (acceleration.status === 'completed' || acceleration.status === 'completed_provisional')) {
@ -330,6 +339,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
acceleration.boost = boostCost; acceleration.boost = boostCost;
this.tx.acceleratedAt = acceleration.added; this.tx.acceleratedAt = acceleration.added;
this.accelerationInfo = acceleration; this.accelerationInfo = acceleration;
this.waitingForAccelerationInfo = false;
this.setIsAccelerated(); this.setIsAccelerated();
} }
} }
@ -608,6 +618,9 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
this.stateService.txConfirmed$.subscribe(([txConfirmed, block]) => { this.stateService.txConfirmed$.subscribe(([txConfirmed, block]) => {
if (txConfirmed && this.tx && !this.tx.status.confirmed && txConfirmed === this.tx.txid) { if (txConfirmed && this.tx && !this.tx.status.confirmed && txConfirmed === this.tx.txid) {
if (this.tx.acceleration) {
this.waitingForAccelerationInfo = true;
}
this.tx.status = { this.tx.status = {
confirmed: true, confirmed: true,
block_height: block.height, block_height: block.height,
@ -803,7 +816,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
} }
setIsAccelerated(initialState: boolean = false) { setIsAccelerated(initialState: boolean = false) {
this.isAcceleration = (this.tx.acceleration || (this.accelerationInfo && this.pool && this.accelerationInfo.pools.some(pool => (pool === this.pool.id)))); this.isAcceleration = ((this.tx.acceleration && (!this.tx.status.confirmed || this.waitingForAccelerationInfo)) || (this.accelerationInfo && this.pool && this.accelerationInfo.pools.some(pool => (pool === this.pool.id))));
if (this.isAcceleration) { if (this.isAcceleration) {
if (initialState) { if (initialState) {
this.accelerationFlowCompleted = true; this.accelerationFlowCompleted = true;