Don't round variables in code, only in templates.

This commit is contained in:
softsimon 2021-04-10 23:23:05 +04:00
parent 2d9b9b5c5d
commit f1c5f83412
No known key found for this signature in database
GPG key ID: 488D7DCFB5A430D7
2 changed files with 7 additions and 9 deletions

View file

@ -176,8 +176,8 @@
</a>
</td>
<td class="d-none d-lg-table-cell">{{ cpfpTx.weight / 4 | vbytes: 2 }}</td>
<td>{{ roundToOneDecimal(cpfpTx) | number : '1.1-1' }} <span i18n="shared.sat-vbyte|sat/vB">sat/vB</span></td>
<td class="d-none d-lg-table-cell"><fa-icon *ngIf="roundToOneDecimal(cpfpTx) < tx.feePerVsize" class="arrow-red" [icon]="['fas', 'angle-double-down']" [fixedWidth]="true"></fa-icon></td>
<td>{{ cpfpTx.fee / (cpfpTx.weight / 4) | number : '1.1-1' }} <span i18n="shared.sat-vbyte|sat/vB">sat/vB</span></td>
<td class="d-none d-lg-table-cell"><fa-icon *ngIf="roundToOneDecimal(cpfpTx) < roundToOneDecimal(tx)" class="arrow-red" [icon]="['fas', 'angle-double-down']" [fixedWidth]="true"></fa-icon></td>
</tr>
</ng-template>
</tbody>

View file

@ -80,7 +80,7 @@ export class TransactionComponent implements OnInit, OnDestroy {
if (tx.fee === undefined) {
this.tx.fee = 0;
}
this.tx.feePerVsize = +(tx.fee / (tx.weight / 4)).toFixed(1);
this.tx.feePerVsize = tx.fee / (tx.weight / 4);
this.isLoadingTx = false;
this.error = undefined;
this.waitingForTransaction = false;
@ -105,11 +105,10 @@ export class TransactionComponent implements OnInit, OnDestroy {
ancestors: tx.ancestors,
bestDescendant: tx.bestDescendant,
};
tx.effectiveFeePerVsize = +(tx.effectiveFeePerVsize).toFixed(1);
} else {
this.apiService.getCpfpinfo$(this.tx.txid)
this.apiService.getCpfpinfo$(this.tx.txid)
.subscribe((cpfpInfo) => {
const lowerFeeParents = cpfpInfo.ancestors.filter((ancestor) => (ancestor.fee / (ancestor.weight / 4)) < tx.feePerVsize);
const lowerFeeParents = cpfpInfo.ancestors.filter((parent) => (parent.fee / (parent.weight / 4)) < tx.effectiveFeePerVsize);
let totalWeight = tx.weight + lowerFeeParents.reduce((prev, val) => prev + val.weight, 0);
let totalFees = tx.fee + lowerFeeParents.reduce((prev, val) => prev + val.fee, 0);
@ -118,9 +117,8 @@ export class TransactionComponent implements OnInit, OnDestroy {
totalFees += cpfpInfo.bestDescendant.fee;
}
const effectiveFeePerVsize = totalFees / (totalWeight / 4);
this.tx.effectiveFeePerVsize = +effectiveFeePerVsize.toFixed(1);
this.stateService.markBlock$.next({ txFeePerVSize: effectiveFeePerVsize });
this.tx.effectiveFeePerVsize = totalFees / (totalWeight / 4);
this.stateService.markBlock$.next({ txFeePerVSize: this.tx.effectiveFeePerVsize });
this.cpfpInfo = cpfpInfo;
});
}