Skip to content

Commit

Permalink
Merge pull request #2322 from cosmos/fabo/2303-balance-display-as-whole
Browse files Browse the repository at this point in the history
Fabo/2303 balance display as whole
  • Loading branch information
faboweb committed Mar 20, 2019
2 parents db62981 + a86120c commit db3c32d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Changed

- [\#2303](https://github.com/cosmos/voyager/issues/2303) Hide amounts in header until they are fully loaded @faboweb

### Security

- [\#2309](https://github.com/cosmos/voyager/pull/2309) remove markdown parser to reduce vulnerability of xss @faboweb
Expand Down
17 changes: 15 additions & 2 deletions app/src/renderer/components/common/TmBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="total-atoms top-section">
<h3>Total {{ bondDenom }}</h3>
<h2 class="total-atoms__value">
{{ num.shortNumber(num.atoms(totalAtoms)) }}
{{ totalAtomsDisplay }}
</h2>
<short-bech32 :address="session.address || ''" />
</div>
Expand Down Expand Up @@ -52,16 +52,29 @@ export default {
...mapGetters([
`connected`,
`session`,
`wallet`,
`delegation`,
`liquidAtoms`,
`lastHeader`,
`totalAtoms`,
`bondDenom`,
`distribution`
]),
loaded() {
return this.wallet.loaded && this.delegation.loaded
},
totalAtomsDisplay() {
return this.loaded ? num.shortNumber(num.atoms(this.totalAtoms)) : `--`
},
unbondedAtoms() {
return this.num.shortNumber(this.num.atoms(this.liquidAtoms))
return this.loaded
? this.num.shortNumber(this.num.atoms(this.liquidAtoms))
: `--`
},
rewards() {
if (!this.distribution.loaded) {
return `--`
}
const rewards = this.distribution.totalRewards[this.bondDenom]
return this.num.shortNumber(
this.num.atoms(rewards && rewards > 10 ? rewards : 0)
Expand Down
20 changes: 20 additions & 0 deletions test/unit/specs/components/common/TmBalance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ describe(`TmBalance`, () => {
totalAtoms: 3210000000,
bondDenom: `stake`,
distribution: {
loaded: true,
totalRewards: {
stake: 1000450000000
}
},
delegation: {
loaded: true
},
wallet: {
loaded: true
},
lastHeader: { height: `10` }
},
dispatch: jest.fn()
Expand All @@ -39,6 +46,19 @@ describe(`TmBalance`, () => {
it(`displays unbonded tokens`, () => {
expect(wrapper.vm.unbondedAtoms).toBe(`1,230.0000…`)
})

it(`displays neither total tokens nor unbonded tokens if not completely loaded`, () => {
wrapper.vm.wallet.loaded = false
wrapper.vm.distribution.loaded = false
expect(wrapper.vm.totalAtomsDisplay).toBe(`--`)
expect(wrapper.vm.unbondedAtoms).toBe(`--`)
})

it(`should not display rewards if not loaded`, () => {
wrapper.vm.distribution.loaded = false
expect(wrapper.vm.rewards).toBe(`--`)
})

it(`gets user rewards`, () => {
expect(wrapper.vm.rewards).toBe(`1,000,450.0000…`)
})
Expand Down

0 comments on commit db3c32d

Please sign in to comment.