-
Notifications
You must be signed in to change notification settings - Fork 98
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
Multiple accounts #224
Multiple accounts #224
Changes from all commits
3f88fb3
7362fd7
eaedc72
c7aab81
cf33f28
2f691c2
6712f5e
0305b77
f1b703c
5528b0d
2aca202
9ae5b8b
ff20b43
1c28ac1
1932d25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,5 +25,5 @@ export default { | |
@require '~variables' | ||
|
||
.ni-field.ni-field-seed | ||
height 5rem | ||
height 6rem | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { KEY_PASSWORD, KEY_NAME } from './wallet' | ||
|
||
export default ({ commit, node }) => { | ||
const emptyNomination = { | ||
keybase: '', | ||
|
@@ -20,35 +18,38 @@ export default ({ commit, node }) => { | |
delegation: [], | ||
pubkey: '', | ||
privkey: null, | ||
signedIn: false | ||
signedIn: false, | ||
accounts: [] | ||
} | ||
|
||
const state = JSON.parse(JSON.stringify(emptyUser)) | ||
|
||
const mutations = { | ||
activateDelegation (state) { | ||
state.delegationActive = true | ||
}, | ||
setAccounts (state, accounts) { | ||
state.accounts = accounts | ||
} | ||
} | ||
|
||
const actions = { | ||
async showInitialScreen ({ dispatch }) { | ||
let exists = await dispatch('accountExists') | ||
await dispatch('loadAccounts') | ||
let exists = state.accounts.length > 0 | ||
let screen = exists ? 'sign-in' : 'welcome' | ||
commit('setModalSessionState', screen) | ||
commit('setModalSession', true) | ||
}, | ||
async accountExists (state, account = KEY_NAME) { | ||
async loadAccounts ({ commit }) { | ||
try { | ||
let keys = await node.listKeys() | ||
return !!keys.find(key => key.name === account) | ||
commit('setAccounts', keys.map((key) => key.name)) | ||
} catch (err) { | ||
commit('notifyError', { title: `Couldn't read keys'`, body: err.message }) | ||
commit('notifyError', { title: `Couldn't read keys`, body: err.message }) | ||
} | ||
}, | ||
// testing if the provided password works so we can show the user early if he uses the wrong password | ||
// testing this by trying to change the password... to the same password... | ||
async testLogin (state, {password, account = KEY_NAME}) { | ||
async testLogin (state, { password, account }) { | ||
try { | ||
return await node.updateKey(account, { | ||
name: account, | ||
|
@@ -62,41 +63,42 @@ export default ({ commit, node }) => { | |
// to create a temporary seed phrase, we create a junk account with name 'trunk' for now | ||
async createSeed ({ commit }) { | ||
let JUNK_ACCOUNT_NAME = 'trunk' | ||
let TRUNK_PASSWORD = '1234567890' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to get rid of this. A malicious user could access the last generated trunk account with the standard password. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prerequesit: cosmos/cosmos-sdk#301 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean in this PR or an another PR? this is not new — this is currently how it works... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note. I commented on that, because I implemented it like that and wanted to share the thought. |
||
try { | ||
// cleanup an existing junk account | ||
let keys = await node.listKeys() | ||
if (keys.find(key => key.name === JUNK_ACCOUNT_NAME)) { | ||
await node.deleteKey(JUNK_ACCOUNT_NAME, { | ||
password: KEY_PASSWORD, | ||
password: TRUNK_PASSWORD, | ||
name: JUNK_ACCOUNT_NAME | ||
}) | ||
} | ||
|
||
// generate seedPhrase with junk account | ||
let temporaryKey = await node.generateKey({ name: JUNK_ACCOUNT_NAME, password: KEY_PASSWORD }) | ||
let temporaryKey = await node.generateKey({ name: JUNK_ACCOUNT_NAME, password: TRUNK_PASSWORD }) | ||
return temporaryKey.seed_phrase | ||
} catch (err) { | ||
commit('notifyError', { title: 'Couln\'t create a seed', body: err.message }) | ||
commit('notifyError', { title: `Couldn't create a seed`, body: err.message }) | ||
} | ||
}, | ||
async createKey ({ commit, dispatch }, { seedPhrase, password, name = KEY_NAME }) { | ||
async createKey ({ commit, dispatch }, { seedPhrase, password, name }) { | ||
try { | ||
let {key} = await node.recoverKey({ name, password, seed_phrase: seedPhrase }) | ||
dispatch('initializeWallet', key) | ||
return key | ||
} catch (err) { | ||
commit('notifyError', { title: 'Couln\'t create a key', body: err.message }) | ||
commit('notifyError', { title: `Couldn't create a key`, body: err.message }) | ||
} | ||
}, | ||
async deleteKey ({ commit, dispatch }, { password, name = KEY_NAME }) { | ||
async deleteKey ({ commit, dispatch }, { password, name }) { | ||
try { | ||
await node.deleteKey(name, { name, password }) | ||
return true | ||
} catch (err) { | ||
commit('notifyError', { title: `Couln't delete account ${name}`, body: err.message }) | ||
commit('notifyError', { title: `Couldn't delete account ${name}`, body: err.message }) | ||
} | ||
}, | ||
async signIn ({ state, dispatch }, {password, account = KEY_NAME}) { | ||
async signIn ({ state, dispatch }, { password, account }) { | ||
state.password = password | ||
state.account = account | ||
state.signedIn = true | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use allDenomBalances.length?