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/2202+2204 fix number #2205

Merged
merged 12 commits into from
Mar 7, 2019
6 changes: 5 additions & 1 deletion PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
### Added

- [\#2104](https://github.com/cosmos/voyager/issues/2104) fix transaction times @fedekunze
- [\#1805](https://github.com/cosmos/voyager/issues/1805) support all transaction types @fedekunze

### Changed

- [#\2202](https://github.com/cosmos/voyager/pull/2202) Fix circle configuration for publishing @sabau
- [\#1805](https://github.com/cosmos/voyager/issues/1805) support all transaction types @fedekunze

### Fixed

- [#\2202](https://github.com/cosmos/voyager/issues/2202) Fix number conversions @faboweb
2 changes: 1 addition & 1 deletion PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Thank you! 🚀

For contributor:

- [ ] Added entries in `CHANGELOG.md` with issue # and GitHub username
- [ ] Added entries in `PENDING.md` with issue # and GitHub username
- [ ] Reviewed `Files changed` in the github PR explorer
- [ ] Attach screenshots of the UI components on the PR description (if applicable)
- [ ] Scope of work approved for big PRs
Expand Down
10 changes: 6 additions & 4 deletions app/src/renderer/components/governance/PageProposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,18 @@ export default {
.toNumber()
},
yesPercentage({ tally, totalVotes } = this) {
return num.percentInt(tally.yes / totalVotes)
return num.percentInt(totalVotes === 0 ? 0 : tally.yes / totalVotes)
},
noPercentage({ tally, totalVotes } = this) {
return num.percentInt(tally.no / totalVotes)
return num.percentInt(totalVotes === 0 ? 0 : tally.no / totalVotes)
},
noWithVetoPercentage({ tally, totalVotes } = this) {
return num.percentInt(tally.no_with_veto / totalVotes)
return num.percentInt(
totalVotes === 0 ? 0 : tally.no_with_veto / totalVotes
)
},
abstainPercentage({ tally, totalVotes } = this) {
return num.percentInt(tally.abstain / totalVotes)
return num.percentInt(totalVotes === 0 ? 0 : tally.abstain / totalVotes)
},
tally({ proposals, proposalId } = this) {
const { yes, no, abstain, no_with_veto } =
Expand Down
13 changes: 7 additions & 6 deletions app/src/renderer/components/staking/LiValidator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ export default {
const info = this.validator.signing_info
if (info) {
// uptime in the past 10k blocks
const uptimeRollingWindow = info.signed_blocks_counter / rollingWindow
return `${this.num.pretty(uptimeRollingWindow * 100)}%`
const uptimeRollingWindow =
(rollingWindow - info.missed_blocks_counter) / rollingWindow
return num.percent(uptimeRollingWindow)
}
return `--`
},
Expand Down Expand Up @@ -163,15 +164,15 @@ export default {
const validatorRewards = this.distribution.rewards[
this.validator.operator_address
]
return validatorRewards ? num.shortNumber(
num.atoms(validatorRewards[this.bondDenom]) || 0
) : null
return validatorRewards
? num.shortNumber(num.atoms(validatorRewards[this.bondDenom]) || 0)
: null
}
},
watch: {
lastHeader: {
immediate: true,
handler(){
handler() {
if (this.yourVotes > 0) {
this.$store.dispatch(
`getRewardsFromValidator`,
Expand Down
21 changes: 8 additions & 13 deletions app/src/renderer/components/transactions/LiBankTransaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@
>
<template v-if="sent">
<div slot="caption">
Sent&nbsp;<b>{{ atoms(coins.amount) }}</b><span>&nbsp;{{ coins.denom.toUpperCase() }}</span>
Sent&nbsp;<b>{{ full(atoms(coins.amount)) }}</b><span>&nbsp;{{ coins.denom.toUpperCase() }}</span>
</div>
<span
slot="details"
>
<template
v-if="sentSelf"
>
<span slot="details">
<template v-if="sentSelf">
To yourself!
</template><template
v-else
>
</template><template v-else>
To {{ receiver }}
</template>
</span>
</template><template v-else>
<div slot="caption">
Received&nbsp;<b>{{ atoms(coins.amount) }}</b><span>&nbsp;{{ coins.denom.toUpperCase() }}</span>
Received&nbsp;<b>{{ full(atoms(coins.amount)) }}</b><span>&nbsp;{{ coins.denom.toUpperCase() }}</span>
</div>
<span slot="details">From {{ sender }}</span>
</template>
Expand All @@ -32,7 +26,7 @@

<script>
import LiTransaction from "./LiTransaction"
import { atoms } from "../../scripts/num.js"
import { atoms, full } from "../../scripts/num.js"

export default {
name: `li-bank-transaction`,
Expand All @@ -48,7 +42,8 @@ export default {
}
},
data: () => ({
atoms
atoms,
full
}),
computed: {
tx() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
>
<template v-if="txType === `cosmos-sdk/MsgSubmitProposal`">
<div slot="caption">
Submit {{ tx.proposal_type.toLowerCase() }} proposal&nbsp;<b>{{ atoms(tx.initial_deposit[0].amount) }}</b><span>&nbsp;{{ tx.initial_deposit[0].denom }}s</span>
Submit {{ tx.proposal_type.toLowerCase() }} proposal&nbsp;<b>{{ full(atoms(tx.initial_deposit[0].amount)) }}</b><span>&nbsp;{{ tx.initial_deposit[0].denom }}s</span>
</div>
<div slot="details">
Title:&nbsp;<i>{{ tx.title }}</i>
Expand All @@ -16,7 +16,7 @@
<div slot="caption">
Deposit&nbsp;
<template>
<b>{{ pretty(atoms(tx.amount[0].amount)) }}</b>
<b>{{ full(atoms(tx.amount[0].amount)) }}</b>
<span>&nbsp;{{ tx.amount[0].denom }}s</span>
</template>
</div>
Expand All @@ -43,7 +43,7 @@

<script>
import LiTransaction from "./LiTransaction"
import { pretty, atoms } from "../../scripts/num.js"
import { full, atoms } from "../../scripts/num.js"

export default {
name: `li-gov-transaction`,
Expand All @@ -67,7 +67,7 @@ export default {
}
},
data: () => ({
pretty,
full,
atoms
}),
computed: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<template v-if="txType === `cosmos-sdk/MsgCreateValidator`">
<div slot="caption">
Create validator&nbsp;
<b>{{ atoms(tx.value.amount) }}</b>
<b>{{ full(atoms(tx.value.amount)) }}</b>
<span>&nbsp;{{ tx.value.denom }}s</span>
</div>
<div slot="details">
Expand All @@ -32,7 +32,7 @@
<template v-else-if="txType === `cosmos-sdk/MsgDelegate`">
<div slot="caption">
Delegation&nbsp;
<b>{{ atoms(tx.value.amount) }}</b>
<b>{{ full(atoms(tx.value.amount)) }}</b>
<span>&nbsp;{{ tx.value.denom }}s</span>
</div>
<div slot="details">
Expand Down Expand Up @@ -108,7 +108,7 @@

<script>
import LiTransaction from "./LiTransaction"
import { pretty, atoms } from "../../scripts/num.js"
import { atoms, full } from "../../scripts/num.js"
import { calculateTokens } from "../../scripts/common.js"
import moment from "moment"

Expand Down Expand Up @@ -147,7 +147,7 @@ export default {
},
data: () => ({
atoms,
pretty
full
}),
computed: {
tx() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/renderer/connectors/lcdClientMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ const state = {
start_height: 2,
index_offset: 1,
jailed_until: new Date(Date.now()).toISOString(),
signed_blocks_counter: 1
missed_blocks_counter: 1
},
proposals: {
1: {
Expand Down
62 changes: 17 additions & 45 deletions app/src/renderer/scripts/num.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,39 @@ import BigNumber from "bignumber.js"
* @module num
*/

const numeral = require(`numeral`)
function usd(num) {
return numeral(num).format(`$0,0.00`)
const language = window.navigator.userLanguage || window.navigator.language
function full(number = 0) {
return new Intl.NumberFormat(language, { minimumFractionDigits: 7 }).format(number)
}
function usdInt(num) {
return numeral(num).format(`$0,0`)
function shortNumber(number = 0) {
return new Intl.NumberFormat(language, { minimumFractionDigits: 4 }).format(number) + `…`
}
function full(num) {
return numeral(num).format(`0,0.0000000000`)
function pretty(number = 0) {
return new Intl.NumberFormat(language, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(Math.round(number * 100) / 100)
}
function shortNumber(num) {
return numeral(num).format(`0,0.0000`) + `…`
function prettyInt(number = 0) {
return new Intl.NumberFormat(language).format(Math.round(number))
}
function pretty(num) {
return numeral(num).format(`0,0.00`)
function percentInt(number = 0) {
return new Intl.NumberFormat(language).format(Math.round(number * 100)) + `%`
}
function prettyInt(num) {
return numeral(num).format(`0,0`)
function percent(number = 0) {
return new Intl.NumberFormat(language, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(Math.round(number * 10000) / 100) + `%`
}
function short(num) {
if (num >= 1000000000) {
return pretty(num / 1000000000) + `B`
}
if (num >= 1000000) {
return pretty(num / 1000000) + `M`
}
if (num >= 1000) {
return pretty(num / 1000) + `K`
}
return numeral(num).format(`0.00`)
function atoms(number = 0) {
return BigNumber(number).div(10e6).toNumber()
}
function shortInt(num) {
if (num > 1000) {
return short(num)
}
return prettyInt(num)
}
function percentInt(x) {
return numeral(x).format(`0%`)
}
function percent(x) {
return numeral(x).format(`0.00%`)
}
function atoms(x) {
return BigNumber(x).div(10e6).toNumber()
}
function uatoms(x) {
return BigNumber(x).times(10e6).toNumber()
function uatoms(number = 0) {
return BigNumber(number).times(10e6).toFixed(7)
}

module.exports = {
atoms,
uatoms,
usd,
usdInt,
full,
shortNumber,
pretty,
prettyInt,
short,
shortInt,
percent,
percentInt
}
2 changes: 1 addition & 1 deletion tasks/changelog-changed-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [ "$currentBranch" = "master" ] || [ "$currentBranch" = "release" ] || [ "$cu
echo "This branch is the develop branch. Checks on updating the changelog are omitted."
exit 0;
fi
if [ "$(git diff --name-only origin/develop | grep -c CHANGELOG.md)" -ge 1 ]; then
if [ "$(git diff --name-only origin/develop | grep -c PENDING.md)" -ge 1 ]; then
echo "CHANGELOG updated"
exit 0;
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe(`ModalDeposit`, () => {
{
amount: [
{
amount: `100000000`,
amount: `100000000.0000000`,
denom: `stake`
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe(`ModalPropose`, () => {
`submitProposal`,
{
description: `a valid description for the proposal`,
initial_deposit: [{ amount: `150000000`, denom: `stake` }],
initial_deposit: [{ amount: `150000000.0000000`, denom: `stake` }],
title: `A new text proposal for Cosmos`,
type: `Text`,
password: `1234567890`,
Expand Down
4 changes: 2 additions & 2 deletions test/unit/specs/components/staking/DelegationModal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe(`DelegationModal`, () => {

expect($store.dispatch).toHaveBeenCalledWith(`submitDelegation`,
{
amount: `500000000`,
amount: `500000000.0000000`,
validator_addr: validator.operator_address,
password: `1234567890`,
submitType: `local`
Expand Down Expand Up @@ -189,7 +189,7 @@ describe(`DelegationModal`, () => {

expect($store.dispatch).toHaveBeenCalledWith(`submitRedelegation`,
{
amount: `500000000`,
amount: `500000000.0000000`,
validatorSrc: delegates.delegates[0],
validatorDst: validator,
password: `1234567890`,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/specs/components/staking/LiValidator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe(`LiValidator`, () => {
start_height: 0,
index_offset: 465400,
jailed_until: `1970-01-01T00:00:00Z`,
signed_blocks_counter: 9878
missed_blocks_counter: 122
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/unit/specs/components/staking/PageValidator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe(`PageValidator`, () => {
const delegationString = PageValidator.computed.myDelegation.call(
{ bondDenom, myBond }
)
expect(delegationString).toBe(`10.0000000000 stake`)
expect(delegationString).toBe(`10.0000000 stake`)
})

it(`when user doesn't have any delegations`, () => {
Expand Down Expand Up @@ -232,7 +232,7 @@ describe(`PageValidator`, () => {
const rewardsString = PageValidator.computed.rewards.call(
{ session, bondDenom, distribution, validator }
)
expect(rewardsString).toBe(`10.0000000000 stake`)
expect(rewardsString).toBe(`10.0000000 stake`)
})

it(`when validator rewards are 0`, () => {
Expand All @@ -246,7 +246,7 @@ describe(`PageValidator`, () => {
const rewardsString = PageValidator.computed.rewards.call(
{ session, bondDenom, distribution, validator }
)
expect(rewardsString).toBe(`0.0000000000 stake`)
expect(rewardsString).toBe(`0.0000000 stake`)
})

it(`when user doesn't have any delegations`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ exports[`PageValidator shows a validator profile information errors signing info
</dt>

<dd>
0.0000000000 STAKE
0.0000000 STAKE
</dd>
</dl>
</div>
Expand Down Expand Up @@ -412,7 +412,7 @@ exports[`PageValidator shows a validator profile information if user has signed
</dt>

<dd>
0.0000000000 STAKE
0.0000000 STAKE
</dd>
</dl>
</div>
Expand Down
Loading