Skip to content

Commit 9152a5e

Browse files
committed
fixes
1 parent cd34527 commit 9152a5e

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/app/interfaces/websocket-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface NotificationData {
88
credentialPreview?: {
99
subjectName?: string;
1010
organization?: string;
11-
power?: string;
11+
power?: Array<any>;
1212
expirationDate?: string;
1313
};
1414
timeout?: number;

src/app/services/websocket.service.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,27 +292,47 @@ export class WebsocketService {
292292
public mapPowersToHumanReadable(powers: Array<any>): string {
293293
if (!Array.isArray(powers) || powers.length === 0) return '';
294294

295+
const unknown = this.translate.instant('common.unknown') || 'Desconocido';
296+
295297
const lines = powers
296298
.map((p) => {
297299
const fnKey = this.normalizeKey(p?.function);
298300
const actionKeys = this.normalizeActionKeys(p?.action);
299301

300-
const functionLabel =
301-
this.translate.instant(`vc-fields.power.${fnKey}`) || p?.function || '';
302+
const functionLabelRaw =
303+
this.getSafeTranslation(`vc-fields.power.${fnKey}`, p?.function, unknown);
304+
305+
const actionLabelsRaw = actionKeys
306+
.map((a) => this.getSafeTranslation(`vc-fields.power.${a}`, a, unknown))
307+
.filter((x) => x && x !== unknown);
302308

303-
const actionLabels = actionKeys
304-
.map((a) => this.translate.instant(`vc-fields.power.${a}`) || a)
305-
.join(', ');
309+
const functionLabel = this.escapeHtml(functionLabelRaw);
310+
const actionLabels = this.escapeHtml(actionLabelsRaw.join(', '));
306311

307-
const line = `${functionLabel}: ${actionLabels}`;
312+
if (!functionLabel || !actionLabels) return '';
308313

309-
return line.trim();
314+
return `${functionLabel}: ${actionLabels}`;
310315
})
311316
.filter(Boolean);
312317

313318
return lines.join('<br/>');
314319
}
315320

321+
private getSafeTranslation(key: string, fallbackText: unknown, unknown: string): string {
322+
const translated = this.translate.instant(key);
323+
324+
const hasRealTranslation = translated && translated !== key;
325+
326+
if (hasRealTranslation) return String(translated);
327+
328+
const fb = String(fallbackText ?? '').trim();
329+
const looksLikeKey = fb.includes('.') || fb.includes('_') || fb.includes('-');
330+
if (!fb || looksLikeKey) return unknown;
331+
332+
return fb;
333+
}
334+
335+
316336

317337
private normalizeKey(value: unknown): string {
318338
return String(value ?? '')

0 commit comments

Comments
 (0)