Adding fee rating to confirmed transactions.
This commit is contained in:
parent
dbf8d025e9
commit
abf74c1aaf
@ -45,12 +45,18 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<ng-template [ngIf]="tx.fee">
|
<ng-template [ngIf]="tx.fee">
|
||||||
<tr>
|
<tr>
|
||||||
<td>Fee</td>
|
<td>Fee per vByte</td>
|
||||||
<td>{{ tx.fee | number }} sats (<app-fiat [value]="tx.fee"></app-fiat>)</td>
|
<td>
|
||||||
|
{{ tx.fee / (tx.weight / 4) | number : '1.2-2' }} sats/vB
|
||||||
|
|
||||||
|
<span *ngIf="feeRating === 1" class="badge badge-success">Optimal</span>
|
||||||
|
<span *ngIf="feeRating === 2" class="badge badge-warning">Overpaid {{ overpaidTimes }}x</span>
|
||||||
|
<span *ngIf="feeRating === 3" class="badge badge-danger">Overpaid {{ overpaidTimes }}x</span>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Fee per vByte</td>
|
<td>Fee</td>
|
||||||
<td>{{ tx.fee / (tx.weight / 4) | number : '1.2-2' }} sats/vB</td>
|
<td>{{ tx.fee | number }} sats (<app-fiat [value]="tx.fee"></app-fiat>)</td>
|
||||||
</tr>
|
</tr>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { ElectrsApiService } from '../../services/electrs-api.service';
|
import { ElectrsApiService } from '../../services/electrs-api.service';
|
||||||
import { ActivatedRoute, ParamMap } from '@angular/router';
|
import { ActivatedRoute, ParamMap } from '@angular/router';
|
||||||
import { switchMap } from 'rxjs/operators';
|
import { switchMap, filter } from 'rxjs/operators';
|
||||||
import { Transaction, Block } from '../../interfaces/electrs.interface';
|
import { Transaction, Block } from '../../interfaces/electrs.interface';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { StateService } from '../../services/state.service';
|
import { StateService } from '../../services/state.service';
|
||||||
@ -17,6 +17,8 @@ import { ApiService } from 'src/app/services/api.service';
|
|||||||
export class TransactionComponent implements OnInit, OnDestroy {
|
export class TransactionComponent implements OnInit, OnDestroy {
|
||||||
tx: Transaction;
|
tx: Transaction;
|
||||||
txId: string;
|
txId: string;
|
||||||
|
feeRating: number;
|
||||||
|
overpaidTimes: number;
|
||||||
isLoadingTx = true;
|
isLoadingTx = true;
|
||||||
error: any = undefined;
|
error: any = undefined;
|
||||||
latestBlock: Block;
|
latestBlock: Block;
|
||||||
@ -41,6 +43,7 @@ export class TransactionComponent implements OnInit, OnDestroy {
|
|||||||
switchMap((params: ParamMap) => {
|
switchMap((params: ParamMap) => {
|
||||||
this.txId = params.get('id') || '';
|
this.txId = params.get('id') || '';
|
||||||
this.error = undefined;
|
this.error = undefined;
|
||||||
|
this.feeRating = undefined;
|
||||||
this.isLoadingTx = true;
|
this.isLoadingTx = true;
|
||||||
this.transactionTime = -1;
|
this.transactionTime = -1;
|
||||||
document.body.scrollTo(0, 0);
|
document.body.scrollTo(0, 0);
|
||||||
@ -58,6 +61,8 @@ export class TransactionComponent implements OnInit, OnDestroy {
|
|||||||
if (!tx.status.confirmed) {
|
if (!tx.status.confirmed) {
|
||||||
this.websocketService.startTrackTransaction(tx.txid);
|
this.websocketService.startTrackTransaction(tx.txid);
|
||||||
this.getTransactionTime();
|
this.getTransactionTime();
|
||||||
|
} else {
|
||||||
|
this.findBlockAndSetFeeRating();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
@ -77,6 +82,7 @@ export class TransactionComponent implements OnInit, OnDestroy {
|
|||||||
block_time: block.timestamp,
|
block_time: block.timestamp,
|
||||||
};
|
};
|
||||||
this.audioService.playSound('magic');
|
this.audioService.playSound('magic');
|
||||||
|
this.findBlockAndSetFeeRating();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +93,24 @@ export class TransactionComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findBlockAndSetFeeRating() {
|
||||||
|
this.stateService.blocks$
|
||||||
|
.pipe(filter((block) => block.height === this.tx.status.block_height))
|
||||||
|
.subscribe((block) => {
|
||||||
|
const feePervByte = this.tx.fee / (this.tx.weight / 4);
|
||||||
|
|
||||||
|
if (feePervByte <= block.feeRange[Math.round(block.feeRange.length * 0.5)]) {
|
||||||
|
this.feeRating = 1;
|
||||||
|
} else {
|
||||||
|
this.feeRating = 2;
|
||||||
|
this.overpaidTimes = Math.round(feePervByte / block.medianFee);
|
||||||
|
if (this.overpaidTimes > 10) {
|
||||||
|
this.feeRating = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.websocketService.startTrackTransaction('stop');
|
this.websocketService.startTrackTransaction('stop');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user