Skip to content

Commit

Permalink
Merge pull request #271 from cosmos/fabo/209-candidate-profiles
Browse files Browse the repository at this point in the history
Fabo/209 candidate profiles
  • Loading branch information
nylira authored Dec 28, 2017
2 parents 0db8736 + 171a439 commit e28bcfb
Show file tree
Hide file tree
Showing 4 changed files with 516 additions and 26 deletions.
53 changes: 27 additions & 26 deletions app/src/renderer/components/staking/PageDelegate.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
<template lang="pug">
page(icon="storage" :title="delegate.keybaseID")
page(icon="storage" :title="delegate.description.moniker")
div(slot="menu"): tool-bar
router-link(to="/staking" exact)
i.material-icons arrow_back
.label Back
template(v-if='isDelegator')
a(v-if='inCart' @click.native='rm(delegate.id)')
i.material-icons delete
.label Remove
a(v-else @click.native='add(delegate.id)')
i.material-icons add
.label Add
a(v-if='inCart' @click.native='rm(delegate.id)')
i.material-icons delete
.label Remove
a(v-else-if="config.devMode" @click.native='add(delegate)')
i.material-icons add
.label Add

part(title="Delegate Description")
text-block(:content="delegate.description")
part(title="Delegate Description" v-if="delegate.description.website")
text-block( :content="delegate.description.details")
part(title="Delegate Details")
list-item(dt='Public Key' :dd='delegate.id')
list-item(dt='Country' :dd='delegate.country')
list-item(dt='Start Date' :dd='delegate.startDate')
part(title="Delegate Stake")
list-item(dt='Country' :dd='country')
list-item(dt='Start Date' :dd='delegate.startDate || "n/a"')
part(title="Delegate Stake" v-if="config.devMode")
list-item(dt='Voting Power' :dd='delegate.voting_power + " ATOM"')
list-item(dt='Shares' :dd='delegate.shares + " ATOM"')
list-item(dt='Bonded Atoms' :dd='delegate.shares + " ATOM"')
list-item(dt='Commission'
:dd='(delegate.commission * 100).toFixed(2) + "%"')
list-item(dt='Max Commission'
Expand All @@ -29,7 +28,7 @@ page(icon="storage" :title="delegate.keybaseID")
:dd='(delegate.commissionMaxRate * 100).toFixed(2) + "%"')

part(title="External")
list-item(dt="Website" :dd="delegate.url" :href="delegate.url")
list-item(dt="Website" :dd="delegate.description.website" :href="delegate.description.website")
</template>

<script>
Expand All @@ -52,35 +51,37 @@ export default {
ToolBar
},
computed: {
...mapGetters(['delegates', 'countries', 'shoppingCart', 'user']),
...mapGetters(['delegates', 'shoppingCart', 'user', 'config']),
delegate () {
let value = {}
if (this.delegates) {
let value = {
description: {}
}
if (this.delegates && this.$route.params.delegate) {
value = this.delegates.find(v => v.id === this.$route.params.delegate)
}
return value
},
inCart () {
return this.shoppingCart.find(c => c.delegateId === this.delegate.id)
return this.shoppingCart.find(c => c.id === this.delegate.id) !== undefined
},
isDelegator () { return this.user.signedIn && !this.user.nominationActive },
isMe () {
return this.user.nominationActive && this.user.nomination.id === this.delegate.id
country () {
return this.delegate.country ? this.countryName(this.delegate.country) : 'n/a'
}
},
methods: {
countryName (code) {
return countries.find(c => c.value === code).key
let country = countries.find(c => c.value === code)
return country ? country.key : code
},
add (delegateId) {
this.$store.commit('addToCart', delegateId)
add (delegate) {
this.$store.commit('addToCart', delegate)
},
rm (delegateId) {
this.$store.commit('removeFromCart', delegateId)
}
},
mounted () {
if (!this.delegate) { this.$router.push('/staking') }
if (!this.delegate.id) { this.$router.push('/staking') }
}
}
</script>
45 changes: 45 additions & 0 deletions test/unit/specs/PageDelegate.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import setup from '../helpers/vuex-setup'
import PageDelegate from 'renderer/components/staking/PageDelegate'

describe('PageDelegate', () => {
let wrapper, store, router
let {mount} = setup()

beforeEach(() => {
let instance = mount(PageDelegate)
wrapper = instance.wrapper
store = instance.store
router = instance.router

store.commit('addDelegate', {
pub_key: {
type: 'ed25519',
data: 'pubkeyX'
},
voting_power: 10000,
shares: 5000,
description: {
description: 'descriptionX',
moniker: 'monikerX',
country: 'US'
}
})
router.push('/staking/delegates/pubkeyX')
})

it('has the expected html structure', () => {
expect(wrapper.vm.$el).toMatchSnapshot()
})

it('should add/remove candidate to cart', () => {
expect(wrapper.vm.inCart).toBe(false)
wrapper.vm.add(wrapper.vm.delegate)
expect(wrapper.vm.inCart).toBe(true)
wrapper.vm.rm('pubkeyX')
expect(wrapper.vm.inCart).toBe(false)
})

it('should show the correct country name', () => {
expect(wrapper.html()).toContain('United States')
})
})
1 change: 1 addition & 0 deletions test/unit/specs/PageDelegates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('PageDelegates', () => {
wrapper = instance.wrapper
store = instance.store

store.state.user.address = 'abc'
store.commit('addDelegate', {
pub_key: {
type: 'ed25519',
Expand Down
Loading

0 comments on commit e28bcfb

Please sign in to comment.