feat(gui): Display logs of specific swap on press of button on history page

This commit is contained in:
binarybaron 2024-09-09 21:00:27 +02:00
parent 063f9dbf9b
commit c486ca5de9
No known key found for this signature in database
GPG key ID: 99B75D3E1476A26E
5 changed files with 66 additions and 13 deletions

View file

@ -18,3 +18,26 @@ export interface CliLog {
[index: string]: unknown;
}[];
}
function isCliLog(log: unknown): log is CliLog {
return (
typeof log === "object" &&
log !== null &&
"timestamp" in log &&
"level" in log &&
"fields" in log
);
}
export function parseCliLogString(log: string): CliLog | string {
try {
const parsed = JSON.parse(log);
if (isCliLog(parsed)) {
return parsed;
} else {
return log;
}
} catch (err) {
return log;
}
}