Don't render full input witness if user does not press "show all"

This commit is contained in:
natsoni 2024-06-06 17:53:20 +02:00
parent f840ac951b
commit 77d42bfdbb
No known key found for this signature in database
GPG key ID: C65917583181743B
3 changed files with 39 additions and 50 deletions

View file

@ -114,22 +114,33 @@
<td i18n="transactions-list.witness">Witness</td>
<td style="text-align: left;">
<ng-container *ngFor="let witness of vin.witness; index as i">
<input type="checkbox" [id]="'tx' + vindex + 'witness' + i" style="display: none;">
<p class="witness-item" [class.accordioned]="witness.length > 1000">
<ng-template [ngIf]="witness" [ngIfElse]="emptyWitnessItem">
<p class="witness-item">
@if (witness.length > 1000) {
@if (!showFullWitness[vindex][i]) {
{{ witness | slice:0:1000 }}
} @else {
{{ witness }}
}
} @else if (witness) {
{{ witness }}
</ng-template>
<ng-template #emptyWitnessItem>
} @else {
&lt;empty&gt;
</ng-template>
}
</p>
<div class="witness-toggle" *ngIf="witness.length > 1000">
<span class="ellipsis">...</span>
<label [for]="'tx' + vindex + 'witness' + i" class="btn btn-sm btn-primary mt-2">
<span class="show-all" i18n="show-all">Show all</span>
<span class="show-less" i18n="show-less">Show less</span>
</label>
</div>
@if (witness.length > 1000) {
<div style="display: flex;">
@if (!showFullWitness[vindex][i]) {
<span>...</span>
}
<label class="btn btn-sm btn-primary mt-2" (click)="toggleShowFullWitness(vindex, i)" style="margin-left: auto;">
@if (!showFullWitness[vindex][i]) {
<span i18n="show-all">Show all</span>
} @else {
<span i18n="show-less">Show less</span>
}
</label>
</div>
}
</ng-container>
</td>
</tr>

View file

@ -172,42 +172,7 @@ h2 {
}
.vin-witness {
.witness-item.accordioned {
max-height: 300px;
overflow: hidden;
}
input:checked + .witness-item.accordioned {
max-height: none;
}
.witness-toggle {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: space-between;
margin-bottom: 1em;
.show-all {
display: inline;
}
.show-less {
display: none;
}
.ellipsis {
visibility: visible;
}
}
input:checked ~ .witness-toggle {
.show-all {
display: none;
}
.show-less {
display: inline;
}
.ellipsis {
visibility: hidden;
}
.witness-item {
overflow: hidden;
}
}

View file

@ -49,6 +49,7 @@ export class TransactionsListComponent implements OnInit, OnChanges {
inputRowLimit: number = 12;
outputRowLimit: number = 12;
showFullScript: { [vinIndex: number]: boolean } = {};
showFullWitness: { [vinIndex: number]: { [witnessIndex: number]: boolean } } = {};
constructor(
public stateService: StateService,
@ -302,8 +303,16 @@ export class TransactionsListComponent implements OnInit, OnChanges {
if (this.showDetails$.value === true) {
this.showDetails$.next(false);
this.showFullScript = {};
this.showFullWitness = {};
} else {
this.showFullScript = this.transactions[0] ? this.transactions[0].vin.reduce((acc, _, i) => ({...acc, [i]: false}), {}) : {};
this.showFullWitness = this.transactions[0] ? this.transactions[0].vin.reduce((acc, vin, vinIndex) => {
acc[vinIndex] = vin.witness ? vin.witness.reduce((witnessAcc, _, witnessIndex) => {
witnessAcc[witnessIndex] = false;
return witnessAcc;
}, {}) : {};
return acc;
}, {}) : {};
this.showDetails$.next(true);
}
}
@ -359,6 +368,10 @@ export class TransactionsListComponent implements OnInit, OnChanges {
this.showFullScript[vinIndex] = !this.showFullScript[vinIndex];
}
toggleShowFullWitness(vinIndex: number, witnessIndex: number): void {
this.showFullWitness[vinIndex][witnessIndex] = !this.showFullWitness[vinIndex][witnessIndex];
}
ngOnDestroy(): void {
this.outspendsSubscription.unsubscribe();
this.currencyChangeSubscription?.unsubscribe();