Skip to content

Commit

Permalink
chooseFilter for pagevalidator. fix website (#3289)
Browse files Browse the repository at this point in the history
* chooseFilter for pagevalidator. fix website

* changelog

* add filter as second parameter

* add test for isblankfield

* lint
  • Loading branch information
Bitcoinera authored and faboweb committed Dec 17, 2019
1 parent c8ab4eb commit cf4d7b7
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 11 deletions.
1 change: 1 addition & 0 deletions changes/ana_add-choosefilter-for-pagevalidator
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Changed] [#3289](https://github.com/cosmos/lunie/pull/3289) Now PageValidator handles empty fields more uniformly, always displaying `--` @Bitcoinera
25 changes: 17 additions & 8 deletions src/components/staking/PageValidator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</li>
<li class="column">
<h4>Website</h4>
<span v-if="validator.website !== ``">
<span v-if="validator.website">
<a
id="validator-website"
:href="validator.website + `?ref=lunie`"
Expand Down Expand Up @@ -114,25 +114,29 @@
</li>
<li>
<h4>Uptime</h4>
<span id="page-profile__uptime">
{{ validator.uptimePercentage | percent }}
</span>
<span id="page-profile__uptime">{{
isBlankField(validator.uptimePercentage, percent)
}}</span>
</li>
<li>
<h4>Current Commission Rate</h4>
<span>{{ validator.commission | percent }}</span>
<span>{{ isBlankField(validator.commission, percent) }}</span>
</li>
<li>
<h4>Max Commission Rate</h4>
<span>{{ validator.maxCommission | percent }}</span>
<span>{{ isBlankField(validator.maxCommission, percent) }}</span>
</li>
<li>
<h4>Max Daily Commission Change</h4>
<span>{{ validator.maxChangeCommission | percent }}</span>
<span>{{
isBlankField(validator.maxChangeCommission, percent)
}}</span>
</li>
<li>
<h4>Last Commission Change</h4>
<span>{{ validator.commissionUpdateTime | fromNow }}</span>
<span>{{
isBlankField(validator.commissionUpdateTime, fromNow)
}}</span>
</li>
</ul>

Expand Down Expand Up @@ -230,6 +234,8 @@ export default {
shortDecimals,
atoms,
percent,
fromNow,
noBlanks,
moment,
onDelegation(options) {
this.$refs.delegationModal.open(options)
Expand All @@ -251,6 +257,9 @@ export default {
`undelegations`,
`transactions`
]) // TODO use more finegrained query string (network and address)
},
isBlankField(field, alternateFilter) {
return field ? alternateFilter(field) : noBlanks(field)
}
},
apollo: {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/specs/components/common/TmSessionHardware.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import TmSessionHardware from "common/TmSessionHardware"
const localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(Vuelidate)
localVue.directive(`tooltip`, () => { })
localVue.directive(`focus`, () => { })
localVue.directive(`tooltip`, () => {})
localVue.directive(`focus`, () => {})

describe(`TmSessionHardware`, () => {
let wrapper, store
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/specs/components/staking/PageValidator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,21 @@ describe(`PageValidator`, () => {
$store.state.session.signedIn = false
expect(wrapper.element).toMatchSnapshot()
})
it(`if uptimePercentage is blank`, () => {
wrapper.setProps({ validator: { uptimePercentage: `` } })
expect(wrapper.element).toMatchSnapshot()
})
})

describe(`isBlankField method`, () => {
it(`returns "--"`, async () => {
validator.maxCommission = null
const percent = jest.fn()
const afterFilter = PageValidator.methods.isBlankField(
validator.maxCommission,
percent
)

expect(afterFilter).toBe(`--`)
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PageValidator if uptimePercentage is blank 1`] = `
<tmpage-stub
class="small"
data-title="Validator"
dataempty="true"
hideheader="true"
managed="true"
subtitle=""
title=""
>
<div>
Validator Not Found
</div>
<div>
Please visit the
<router-link-stub
to="/validators/"
>
Validators
</router-link-stub>
page to view
all validators
</div>
</tmpage-stub>
`;

exports[`PageValidator if user has signed in - status text banned 1`] = `
<tmpage-stub
class="small"
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/specs/filters/filters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ describe(`formatBech32 Filter`, () => {
})

it(`should return an abbreviated version of an Ethereum address, with "0x" and then the first four characters, followed by "..." and finally the last four characters`, () => {
expect(formatBech32(`0x00b1606fc5b771f3079b4fd3ea49e66a2d5fd665`)).toBe(`0x00b1…d665`)
expect(formatBech32(`0x00b1606fc5b771f3079b4fd3ea49e66a2d5fd665`)).toBe(
`0x00b1…d665`
)
})

it(`should return 'Not A Valid Bech32 Address' when no 1 is present`, () => {
Expand Down

0 comments on commit cf4d7b7

Please sign in to comment.