Skip to content

Commit 8c22ff5

Browse files
authored
test: stringify objects in service worker console log (#1471)
1 parent ac8887b commit 8c22ff5

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

apps/browser-extension-wallet/src/lib/scripts/background/wallet.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ import axiosFetchAdapter from '@shiroyasha9/axios-fetch-adapter';
3232
import { SharedWalletScriptKind } from '@lace/core';
3333
import { getBaseUrlForChain } from '@utils/chain';
3434
import { cacheNamiMetadataSubscription } from './cache-nami-metadata';
35-
36-
const logger = console;
35+
import { logger } from '@lace/common';
3736

3837
// It is important that this file is not exported from index,
3938
// because creating wallet repository with store creates an actual pouchdb database

packages/common/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"react-tooltip": "4.2.7"
5252
},
5353
"devDependencies": {
54+
"ts-log": "^2.2.7",
5455
"typescript": "^4.9.5"
5556
},
5657
"peerDependencies": {

packages/common/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ export * from '@ui/components/Radio';
3030
export * from '@ui/components/Timeline';
3131

3232
export * from '@analytics/index';
33+
34+
export * from './stringifyLogger';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* eslint-disable no-console */
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
3+
import { Logger } from 'ts-log';
4+
import { toSerializableObject } from '@cardano-sdk/util';
5+
6+
export class StringifyLogger implements Logger {
7+
private convertParams(params: any[]) {
8+
return params.map((param) =>
9+
param && typeof param === 'object' ? JSON.stringify(toSerializableObject(param)) : param
10+
);
11+
}
12+
13+
trace(...params: any[]): void {
14+
console.trace(...this.convertParams(params));
15+
}
16+
17+
debug(...params: any[]): void {
18+
console.debug(...this.convertParams(params));
19+
}
20+
21+
info(...params: any[]): void {
22+
console.log(...this.convertParams(params));
23+
}
24+
25+
warn(...params: any[]): void {
26+
console.warn(...this.convertParams(params));
27+
}
28+
29+
error(...params: any[]): void {
30+
console.error(...this.convertParams(params));
31+
}
32+
33+
fatal(...params: any[]): void {
34+
console.error(...this.convertParams(params));
35+
}
36+
}
37+
38+
export const logger = new StringifyLogger();

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13331,6 +13331,7 @@ __metadata:
1333113331
react-copy-to-clipboard: 5.0.4
1333213332
react-dom: 17.0.2
1333313333
react-tooltip: 4.2.7
13334+
ts-log: ^2.2.7
1333413335
typescript: ^4.9.5
1333513336
peerDependencies:
1333613337
react: 17.0.2
@@ -56718,6 +56719,13 @@ __metadata:
5671856719
languageName: node
5671956720
linkType: hard
5672056721

56722+
"ts-log@npm:^2.2.7":
56723+
version: 2.2.7
56724+
resolution: "ts-log@npm:2.2.7"
56725+
checksum: c423a5eb54abb9471578902953814d3d0c88b3f237db016998f8998ecf982cb0f748bb8ebf93670eeba9b836ff0ce407d8065a340f3ab218ea7b9442c255b3d4
56726+
languageName: node
56727+
linkType: hard
56728+
5672156729
"ts-mixer@npm:^6.0.3":
5672256730
version: 6.0.4
5672356731
resolution: "ts-mixer@npm:6.0.4"

0 commit comments

Comments
 (0)