Skip to content

Commit

Permalink
Fetch msgId within the check method
Browse files Browse the repository at this point in the history
  • Loading branch information
filipsekulic committed Dec 8, 2022
1 parent 1f5db07 commit df954ff
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 53 deletions.
55 changes: 27 additions & 28 deletions app/scripts/lib/personal-message-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,41 +82,40 @@ 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(
new Error('MetaMask Message Signature: from field is required.'),
);
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,
)}`,
),
);
}
});
});
});
}
Expand Down
50 changes: 25 additions & 25 deletions app/scripts/lib/typed-message-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,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,
)}`,
),
);
}
});
});
});
}
Expand Down

0 comments on commit df954ff

Please sign in to comment.