Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle locked signers #648

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
10 changes: 8 additions & 2 deletions app/App/Panel/Main/Account/SignerStatus/index.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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' ? (
<div className={shake ? 'signerStatus headShake' : 'signerStatus'} ref={this.statusRef}>
<div className='signerStatusWrap'>
<div className='signerStatusTop'>
Expand Down
30 changes: 29 additions & 1 deletion app/App/Panel/Notify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,28 @@ class Notify extends React.Component {
)
}

signerLockedWarning ({ req = {} }) {
return (
<div className='notifyBoxWrap' onMouseDown={e => e.stopPropagation()}>
<div className='notifyBox'>
<div className='notifyTitle'>
Signer locked!
</div>
<div className='notifyBody'>
<div className='notifyBodyQuestion'>
Please unlock this signer and try again
</div>
</div>
<div className='notifyInput'>
<div className='notifyInputOption notifyInputSingleButton' onMouseDown={() => { this.store.notify() }}>
<div className='notifyInputOptionText'>OK</div>
</div>
</div>
</div>
</div>
)
}

noSignerWarning ({ req = {} }) {
return (
<div className='notifyBoxWrap' onMouseDown={e => e.stopPropagation()}>
Expand Down Expand Up @@ -523,7 +545,13 @@ class Notify extends React.Component {
{this.noSignerWarning(this.store('view.notifyData'))}
</div>
)
}else if (notify === 'signerCompatibilityWarning') {
} else if (notify === 'signerLockedWarning') {
return (
<div className='notify cardShow' onMouseDown={() => this.store.notify()}>
{this.signerLockedWarning(this.store('view.notifyData'))}
</div>
)
} else if (notify === 'signerCompatibilityWarning') {
return (
<div className='notify cardShow' onMouseDown={() => this.store.notify()}>
{this.signerCompatibilityWarning(this.store('view.notifyData'))}
Expand Down
23 changes: 13 additions & 10 deletions main/accounts/Account/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
}
}

Expand Down
2 changes: 2 additions & 0 deletions main/accounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down