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

allow up to 40 Lattice addresses to be loaded #598

Merged
merged 2 commits into from
Oct 13, 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
4 changes: 3 additions & 1 deletion app/App/Panel/Local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ class Settings extends React.Component {
onChange={(value) => link.send('tray:action', 'setLatticeAccountLimit', value)}
options={[
{ text: '5', value: 5 },
{ text: '10', value: 10 }
{ text: '10', value: 10 },
{ text: '20', value: 20 },
{ text: '40', value: 40 },
]}
/>
</div>
Expand Down
52 changes: 37 additions & 15 deletions main/signers/lattice/Lattice/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { sign, signerCompatibility, londonToLegacy } = require('../../../transact
const store = require('../../../store')
const Signer = require('../../Signer').default

const ADDRESS_LIMIT = 10
const HARDENED_OFFSET = 0x80000000

function humanReadable (str) {
Expand All @@ -35,7 +36,12 @@ class Lattice extends Signer {

if (this.accountLimit !== store('main.latticeSettings.accountLimit')) {
this.accountLimit = store('main.latticeSettings.accountLimit')
this.open()

if (this.addresses.length < this.accountLimit) {
this.open()
} else {
this.update()
}
}
})
}
Expand Down Expand Up @@ -108,10 +114,9 @@ class Lattice extends Signer {
this.appVersion = { major, minor, patch }

if (this.paired) {
if (this.addresses.length === 0) {
this.status = 'addresses'
this.update()
}
this.status = 'addresses'
this.update()

await this.deriveAddresses()
} else {
this.status = 'pair'
Expand Down Expand Up @@ -156,20 +161,28 @@ class Lattice extends Signer {
async deriveAddresses () {
// TODO: Move these settings to be device spectifc
const accountLimit = store('main.latticeSettings.accountLimit')

try {
const req = {
currency: 'ETH',
startPath: this._getPath(0),
n: accountLimit,
skipCache: true
}
if (!this.client) throw new Error('Client not ready during deriveAddresse')
if (!this.client) throw new Error('Client not ready during deriveAddresses')

const getAddresses = promisify(this.client.getAddresses).bind(this.client)
const result = await getAddresses(req)

while (this.addresses.length < accountLimit) {
const req = {
currency: 'ETH',
startPath: this._getPath(this.addresses.length),
n: Math.min(ADDRESS_LIMIT, accountLimit - this.addresses.length),
skipCache: true
}

const loadedAddresses = await getAddresses(req)
this.addresses = [...this.addresses, ...loadedAddresses]
}

this.status = 'ok'
this.addresses = result
this.update()
return result

return this.addresses
} catch (err) {
if (err === 'Error from device: Invalid Request') return log.warn('Lattice: Invalid Request')
if (err === 'Error from device: Device Busy') return log.warn('Lattice: Device Busy')
Expand Down Expand Up @@ -255,6 +268,15 @@ class Lattice extends Signer {
return (store('main.signers')[`lattice-${this.deviceId}`]) !== undefined
}

summary () {
const summary = super.summary()

return {
...summary,
addresses: this.addresses.slice(0, this.accountLimit || this.addresses.length)
}
}

update () {
// If this signer exists, update with current params
if (this.signerExists())
Expand Down