From 0813cc5c8860bf8f5aa31a79ad09225a235a2070 Mon Sep 17 00:00:00 2001 From: Erik Marks <25517051+rekmarks@users.noreply.github.com> Date: Tue, 16 Jun 2020 07:40:00 -0700 Subject: [PATCH] Fix encrypt/decrypt beforeunload bugs (#8816) --- app/scripts/lib/decrypt-message-manager.js | 6 +-- .../lib/encryption-public-key-manager.js | 6 +-- .../confirm-decrypt-message.component.js | 40 +++++++++++-------- ...confirm-encryption-public-key.component.js | 28 ++++++++----- 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/app/scripts/lib/decrypt-message-manager.js b/app/scripts/lib/decrypt-message-manager.js index cf67ee03e..94f88d12d 100644 --- a/app/scripts/lib/decrypt-message-manager.js +++ b/app/scripts/lib/decrypt-message-manager.js @@ -82,7 +82,7 @@ export default class DecryptMessageManager extends EventEmitter { addUnapprovedMessageAsync (msgParams, req) { return new Promise((resolve, reject) => { if (!msgParams.from) { - reject(new Error('MetaMask Message for Decryption: from field is required.')) + reject(new Error('MetaMask Decryption: from field is required.')) } const msgId = this.addUnapprovedMessage(msgParams, req) this.once(`${msgId}:finished`, (data) => { @@ -90,11 +90,11 @@ export default class DecryptMessageManager extends EventEmitter { case 'decrypted': return resolve(data.rawData) case 'rejected': - return reject(ethErrors.provider.userRejectedRequest('MetaMask Message for Decryption: User denied message decryption.')) + return reject(ethErrors.provider.userRejectedRequest('MetaMask Decryption: User denied message decryption.')) case 'errored': return reject(new Error('This message cannot be decrypted')) default: - return reject(new Error(`MetaMask Message for Decryption: Unknown problem: ${JSON.stringify(msgParams)}`)) + return reject(new Error(`MetaMask Decryption: Unknown problem: ${JSON.stringify(msgParams)}`)) } }) }) diff --git a/app/scripts/lib/encryption-public-key-manager.js b/app/scripts/lib/encryption-public-key-manager.js index a714f60e4..0ae12442b 100644 --- a/app/scripts/lib/encryption-public-key-manager.js +++ b/app/scripts/lib/encryption-public-key-manager.js @@ -79,7 +79,7 @@ export default class EncryptionPublicKeyManager extends EventEmitter { addUnapprovedMessageAsync (address, req) { return new Promise((resolve, reject) => { if (!address) { - reject(new Error('MetaMask Message for EncryptionPublicKey: address field is required.')) + reject(new Error('MetaMask Message: address field is required.')) } const msgId = this.addUnapprovedMessage(address, req) this.once(`${msgId}:finished`, (data) => { @@ -87,9 +87,9 @@ export default class EncryptionPublicKeyManager extends EventEmitter { case 'received': return resolve(data.rawData) case 'rejected': - return reject(ethErrors.provider.userRejectedRequest('MetaMask Message for EncryptionPublicKey: User denied message EncryptionPublicKey.')) + return reject(ethErrors.provider.userRejectedRequest('MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.')) default: - return reject(new Error(`MetaMask Message for EncryptionPublicKey: Unknown problem: ${JSON.stringify(address)}`)) + return reject(new Error(`MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(address)}`)) } }) }) diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js index fafc401e9..3f82c39c4 100644 --- a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js @@ -52,9 +52,14 @@ export default class ConfirmDecryptMessage extends Component { this._removeBeforeUnload() } - _beforeUnload = (event) => { - const { clearConfirmTransaction, cancelDecryptMessage } = this.props + _beforeUnload = async (event) => { + const { + clearConfirmTransaction, + cancelDecryptMessage, + txData, + } = this.props const { metricsEvent } = this.context + await cancelDecryptMessage(txData, event) metricsEvent({ eventOpts: { category: 'Messages', @@ -63,7 +68,6 @@ export default class ConfirmDecryptMessage extends Component { }, }) clearConfirmTransaction() - cancelDecryptMessage(event) } _removeBeforeUnload = () => { @@ -103,11 +107,12 @@ export default class ConfirmDecryptMessage extends Component { renderAccount = () => { const { fromAccount } = this.state + const { t } = this.context return (