From 504ce81a363c9f799bc8b325a150ab29cac5cdbf Mon Sep 17 00:00:00 2001 From: Filip Sekulic Date: Thu, 8 Dec 2022 13:36:19 +0100 Subject: [PATCH] Fetch msgId within the check method --- app/scripts/lib/personal-message-manager.js | 55 ++++++++++----------- app/scripts/lib/typed-message-manager.js | 50 +++++++++---------- 2 files changed, 52 insertions(+), 53 deletions(-) diff --git a/app/scripts/lib/personal-message-manager.js b/app/scripts/lib/personal-message-manager.js index 221ca211e6ab..24bd8c7c3e0c 100644 --- a/app/scripts/lib/personal-message-manager.js +++ b/app/scripts/lib/personal-message-manager.js @@ -90,9 +90,7 @@ export default class PersonalMessageManager extends EventEmitter { * @param {object} [req] - The original request object possibly containing the origin * @returns {promise} When the message has been signed or rejected */ - async addUnapprovedMessageAsync(msgParams, req) { - const msgId = await this.addUnapprovedMessage(msgParams, req); - + addUnapprovedMessageAsync(msgParams, req) { return new Promise((resolve, reject) => { if (!msgParams.from) { reject( @@ -100,31 +98,32 @@ export default class PersonalMessageManager extends EventEmitter { ); return; } - - this.once(`${msgId}:finished`, (data) => { - switch (data.status) { - case 'signed': - resolve(data.rawSig); - return; - case 'rejected': - reject( - ethErrors.provider.userRejectedRequest( - 'MetaMask Message Signature: User denied message signature.', - ), - ); - return; - case 'errored': - reject(new Error(`MetaMask Message Signature: ${data.error}`)); - return; - default: - reject( - new Error( - `MetaMask Message Signature: Unknown problem: ${JSON.stringify( - msgParams, - )}`, - ), - ); - } + this.addUnapprovedMessage(msgParams, req).then((msgId) => { + this.once(`${msgId}:finished`, (data) => { + switch (data.status) { + case 'signed': + resolve(data.rawSig); + return; + case 'rejected': + reject( + ethErrors.provider.userRejectedRequest( + 'MetaMask Message Signature: User denied message signature.', + ), + ); + return; + case 'errored': + reject(new Error(`MetaMask Message Signature: ${data.error}`)); + return; + default: + reject( + new Error( + `MetaMask Message Signature: Unknown problem: ${JSON.stringify( + msgParams, + )}`, + ), + ); + } + }); }); }); } diff --git a/app/scripts/lib/typed-message-manager.js b/app/scripts/lib/typed-message-manager.js index bedaefa5b3d7..b9526d0f3386 100644 --- a/app/scripts/lib/typed-message-manager.js +++ b/app/scripts/lib/typed-message-manager.js @@ -92,32 +92,32 @@ export default class TypedMessageManager extends EventEmitter { * @returns {promise} When the message has been signed or rejected */ async addUnapprovedMessageAsync(msgParams, req, version) { - const msgId = await this.addUnapprovedMessage(msgParams, req, version); - return new Promise((resolve, reject) => { - this.once(`${msgId}:finished`, (data) => { - switch (data.status) { - case 'signed': - return resolve(data.rawSig); - case 'rejected': - return reject( - ethErrors.provider.userRejectedRequest( - 'MetaMask Message Signature: User denied message signature.', - ), - ); - case 'errored': - return reject( - new Error(`MetaMask Message Signature: ${data.error}`), - ); - default: - return reject( - new Error( - `MetaMask Message Signature: Unknown problem: ${JSON.stringify( - msgParams, - )}`, - ), - ); - } + this.addUnapprovedMessage(msgParams, req, version).then((msgId) => { + this.once(`${msgId}:finished`, (data) => { + switch (data.status) { + case 'signed': + return resolve(data.rawSig); + case 'rejected': + return reject( + ethErrors.provider.userRejectedRequest( + 'MetaMask Message Signature: User denied message signature.', + ), + ); + case 'errored': + return reject( + new Error(`MetaMask Message Signature: ${data.error}`), + ); + default: + return reject( + new Error( + `MetaMask Message Signature: Unknown problem: ${JSON.stringify( + msgParams, + )}`, + ), + ); + } + }); }); }); }