diff --git a/PENDING.md b/PENDING.md index 9fa4faf27b..2e8ad3845d 100644 --- a/PENDING.md +++ b/PENDING.md @@ -5,4 +5,5 @@ ### Fixed - [\#2257](https://github.com/cosmos/voyager/pull/2257) fixed console +- [\#2269](https://github.com/cosmos/voyager/pull/2269) Persist session type if signed in with ledger @faboweb - [\#2273](https://github.com/cosmos/voyager/issues/2273) fixed atoms and uatoms conversion @fedekunze diff --git a/app/src/renderer/components/common/ActionModal.vue b/app/src/renderer/components/common/ActionModal.vue index d4423ca4e4..14d9bdd4a5 100644 --- a/app/src/renderer/components/common/ActionModal.vue +++ b/app/src/renderer/components/common/ActionModal.vue @@ -194,15 +194,15 @@ export default { track }), computed: { - ...mapGetters([`connected`, `ledger`, `session`]), + ...mapGetters([`connected`, `session`]), selectedSignMethod() { - if (this.ledger.isConnected) { + if (this.session.sessionType === `ledger`) { return signWithLedger } return signWithLocalKeystore }, signMethods() { - if (this.ledger.isConnected) { + if (this.session.sessionType === `ledger`) { return [ { key: `Ledger Nano S`, diff --git a/app/src/renderer/vuex/modules/session.js b/app/src/renderer/vuex/modules/session.js index d7f4ea8b6f..3ffdbbd333 100644 --- a/app/src/renderer/vuex/modules/session.js +++ b/app/src/renderer/vuex/modules/session.js @@ -13,6 +13,7 @@ export default () => { experimentalMode: config.development, // development mode insecureMode: config.development, // show the local signer signedIn: false, + sessionType: null, // local, ledger accounts: [], localKeyPairName: null, // used for signing with a locally stored key; TODO: move into own module pauseHistory: false, @@ -46,6 +47,9 @@ export default () => { setSignIn(state, hasSignedIn) { state.signedIn = hasSignedIn }, + setSessionType(state, sessionType) { + state.sessionType = sessionType + }, setAccounts(state, accounts) { state.accounts = accounts }, @@ -148,6 +152,7 @@ export default () => { .find(({ name }) => name === localKeyPairName).address } commit(`setSignIn`, true) + commit(`setSessionType`, sessionType) dispatch(`setErrorCollection`, { account: accountAddress, optin: errorCollection diff --git a/test/unit/specs/components/common/ActionModal.spec.js b/test/unit/specs/components/common/ActionModal.spec.js index 922faa0880..267b42b264 100644 --- a/test/unit/specs/components/common/ActionModal.spec.js +++ b/test/unit/specs/components/common/ActionModal.spec.js @@ -14,8 +14,7 @@ describe(`ActionModal`, () => { dispatch: jest.fn(), getters: { connected: true, - ledger: { isConnected: false }, - session: { signedIn: true } + session: { signedIn: true, sessionType: `local` } } } @@ -43,8 +42,7 @@ describe(`ActionModal`, () => { $store = { getters: { connected: true, - ledger: { isConnected: true }, - session: { signedIn: true } + session: { signedIn: true, sessionType: `ledger` } } } wrapper = shallowMount(ActionModal, { @@ -63,7 +61,7 @@ describe(`ActionModal`, () => { }) it(`with ledger and is on sign step`, async () => { - wrapper.vm.ledger.isConnected = true + wrapper.vm.session.sessionType = `ledger` wrapper.vm.step = `sign` await wrapper.vm.$nextTick() expect(wrapper.vm.$el).toMatchSnapshot() @@ -149,7 +147,7 @@ describe(`ActionModal`, () => { describe(`runs validation and changes step`, () => { let self, getterValues beforeEach(() => { - getterValues = { ledger: { isConnected: false } } + getterValues = { session: { sessionType: `ledger` } } self = { ...getterValues, submit: jest.fn(), @@ -168,7 +166,7 @@ describe(`ActionModal`, () => { }) it(`if connected to ledger and is on 'txDetails' step`, async () => { - self.ledger = { isConnected: true } + self.session.sessionType = `ledger` self.selectedSignMethod = `ledger` await ActionModal.methods.validateChangeStep.call(self) expect(self.validate).toHaveBeenCalled() @@ -177,7 +175,7 @@ describe(`ActionModal`, () => { }) it(`if connected to ledger and is on 'sign' step`, async () => { - self.ledger = { isConnected: true } + self.session.sessionType = `ledger` self.selectedSignMethod = `ledger` self.step = `sign` await ActionModal.methods.validateChangeStep.call(self) @@ -210,7 +208,7 @@ describe(`ActionModal`, () => { let self, getterValues beforeEach(() => { - getterValues = { ledger: { isConnected: false } } + getterValues = { session: { sessionType: `ledger` } } self = { ...getterValues, submit: jest.fn( @@ -235,7 +233,7 @@ describe(`ActionModal`, () => { }) it(`when signing with ledger`, done => { - self.ledger = { isConnected: true } + self.session.sessionType = `ledger` self.step = `sign` ActionModal.methods.validateChangeStep.call(self).then(() => { expect(self.sending).toBe(false) @@ -252,7 +250,7 @@ describe(`ActionModal`, () => { }) it(`hides password input if signing with Ledger`, async () => { - $store.getters.ledger.isConnected = true + $store.getters.session.sessionType = `ledger` wrapper = shallowMount(ActionModal, { localVue, propsData: { @@ -280,7 +278,7 @@ describe(`ActionModal`, () => { }) it(`selects ledger if device is connected`, () => { - $store.getters.ledger.isConnected = true + $store.getters.session.sessionType = `ledger` expect(wrapper.vm.selectedSignMethod).toBe(`ledger`) expect(wrapper.vm.signMethods).toEqual([ { diff --git a/test/unit/specs/store/session.spec.js b/test/unit/specs/store/session.spec.js index ff3d6a88dd..2cf59a163f 100644 --- a/test/unit/specs/store/session.spec.js +++ b/test/unit/specs/store/session.spec.js @@ -72,6 +72,11 @@ describe(`Module: Session`, () => { expect(state.pauseHistory).toBe(false) }) + it(`should set the session type`, () => { + mutations.setSessionType(state, `xxx`) + expect(state.sessionType).toBe(`xxx`) + }) + it(`should set accounts`, () => { mutations.setAccounts(state, accounts) expect(state.accounts).toEqual(accounts) @@ -231,6 +236,7 @@ describe(`Module: Session`, () => { `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9` ) expect(commit).toHaveBeenCalledWith(`toggleSessionModal`, false) + expect(commit).toHaveBeenCalledWith(`setSessionType`, `local`) expect(dispatch).toHaveBeenCalledWith(`loadPersistedState`) expect(dispatch).toHaveBeenCalledWith(`initializeWallet`, { address: `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9` @@ -252,6 +258,7 @@ describe(`Module: Session`, () => { ) expect(commit).toHaveBeenCalledWith(`setUserAddress`, address) expect(commit).toHaveBeenCalledWith(`toggleSessionModal`, false) + expect(commit).toHaveBeenCalledWith(`setSessionType`, `ledger`) expect(dispatch).toHaveBeenCalledWith(`loadPersistedState`) expect(dispatch).toHaveBeenCalledWith(`initializeWallet`, { address }) expect(dispatch).toHaveBeenCalledWith(`loadErrorCollection`, address)