Merge pull request #2521 from mononaut/fix-liquid-cb-previews

Fix preview tx diagram for zero value transactions
This commit is contained in:
wiz 2022-09-09 18:13:59 +02:00 committed by GitHub
commit d6d0c42691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,18 +87,21 @@ export class TxBowtieGraphComponent implements OnInit, OnChanges {
// assume confidential inputs/outputs have the same average value as the known ones // assume confidential inputs/outputs have the same average value as the known ones
const adjustedTotalInput = totalInput + ((totalInput / knownInputCount) * confidentialInputCount); const adjustedTotalInput = totalInput + ((totalInput / knownInputCount) * confidentialInputCount);
const adjustedTotalOutput = totalOutput + ((totalOutput / knownOutputCount) * confidentialOutputCount); const adjustedTotalOutput = totalOutput + ((totalOutput / knownOutputCount) * confidentialOutputCount);
return Math.max(adjustedTotalInput, adjustedTotalOutput) || 1; return Math.max(adjustedTotalInput, adjustedTotalOutput);
} else { } else {
// otherwise knowing the actual total of one side suffices // otherwise knowing the actual total of one side suffices
return Math.max(totalInput, totalOutput) || 1; return Math.max(totalInput, totalOutput);
} }
} }
} }
initLines(side: 'in' | 'out', xputs: { type: string, value: number | void }[], total: number, maxVisibleStrands: number): SvgLine[] { initLines(side: 'in' | 'out', xputs: { type: string, value: number | void }[], total: number, maxVisibleStrands: number): SvgLine[] {
const lines = []; if (!total) {
const weights = xputs.map((put): number => this.combinedWeight / xputs.length);
return this.linesFromWeights(side, xputs, weights, maxVisibleStrands);
} else {
let unknownCount = 0; let unknownCount = 0;
let unknownTotal = total == null ? this.combinedWeight : total; let unknownTotal = total;
xputs.forEach(put => { xputs.forEach(put => {
if (put.value == null) { if (put.value == null) {
unknownCount++; unknownCount++;
@ -107,9 +110,14 @@ export class TxBowtieGraphComponent implements OnInit, OnChanges {
} }
}); });
const unknownShare = unknownTotal / unknownCount; const unknownShare = unknownTotal / unknownCount;
// conceptual weights // conceptual weights
const weights = xputs.map((put): number => this.combinedWeight * (put.value == null ? unknownShare : put.value as number) / total); const weights = xputs.map((put): number => this.combinedWeight * (put.value == null ? unknownShare : put.value as number) / total);
return this.linesFromWeights(side, xputs, weights, maxVisibleStrands);
}
}
linesFromWeights(side: 'in' | 'out', xputs: { type: string, value: number | void }[], weights: number[], maxVisibleStrands: number) {
const lines = [];
// actual displayed line thicknesses // actual displayed line thicknesses
const minWeights = weights.map((w) => Math.max(this.minWeight - 1, w) + 1); const minWeights = weights.map((w) => Math.max(this.minWeight - 1, w) + 1);
const visibleStrands = Math.min(maxVisibleStrands, xputs.length); const visibleStrands = Math.min(maxVisibleStrands, xputs.length);