From f4061e3dde63f024cd2ead3797a0ecd660654e40 Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Mon, 29 Nov 2021 19:32:24 -0500 Subject: [PATCH] handle locked signers --- .../Requests/TransactionRequest/index.js | 2 ++ .../Panel/Main/Account/SignerStatus/index.js | 10 +++++-- app/App/Panel/Notify/index.js | 30 ++++++++++++++++++- main/accounts/Account/index.js | 23 +++++++------- main/accounts/index.js | 2 ++ 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/app/App/Panel/Main/Account/Requests/TransactionRequest/index.js b/app/App/Panel/Main/Account/Requests/TransactionRequest/index.js index 9c81c1e55..28f8c635b 100644 --- a/app/App/Panel/Main/Account/Requests/TransactionRequest/index.js +++ b/app/App/Panel/Main/Account/Requests/TransactionRequest/index.js @@ -546,6 +546,8 @@ class TransactionRequest extends React.Component { link.rpc('signerCompatibility', req.handlerId, (e, compatibility) => { if (e === 'No signer') { this.store.notify('noSignerWarning', { req }) + } else if (e === 'Signer locked') { + this.store.notify('signerLockedWarning', { req }) } else if (!compatibility.compatible && !this.store('main.mute.signerCompatibilityWarning')) { this.store.notify('signerCompatibilityWarning', { req, compatibility, chain: this.chain }) } else if ((maxFeeUSD.toNumber() > FEE_WARNING_THRESHOLD_USD || this.toDisplayUSD(maxFeeUSD) === '0.00') && !this.store('main.mute.gasFeeWarning')) { diff --git a/app/App/Panel/Main/Account/SignerStatus/index.js b/app/App/Panel/Main/Account/SignerStatus/index.js index c823e5d44..a74b1161d 100644 --- a/app/App/Panel/Main/Account/SignerStatus/index.js +++ b/app/App/Panel/Main/Account/SignerStatus/index.js @@ -1,9 +1,12 @@ import React from 'react' -import ReactDOM from 'react-dom' import Restore from 'react-restore' import link from '../../../../../../resources/link' import svg from '../../../../../../resources/svg' +function isHardwareSigner (type = '') { + return ['ledger', 'trezor', 'lattice'].includes(type.toLowerCase()) +} + class SignerStatus extends React.Component { constructor (...args) { super(...args) @@ -80,7 +83,10 @@ class SignerStatus extends React.Component { render () { const { shake } = this.state - return this.props.signer && this.props.signer.id && this.props.signer.status === 'locked' ? ( + const signer = this.props.signer || {} + const isHardware = isHardwareSigner(signer.type) + + return !isHardware && signer.id && signer.status === 'locked' ? (
diff --git a/app/App/Panel/Notify/index.js b/app/App/Panel/Notify/index.js index f80d9addc..bcc8df9da 100644 --- a/app/App/Panel/Notify/index.js +++ b/app/App/Panel/Notify/index.js @@ -238,6 +238,28 @@ class Notify extends React.Component { ) } + signerLockedWarning ({ req = {} }) { + return ( +
e.stopPropagation()}> +
+
+ Signer locked! +
+
+
+ Please unlock this signer and try again +
+
+
+
{ this.store.notify() }}> +
OK
+
+
+
+
+ ) + } + noSignerWarning ({ req = {} }) { return (
e.stopPropagation()}> @@ -523,7 +545,13 @@ class Notify extends React.Component { {this.noSignerWarning(this.store('view.notifyData'))}
) - }else if (notify === 'signerCompatibilityWarning') { + } else if (notify === 'signerLockedWarning') { + return ( +
this.store.notify()}> + {this.signerLockedWarning(this.store('view.notifyData'))} +
+ ) + } else if (notify === 'signerCompatibilityWarning') { return (
this.store.notify()}> {this.signerCompatibilityWarning(this.store('view.notifyData'))} diff --git a/main/accounts/Account/index.js b/main/accounts/Account/index.js index 1f116fe56..750276ea6 100644 --- a/main/accounts/Account/index.js +++ b/main/accounts/Account/index.js @@ -220,18 +220,21 @@ class Account { log.info('Could not find address in signer') cb(new Error('Could not find address in signer')) } - } else if (this.signer && signers.get(this.signer) && signers.get(this.signer).verifyAddress) { - const s = signers.get(this.signer) - const index = s.addresses.map(a => a.toLowerCase()).indexOf(this.address) - if (index > -1) { - s.verifyAddress(index, this.address, display, cb) + } else { + const signer = signers.get(this.signer) || {} + + if (signer.verifyAddress && signer.status === 'ok') { + const index = s.addresses.map(a => a.toLowerCase()).indexOf(this.address) + if (index > -1) { + signer.verifyAddress(index, this.address, display, cb) + } else { + log.info('Could not find address in signer') + cb(new Error('Could not find address in signer')) + } } else { - log.info('Could not find address in signer') - cb(new Error('Could not find address in signer')) + log.info('No signer active to verify address') + cb(new Error('No signer active to verify address')) } - } else { - log.info('No signer active to verify address') - cb(new Error('No signer active to verify address')) } } diff --git a/main/accounts/index.js b/main/accounts/index.js index 7e4f9f2f3..d28c99ab8 100644 --- a/main/accounts/index.js +++ b/main/accounts/index.js @@ -480,6 +480,8 @@ class Accounts extends EventEmitter { const signer = currentAccount.getSigner() if (!signer) return cb(new Error('No signer')) + if (signer.status === 'locked') return cb(new Error('Signer locked')) + const data = currentAccount.requests[handlerId].data cb(null, signerCompatibility(data, signer.summary())) }