Fix transaction component ETA

This commit is contained in:
Mononaut 2023-06-29 11:22:33 -04:00
parent 5f787db30d
commit d9ed02a033
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E
3 changed files with 15 additions and 11 deletions

View File

@ -143,6 +143,8 @@ export class MempoolBlocksComponent implements OnInit, OnChanges, OnDestroy {
this.mempoolBlocksFull = JSON.parse(stringifiedBlocks); this.mempoolBlocksFull = JSON.parse(stringifiedBlocks);
this.mempoolBlocks = this.reduceMempoolBlocksToFitScreen(JSON.parse(stringifiedBlocks)); this.mempoolBlocks = this.reduceMempoolBlocksToFitScreen(JSON.parse(stringifiedBlocks));
this.now = Date.now();
this.updateMempoolBlockStyles(); this.updateMempoolBlockStyles();
this.calculateTransactionPosition(); this.calculateTransactionPosition();
return this.mempoolBlocks; return this.mempoolBlocks;
@ -152,7 +154,8 @@ export class MempoolBlocksComponent implements OnInit, OnChanges, OnDestroy {
this.difficultyAdjustments$ = this.stateService.difficultyAdjustment$ this.difficultyAdjustments$ = this.stateService.difficultyAdjustment$
.pipe( .pipe(
map((da) => { map((da) => {
this.now = new Date().getTime(); this.now = Date.now();
this.cd.markForCheck();
return da; return da;
}) })
); );

View File

@ -105,7 +105,7 @@
<app-time kind="until" [time]="(60 * 1000 * this.mempoolPosition.block) + now" [fastRender]="false" [fixedRender]="true"></app-time> <app-time kind="until" [time]="(60 * 1000 * this.mempoolPosition.block) + now" [fastRender]="false" [fixedRender]="true"></app-time>
</ng-template> </ng-template>
<ng-template #timeEstimateDefault> <ng-template #timeEstimateDefault>
<app-time kind="until" *ngIf="(timeAvg$ | async) as timeAvg;" [time]="(timeAvg * this.mempoolPosition.block) + now + timeAvg" [fastRender]="false" [fixedRender]="true"></app-time> <app-time kind="until" *ngIf="(da$ | async) as da;" [time]="da.timeAvg * (this.mempoolPosition.block + 1) + now + da.timeOffset" [fastRender]="false" [fixedRender]="true"></app-time>
</ng-template> </ng-template>
</ng-template> </ng-template>
</ng-template> </ng-template>

View File

@ -19,7 +19,7 @@ import { WebsocketService } from '../../services/websocket.service';
import { AudioService } from '../../services/audio.service'; import { AudioService } from '../../services/audio.service';
import { ApiService } from '../../services/api.service'; import { ApiService } from '../../services/api.service';
import { SeoService } from '../../services/seo.service'; import { SeoService } from '../../services/seo.service';
import { BlockExtended, CpfpInfo, RbfTree, MempoolPosition } from '../../interfaces/node-api.interface'; import { BlockExtended, CpfpInfo, RbfTree, MempoolPosition, DifficultyAdjustment } from '../../interfaces/node-api.interface';
import { LiquidUnblinding } from './liquid-ublinding'; import { LiquidUnblinding } from './liquid-ublinding';
import { RelativeUrlPipe } from '../../shared/pipes/relative-url/relative-url.pipe'; import { RelativeUrlPipe } from '../../shared/pipes/relative-url/relative-url.pipe';
import { Price, PriceService } from '../../services/price.service'; import { Price, PriceService } from '../../services/price.service';
@ -65,7 +65,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
fetchCachedTx$ = new Subject<string>(); fetchCachedTx$ = new Subject<string>();
isCached: boolean = false; isCached: boolean = false;
now = Date.now(); now = Date.now();
timeAvg$: Observable<number>; da$: Observable<DifficultyAdjustment>;
liquidUnblinding = new LiquidUnblinding(); liquidUnblinding = new LiquidUnblinding();
inputIndex: number; inputIndex: number;
outputIndex: number; outputIndex: number;
@ -117,11 +117,11 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
this.setFlowEnabled(); this.setFlowEnabled();
}); });
this.timeAvg$ = timer(0, 1000) this.da$ = this.stateService.difficultyAdjustment$.pipe(
.pipe( tap(() => {
switchMap(() => this.stateService.difficultyAdjustment$), this.now = Date.now();
map((da) => da.timeAvg) })
); );
this.urlFragmentSubscription = this.route.fragment.subscribe((fragment) => { this.urlFragmentSubscription = this.route.fragment.subscribe((fragment) => {
this.fragmentParams = new URLSearchParams(fragment || ''); this.fragmentParams = new URLSearchParams(fragment || '');
@ -236,6 +236,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
}); });
this.mempoolPositionSubscription = this.stateService.mempoolTxPosition$.subscribe(txPosition => { this.mempoolPositionSubscription = this.stateService.mempoolTxPosition$.subscribe(txPosition => {
this.now = Date.now();
if (txPosition && txPosition.txid === this.txId && txPosition.position) { if (txPosition && txPosition.txid === this.txId && txPosition.position) {
this.mempoolPosition = txPosition.position; this.mempoolPosition = txPosition.position;
if (this.tx && !this.tx.status.confirmed) { if (this.tx && !this.tx.status.confirmed) {
@ -434,12 +435,12 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
}); });
this.mempoolBlocksSubscription = this.stateService.mempoolBlocks$.subscribe((mempoolBlocks) => { this.mempoolBlocksSubscription = this.stateService.mempoolBlocks$.subscribe((mempoolBlocks) => {
this.now = Date.now();
if (!this.tx || this.mempoolPosition) { if (!this.tx || this.mempoolPosition) {
return; return;
} }
this.now = Date.now();
const txFeePerVSize = const txFeePerVSize =
this.tx.effectiveFeePerVsize || this.tx.fee / (this.tx.weight / 4); this.tx.effectiveFeePerVsize || this.tx.fee / (this.tx.weight / 4);