Skip to content

Commit

Permalink
Merge pull request #2106 from cosmos/fedekunze/2015-ledger-screensaver
Browse files Browse the repository at this point in the history
fix ledger screensaver bug
  • Loading branch information
faboweb authored Feb 27, 2019
2 parents da55bc6 + afe62ac commit ed09a6f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed

- Fixed delegations not loaded on validator lists @faboweb
- [\#2015](https://github.com/cosmos/voyager/issues/2015) fixed error that showed wrong message when Ledger's screensaver mode was on @fedekunze
- Reconnected event was not triggered after reconnection @faboweb
- [\#2094](https://github.com/cosmos/voyager/pull/2094) fix Toolbar @faboweb

Expand Down
8 changes: 6 additions & 2 deletions app/src/renderer/vuex/modules/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,23 @@ export default () => {
},
async pollLedgerDevice({ state }) {
// poll device with low timeout to check if the device is connected
const secondsTimeout = 2 // with less than 2 secs it always timeouts
const secondsTimeout = 3 // a lower value always timeouts
const communicationMethod = await state.externals.comm_u2f.create_async(
secondsTimeout,
true
)
const cosmosLedgerApp = new state.externals.App(communicationMethod)
const response = await cosmosLedgerApp.get_version()

// check if the device is connected or on screensaver mode
const response = await cosmosLedgerApp.publicKey(HDPATH)

switch (response.error_message) {
case `U2F: Timeout`:
throw new Error(`No Ledger found`)
case `Cosmos app does not seem to be open`:
throw new Error(`Cøsmos app is not open`)
case `Unknown error code`: // TODO: create error for screensaver mode
throw new Error(`Ledger's screensaver mode is on`)
case `No errors`:
// do nothing
break
Expand Down
26 changes: 19 additions & 7 deletions test/unit/specs/store/ledger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe(`Module: Ledger`, () => {
describe(`poll Ledger device`, () => {
it(`when Ledger is connected and app is open`, async () => {
state.externals.App = () => ({
get_version: () =>
publicKey: () =>
Promise.resolve({
error_message: `No errors`
})
Expand All @@ -129,7 +129,7 @@ describe(`Module: Ledger`, () => {

it(`when Ledger is connected but app is not open`, async () => {
state.externals.App = () => ({
get_version: () =>
publicKey: () =>
Promise.resolve({
error_message: `Cosmos app does not seem to be open`
})
Expand All @@ -141,7 +141,7 @@ describe(`Module: Ledger`, () => {

it(`when Ledger not connected`, async () => {
state.externals.App = () => ({
get_version: () =>
publicKey: () =>
Promise.resolve({
error_message: `U2F: Timeout`
})
Expand All @@ -151,15 +151,27 @@ describe(`Module: Ledger`, () => {
)
})

it(`fails due to other error`, async () => {
it(`when Ledger is on screensaver mode`, async () => {
state.externals.App = () => ({
get_version: () =>
publicKey: () =>
Promise.resolve({
error_message: `Device is busy`
error_message: `Unknown error code`
})
})
await expect(actions.pollLedgerDevice({ state })).rejects.toThrow(
`Device is busy`
`Ledger's screensaver mode is on`
)
})

it(`fails if publicKey throws`, async () => {
state.externals.App = () => ({
publicKey: () =>
Promise.resolve({
error_message: `Execution Error`
})
})
await expect(actions.pollLedgerDevice({ state })).rejects.toThrow(
`Execution Error`
)
})
})
Expand Down

0 comments on commit ed09a6f

Please sign in to comment.