Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
feat: add logger + now log Snap requests (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccharly authored Mar 14, 2024
1 parent bb0cde2 commit c9faeb1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/SnapKeyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { v4 as uuid } from 'uuid';
import { toCaipChainId, CaipNamespaces } from './caip';
import { DeferredPromise } from './DeferredPromise';
import { KeyringSnapControllerClient } from './KeyringSnapControllerClient';
import { projectLogger as log } from './logger';
import { SnapIdMap } from './SnapIdMap';
import type { SnapMessage } from './types';
import { SnapMessageStruct } from './types';
Expand Down Expand Up @@ -502,16 +503,22 @@ export class SnapKeyring extends EventEmitter {
chainId: string;
}): Promise<KeyringResponse> {
try {
return await this.#snapClient.withSnapId(snapId).submitRequest({
const request = {
id: requestId,
scope: chainId,
account: account.id,
request: {
method,
...(params !== undefined && { params }),
},
});
};

log('Submit Snap request: ', request);

return await this.#snapClient.withSnapId(snapId).submitRequest(request);
} catch (error) {
log('Snap Request failed: ', { requestId });

// If the Snap failed to respond, delete the promise to prevent a leak.
this.#requests.delete(snapId, requestId);
throw error;
Expand Down
7 changes: 7 additions & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* istanbul ignore file */

import { createProjectLogger, createModuleLogger } from '@metamask/utils';

export const projectLogger = createProjectLogger('eth-snap-keyring');

export { createModuleLogger };

0 comments on commit c9faeb1

Please sign in to comment.