diff --git a/src/SnapKeyring.ts b/src/SnapKeyring.ts index f93fa79f..0e0347d5 100644 --- a/src/SnapKeyring.ts +++ b/src/SnapKeyring.ts @@ -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'; @@ -502,7 +503,7 @@ export class SnapKeyring extends EventEmitter { chainId: string; }): Promise { try { - return await this.#snapClient.withSnapId(snapId).submitRequest({ + const request = { id: requestId, scope: chainId, account: account.id, @@ -510,8 +511,14 @@ export class SnapKeyring extends EventEmitter { 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; diff --git a/src/logger.ts b/src/logger.ts new file mode 100644 index 00000000..9293c62e --- /dev/null +++ b/src/logger.ts @@ -0,0 +1,7 @@ +/* istanbul ignore file */ + +import { createProjectLogger, createModuleLogger } from '@metamask/utils'; + +export const projectLogger = createProjectLogger('eth-snap-keyring'); + +export { createModuleLogger };