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

Fabo/ Persist session type if signed in with ledger #2269

Merged
merged 6 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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: 2 additions & 2 deletions PENDING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Fixed

- [\#2257](https://github.com/cosmos/voyager/pull/2257) fixed console
- [\#2273](https://github.com/cosmos/voyager/issues/2273) fixed atoms and uatoms conversion @fedekunze
- Persist session type if signed in with ledger @faboweb
- [\#2273](https://github.com/cosmos/voyager/issues/2273) fixed atoms and uatoms conversion @fedekunze
6 changes: 3 additions & 3 deletions app/src/renderer/components/common/ActionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
5 changes: 5 additions & 0 deletions app/src/renderer/vuex/modules/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -46,6 +47,9 @@ export default () => {
setSignIn(state, hasSignedIn) {
state.signedIn = hasSignedIn
},
setSessionType(state, sessionType) {
state.sessionType = sessionType
},
setAccounts(state, accounts) {
state.accounts = accounts
},
Expand Down Expand Up @@ -148,6 +152,7 @@ export default () => {
.find(({ name }) => name === localKeyPairName).address
}
commit(`setSignIn`, true)
commit(`setSessionType`, sessionType)
dispatch(`setErrorCollection`, {
account: accountAddress,
optin: errorCollection
Expand Down
22 changes: 10 additions & 12 deletions test/unit/specs/components/common/ActionModal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ describe(`ActionModal`, () => {
dispatch: jest.fn(),
getters: {
connected: true,
ledger: { isConnected: false },
session: { signedIn: true }
session: { signedIn: true, sessionType: `local` }
}
}

Expand Down Expand Up @@ -43,8 +42,7 @@ describe(`ActionModal`, () => {
$store = {
getters: {
connected: true,
ledger: { isConnected: true },
session: { signedIn: true }
session: { signedIn: true, sessionType: `ledger` }
}
}
wrapper = shallowMount(ActionModal, {
Expand All @@ -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()
Expand Down Expand Up @@ -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(),
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -210,7 +208,7 @@ describe(`ActionModal`, () => {
let self, getterValues

beforeEach(() => {
getterValues = { ledger: { isConnected: false } }
getterValues = { session: { sessionType: `ledger` } }
self = {
...getterValues,
submit: jest.fn(
Expand All @@ -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)
Expand All @@ -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: {
Expand Down Expand Up @@ -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([
{
Expand Down
7 changes: 7 additions & 0 deletions test/unit/specs/store/session.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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`
Expand All @@ -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)
Expand Down