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

Lattice config #440

Merged
merged 1 commit into from
May 18, 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
19 changes: 3 additions & 16 deletions app/App/Panel/Local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Settings extends React.Component {
this.networkType = context.store('main.currentNetwork.type')
const primaryCustom = context.store('main.networks', this.networkType, this.network, 'connection.primary.custom') || this.customMessage
const secondaryCustom = context.store('main.networks', this.networkType, this.network, 'connection.secondary.custom') || this.customMessage
const latticeEndpoint = context.store('main.latticeSettings.endpoint')
const latticeEndpoint = context.store('main.latticeSettings.endpointCustom')
const latticeEndpointMode = context.store('main.latticeSettings.endpointMode')
const latticeSuffix = context.store('main.latticeSettings.suffix')
this.state = { localShake: {}, primaryCustom, secondaryCustom, latticeEndpoint, latticeSuffix, latticeEndpointMode, resetConfirm: false, expandNetwork: false }
Expand Down Expand Up @@ -103,7 +103,7 @@ class Settings extends React.Component {
const value = e.target.value.replace(/\s+/g, '')
this.setState({ latticeEndpoint: value })
// TODO: Update to target specific Lattice device rather than global
this.inputLatticeTimeout = setTimeout(() => link.send('tray:action', 'setLatticeEndpoint', this.state.latticeEndpoint), 1000)
this.inputLatticeTimeout = setTimeout(() => link.send('tray:action', 'setLatticeEndpointCustom', this.state.latticeEndpoint), 1000)
}

inputLatticeSuffix (e) {
Expand Down Expand Up @@ -191,11 +191,6 @@ class Settings extends React.Component {
presets = Object.keys(presets).map(i => ({ text: i, value: type + ':' + id + ':' + i }))
presets = presets.concat(Object.keys(networkPresets.default).map(i => ({ text: i, value: type + ':' + id + ':' + i })))
presets.push({ text: 'Custom', value: type + ':' + id + ':' + 'custom' })
let latticePresets = {
'default': 'https://signing.gridpl.us',
'custom': ''
}
latticePresets = Object.keys(latticePresets).map((el, i) => ({ text: el, value: latticePresets[el]}))

const networkOptions = []
Object.keys(networks).forEach(type => {
Expand Down Expand Up @@ -388,16 +383,8 @@ class Settings extends React.Component {
<Dropdown
syncValue={this.store('main.latticeSettings.endpointMode')}
onChange={(value) => {

let newState = {
latticeEndpointMode: value
}

if (value === 'default') {
link.send('tray:action', 'setLatticeEndpoint', latticePresets['default'])
}
link.send('tray:action', 'setLatticeEndpointMode', value)
this.setState(newState)
this.setState({ latticeEndpointMode: value })
}}
options={[{ text: 'Default', value: 'default' }, { text: 'Custom', value: 'custom' }]}
/>
Expand Down
13 changes: 6 additions & 7 deletions dash/App/Signer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Signer extends React.Component {
addressLimit: 4,
latticePairCode: ''
}
this.loadingStatus = ['loading', 'connecting', 'addresses']
}

status () {
Expand Down Expand Up @@ -96,11 +95,7 @@ class Signer extends React.Component {
{this.status()}
</div>
{this.statusText()}
{this.loadingStatus.indexOf(this.props.status) > -1 ? (
<div className='signerLoading'>
<div className='signerLoadingLoader' />
</div>
) : this.props.type === 'lattice' && this.props.status === 'pairing' ? (
{this.props.type === 'lattice' && this.props.status === 'pairing' ? (
<div className='signerLatticePair'>
<div className='signerLatticePairTitle'>Please input your Lattice's pairing code</div>
<div className='signerLatticePairInput'>
Expand All @@ -123,7 +118,7 @@ class Signer extends React.Component {
className='signerLatticePairSubmit'
>Pair</div>
</div>
) : (
) : this.props.status === 'ok' || this.props.status === 'locked' ? (
<>
<div className='signerAccountsTitle'>
<span>{'Add & Remove Accounts'}</span>
Expand Down Expand Up @@ -158,6 +153,10 @@ class Signer extends React.Component {
<div className='signerBottomPageNext' onMouseDown={() => this.nextPage()}>{svg.triangleLeft(20)}</div>
</div>
</>
) : (
<div className='signerLoading'>
<div className='signerLoadingLoader' />
</div>
)}
<div className='signerDrawer' onMouseDown={() => this.setState({ showControls: !this.state.showControls })}>
<div className='showControls'>
Expand Down
77 changes: 49 additions & 28 deletions main/signers/lattice/Lattice/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,58 @@ class Lattice extends Signer {
this.type = 'lattice'
this.status = 'loading'

this.suffix = ''
this.baseUrl = ''
this.privKey = ''

this.latticeObs = store.observer(() => {
this.config = store('main.lattice', deviceId) || {}
if (!this.config.privKey) {
store.updateLattice(deviceId, { privKey: crypto.randomBytes(32).toString('hex') })
} else {
if (
this.suffix !== this.config.suffix ||
this.baseUrl !== this.config.baseUrl ||
this.privKey !== this.config.privKey
) {
this.client = this.createClient()
}
this.createClient()

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

})

this.update()
this.deviceStatus()
}

createClient () {
const { suffix, baseUrl, privKey } = this.config
const clientConfig = {
name: suffix ? `Frame-${suffix}` : 'Frame',
crypto: crypto,
timeout: 30000,
baseUrl,
privKey
let endpointMode, baseUrl, suffix, privKey
endpointMode = store('main.latticeSettings.endpointMode')
if (endpointMode === 'custom') {
baseUrl = store('main.latticeSettings.endpointCustom')
} else {
baseUrl = 'https://signing.gridpl.us'
}
suffix = store('main.latticeSettings.suffix')
privKey = store('main.lattice', this.deviceId, 'privKey')

if (
this.endpointMode !== endpointMode ||
this.suffix !== suffix ||
this.baseUrl !== baseUrl ||
this.privKey !== privKey
) {
this.endpointMode = endpointMode
this.suffix = suffix
this.baseUrl = baseUrl
this.privKey = privKey
console.log('creating client with', {
name: suffix ? `Frame-${suffix}` : 'Frame',
timeout: 30000,
baseUrl,
privKey
})
this.client = new Client({
name: suffix ? `Frame-${suffix}` : 'Frame',
crypto: crypto,
timeout: 30000,
baseUrl,
privKey
})
this.status = 'disconnected'
this.update()
this.deviceStatus()
}
return new Client(clientConfig)
}

async setPair (pin) {
Expand All @@ -76,12 +95,12 @@ class Lattice extends Signer {

async open () {
try {
if (this.config.deviceId) {
if (this.deviceId) {
if (!this.client) throw new Error('Client not ready during open')
this.status = 'connecting'
this.update()
const clientConnect = promisify(this.client.connect).bind(this.client)
this.paired = await clientConnect(this.config.deviceId)
this.paired = await clientConnect(this.deviceId)
if (this.paired) {
this.status = 'addresses'
this.update()
Expand All @@ -94,6 +113,8 @@ class Lattice extends Signer {
return new Error('No deviceId')
}
} catch (err) {
this.status = 'disconnected'
this.update()
log.error('Lattice Open Error', err)
return new Error(err)
}
Expand Down Expand Up @@ -130,7 +151,7 @@ class Lattice extends Signer {
this.update()
return result
} catch (err) {
this.status = 'locked'
this.status = err.message
this.update()
return []
}
Expand All @@ -142,8 +163,8 @@ class Lattice extends Signer {
}

async deviceStatus () {
// this.pollStatus() // Unscheduled requets reult in errors
if (this.deviceStatusActive || this.verifyActive) return
// this.pollStatus() // Unscheduled requets result in errors
if (this.deviceStatusActive) return
this.deviceStatusActive = true
try {
// If signer has no addresses, try deriving them
Expand Down
9 changes: 9 additions & 0 deletions main/store/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ module.exports = {
setLatticeAccountLimit: (u, limit) => {
u('main.latticeSettings.accountLimit', () => limit)
},
setLatticeEndpointMode: (u, mode) => {
u('main.latticeSettings.endpointMode', () => mode)
},
setLatticeEndpointCustom: (u, url) => {
u('main.latticeSettings.endpointCustom', () => url)
},
setLatticeSuffix: (u, suffix) => {
u('main.latticeSettings.suffix', () => suffix)
},
setLedgerDerivation: (u, value) => {
u('main.ledger.derivation', () => value)
},
Expand Down
5 changes: 4 additions & 1 deletion main/store/state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ const initial = {
menubarGasPrice: main('menubarGasPrice', false),
lattice: main('lattice', {}),
latticeSettings: {
accountLimit: main('latticeSettings.accountLimit', 4)
accountLimit: main('latticeSettings.accountLimit', 4),
endpointMode: main('latticeSettings.endpointMode', 'default'),
endpointCustom: main('latticeSettings.endpointCustom', ''),
suffix: main('latticeSettings.suffix', '')
},
ledger: {
derivation: main('ledger.derivation', 'live'),
Expand Down