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

Show default balance denominations #176

Merged
merged 6 commits into from
Dec 6, 2017
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
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"event-to-promise": "^0.8.0",
"express": "^4.16.2",
"express-http-proxy": "^1.1.0",
"fs-extra": "^2.0.0",
"fs-extra": "^4.0.0",
"js-weave": "^1.3.0",
"levelup": "^1.3.8",
"memdown": "^1.2.4",
Expand Down
15 changes: 14 additions & 1 deletion app/src/renderer/components/wallet/PageBalances.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,22 @@ export default {
},
computed: {
...mapGetters(['filters', 'wallet']),
allDenomBalances () {
// for denoms not in balances, add empty balance
let balances = this.wallet.balances
let hasDenom = (denom) => {
return !!balances.filter((balance) =>
balance.denom === denom)[0]
}
for (let denom of this.wallet.denoms) {
if (hasDenom(denom)) continue
balances.push({ denom, amount: 0 })
}
return balances
},
filteredBalances () {
let query = this.filters.balances.search.query
let list = orderBy(this.wallet.balances, ['denom'], ['desc'])
let list = orderBy(this.allDenomBalances, ['amount', 'denom'], ['desc', 'asc'])
if (this.filters.balances.search.visible) {
return list.filter(i => includes(i.denom.toLowerCase(), query))
} else {
Expand Down
47 changes: 41 additions & 6 deletions app/src/renderer/vuex/modules/wallet.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
let fs = require('fs-extra')
let { join } = require('path')
let root = require('../../../root.js')

const KEY_NAME = 'default'
// TODO: add UI for password, instead of hardcoding one
const KEY_PASSWORD = '1234567890'

export default ({ commit, node }) => {
let state = {
balances: [
// TODO: set denom list dynamically somehow (maybe from denoms genesis.json?)
{ denom: 'atom', amount: 0 },
{ denom: 'mycoin', amount: 0 }
],
balances: [],
sequence: 0,
key: { address: '' },
history: []
history: [],
denoms: []
}

let mutations = {
Expand All @@ -30,6 +31,10 @@ export default ({ commit, node }) => {
setWalletHistory (state, history) {
state.history = history
console.log('setWalletHistory', history)
},
setDenoms (state, denoms) {
state.denoms = denoms
console.log('setDenoms', denoms)
}
}

Expand All @@ -48,6 +53,7 @@ export default ({ commit, node }) => {
}
commit('setWalletKey', key)
dispatch('queryWalletState')
dispatch('loadDenoms')
},
queryWalletState ({ state, dispatch }) {
dispatch('queryWalletBalances')
Expand Down Expand Up @@ -98,8 +104,37 @@ export default ({ commit, node }) => {
}
if (cb) cb(null, args)
dispatch('queryWalletBalances')
},
async loadDenoms () {
// read genesis.json to get default denoms

// wait for genesis.json to exist
let genesisPath = join(root, 'genesis.json')
while (true) {
try {
await fs.pathExists(genesisPath)
break
} catch (err) {
console.log('waiting for genesis', err, genesisPath)
await sleep(500)
}
}

let genesis = await fs.readJson(genesisPath)
let denoms = {}
for (let account of genesis.app_options.accounts) {
for (let { denom } of account.coins) {
denoms[denom] = true
}
}

commit('setDenoms', Object.keys(denoms))
}
}

return { state, mutations, actions }
}

function sleep (ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
19 changes: 12 additions & 7 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,13 @@ fresh@0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"

fs-extra@^2.0.0:
version "2.1.2"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-2.1.2.tgz#046c70163cef9aad46b0e4a7fa467fb22d71de35"
fs-extra@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^2.1.0"
jsonfile "^4.0.0"
universalify "^0.1.0"

functional-red-black-tree@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -941,9 +942,9 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"

jsonfile@^2.1.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8"
jsonfile@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
optionalDependencies:
graceful-fs "^4.1.6"

Expand Down Expand Up @@ -1684,6 +1685,10 @@ ultron@1.0.x:
version "1.0.2"
resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.0.2.tgz#ace116ab557cd197386a4e88f4685378c8b2e4fa"

universalify@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"

unorm@^1.3.3:
version "1.4.1"
resolved "https://registry.yarnpkg.com/unorm/-/unorm-1.4.1.tgz#364200d5f13646ca8bcd44490271335614792300"
Expand Down
2 changes: 1 addition & 1 deletion test/unit/specs/__snapshots__/PageBalances.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PageBalances has the expected html structure 1`] = `"<div class=\\"ni-page\\"><header class=\\"ni-page-header\\"><div class=\\"ni-page-header-container\\"><div class=\\"ni-page-header-text\\"><div class=\\"ni-page-header-title\\"><div>Balance</div></div><div class=\\"ni-page-header-subtitle\\"><div></div></div></div><menu class=\\"ni-page-header-menu\\"><div><div><div class=\\"ni-tool-bar\\"><div class=\\"ni-tool-bar-container\\"><div class=\\"main\\"><a><i class=\\"material-icons\\">refresh</i><div class=\\"label\\">Refresh</div></a><a data-clipboard-text=\\"\\" class=\\"anchor-copy\\"><i class=\\"material-icons\\">content_copy</i><div class=\\"label\\">Copy</div></a><a><i class=\\"material-icons\\">search</i><div class=\\"label\\">Search</div></a></div><a class=\\"help\\"><i class=\\"material-icons\\">help_outline</i></a></div></div></div></div></menu></div></header><main class=\\"ni-page-main\\"><!----><section class=\\"ni-part\\"><div class=\\"ni-part-container\\"><header class=\\"ni-part-header\\"><div class=\\"ni-part-header-container\\"><div class=\\"ni-part-title h5\\">Your Address</div><menu class=\\"ni-part-menu\\"></menu></div></header><main class=\\"ni-part-main\\"><div class=\\"ni-li\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">Address</div><div class=\\"ni-li-dd\\"></div></div></div></div></main></div></section><section class=\\"ni-part\\"><div class=\\"ni-part-container\\"><header class=\\"ni-part-header\\"><div class=\\"ni-part-header-container\\"><div class=\\"ni-part-title h5\\">Denomination Balances</div><menu class=\\"ni-part-menu\\"></menu></div></header><main class=\\"ni-part-main\\"><div class=\\"ni-li proposal-enter proposal-enter-active\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">456</div><div class=\\"ni-li-dd\\">456</div></div></div></div><div class=\\"ni-li proposal-enter proposal-enter-active\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">123</div><div class=\\"ni-li-dd\\">123</div></div></div></div><div class=\\"ni-li proposal-leave proposal-leave-active\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">MYCOIN</div><div class=\\"ni-li-dd\\">0</div></div></div></div><div class=\\"ni-li proposal-leave proposal-leave-active\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">ATOM</div><div class=\\"ni-li-dd\\">0</div></div></div></div><!----></main></div></section></main><footer class=\\"ni-page-footer\\"><div class=\\"container\\"></div></footer></div>"`;
exports[`PageBalances has the expected html structure 1`] = `"<div class=\\"ni-page\\"><header class=\\"ni-page-header\\"><div class=\\"ni-page-header-container\\"><div class=\\"ni-page-header-text\\"><div class=\\"ni-page-header-title\\"><div>Balance</div></div><div class=\\"ni-page-header-subtitle\\"><div></div></div></div><menu class=\\"ni-page-header-menu\\"><div><div><div class=\\"ni-tool-bar\\"><div class=\\"ni-tool-bar-container\\"><div class=\\"main\\"><a><i class=\\"material-icons\\">refresh</i><div class=\\"label\\">Refresh</div></a><a data-clipboard-text=\\"\\" class=\\"anchor-copy\\"><i class=\\"material-icons\\">content_copy</i><div class=\\"label\\">Copy</div></a><a><i class=\\"material-icons\\">search</i><div class=\\"label\\">Search</div></a></div><a class=\\"help\\"><i class=\\"material-icons\\">help_outline</i></a></div></div></div></div></menu></div></header><main class=\\"ni-page-main\\"><!----><section class=\\"ni-part\\"><div class=\\"ni-part-container\\"><header class=\\"ni-part-header\\"><div class=\\"ni-part-header-container\\"><div class=\\"ni-part-title h5\\">Your Address</div><menu class=\\"ni-part-menu\\"></menu></div></header><main class=\\"ni-part-main\\"><div class=\\"ni-li\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">Address</div><div class=\\"ni-li-dd\\"></div></div></div></div></main></div></section><section class=\\"ni-part\\"><div class=\\"ni-part-container\\"><header class=\\"ni-part-header\\"><div class=\\"ni-part-header-container\\"><div class=\\"ni-part-title h5\\">Denomination Balances</div><menu class=\\"ni-part-menu\\"></menu></div></header><main class=\\"ni-part-main\\"><div class=\\"ni-li proposal-enter proposal-enter-active\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">456</div><div class=\\"ni-li-dd\\">456</div></div></div></div><div class=\\"ni-li proposal-enter proposal-enter-active\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">123</div><div class=\\"ni-li-dd\\">123</div></div></div></div><!----><div class=\\"ni-li proposal-leave proposal-leave-active\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">N/A</div><div class=\\"ni-li-dd\\">None Available</div></div></div></div></main></div></section></main><footer class=\\"ni-page-footer\\"><div class=\\"container\\"></div></footer></div>"`;

exports[`PageBalances should filter the balances 1`] = `"<div class=\\"ni-page\\"><header class=\\"ni-page-header\\"><div class=\\"ni-page-header-container\\"><div class=\\"ni-page-header-text\\"><div class=\\"ni-page-header-title\\"><div>Balance</div></div><div class=\\"ni-page-header-subtitle\\"><div></div></div></div><menu class=\\"ni-page-header-menu\\"><div><div><div class=\\"ni-tool-bar\\"><div class=\\"ni-tool-bar-container\\"><div class=\\"main\\"><a><i class=\\"material-icons\\">refresh</i><div class=\\"label\\">Refresh</div></a><a data-clipboard-text=\\"\\" class=\\"anchor-copy\\"><i class=\\"material-icons\\">content_copy</i><div class=\\"label\\">Copy</div></a><a><i class=\\"material-icons\\">search</i><div class=\\"label\\">Search</div></a></div><a class=\\"help\\"><i class=\\"material-icons\\">help_outline</i></a></div></div></div></div></menu></div></header><main class=\\"ni-page-main\\"><!----><section class=\\"ni-part\\"><div class=\\"ni-part-container\\"><header class=\\"ni-part-header\\"><div class=\\"ni-part-header-container\\"><div class=\\"ni-part-title h5\\">Your Address</div><menu class=\\"ni-part-menu\\"></menu></div></header><main class=\\"ni-part-main\\"><div class=\\"ni-li\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">Address</div><div class=\\"ni-li-dd\\"></div></div></div></div></main></div></section><section class=\\"ni-part\\"><div class=\\"ni-part-container\\"><header class=\\"ni-part-header\\"><div class=\\"ni-part-header-container\\"><div class=\\"ni-part-title h5\\">Denomination Balances</div><menu class=\\"ni-part-menu\\"></menu></div></header><main class=\\"ni-part-main\\"><div class=\\"ni-li\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">456</div><div class=\\"ni-li-dd\\">456</div></div></div></div><div class=\\"ni-li\\"><div class=\\"ni-li-container\\"><div class=\\"ni-li-thumb\\"><!----></div><div class=\\"ni-li-dl\\"><div class=\\"ni-li-dt\\">123</div><div class=\\"ni-li-dd\\">123</div></div></div></div><!----></main></div></section></main><footer class=\\"ni-page-footer\\"><div class=\\"container\\"></div></footer></div>"`;