From e69a6d6dee13a249b3b62f209cd20790c02caf68 Mon Sep 17 00:00:00 2001 From: David Walsh Date: Fri, 7 May 2021 15:54:20 -0500 Subject: [PATCH] Prevent signature request component from canceling hardware wallet signing (#11013) --- .../signature-request.component.js | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/ui/components/app/signature-request/signature-request.component.js b/ui/components/app/signature-request/signature-request.component.js index f19d077ae..37eefcfeb 100644 --- a/ui/components/app/signature-request/signature-request.component.js +++ b/ui/components/app/signature-request/signature-request.component.js @@ -27,23 +27,25 @@ export default class SignatureRequest extends PureComponent { }; componentDidMount() { - const { clearConfirmTransaction, cancel } = this.props; - const { metricsEvent } = this.context; if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) { - window.addEventListener('beforeunload', (event) => { - metricsEvent({ - eventOpts: { - category: 'Transactions', - action: 'Sign Request', - name: 'Cancel Sig Request Via Notification Close', - }, - }); - clearConfirmTransaction(); - cancel(event); - }); + window.addEventListener('beforeunload', this._beforeUnload); } } + _beforeUnload = (event) => { + const { clearConfirmTransaction, cancel } = this.props; + const { metricsEvent } = this.context; + metricsEvent({ + eventOpts: { + category: 'Transactions', + action: 'Sign Request', + name: 'Cancel Sig Request Via Notification Close', + }, + }); + clearConfirmTransaction(); + cancel(event); + }; + formatWallet(wallet) { return `${wallet.slice(0, 8)}...${wallet.slice( wallet.length - 8, @@ -63,6 +65,16 @@ export default class SignatureRequest extends PureComponent { const { address: fromAddress } = fromAccount; const { message, domain = {} } = JSON.parse(data); + const onSign = (event) => { + window.removeEventListener('beforeunload', this._beforeUnload); + sign(event); + }; + + const onCancel = (event) => { + window.removeEventListener('beforeunload', this._beforeUnload); + cancel(event); + }; + return (
@@ -86,7 +98,7 @@ export default class SignatureRequest extends PureComponent {
-