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

Peng/406 fix page bond #414

Merged
merged 8 commits into from
Jan 30, 2018
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.0.0] - 2018-01-15
## [0.3.0] - 2018-01-15
### Added
- Added a changelog @jolesbi.

## [0.3.1] - 2018-01-30
### Changed
* Improved performance of amountBonded in LiDelegate.vue @nylira.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for using the changelog. have to put this in my routine still

* Prevented user from going to PageBond if they don't have any atoms/fermions @nylira.
* Hid the bonding interface on PageDelegates if the user doesn't have any atoms @nylira.
1 change: 0 additions & 1 deletion app/src/renderer/components/common/NiSessionLoading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
.ni-session-title Loading…
.ni-session-main &nbsp
.ni-session-footer  
notifications(:notifications='notifications' theme='cosmos')
</template>

<script>
Expand Down
4 changes: 3 additions & 1 deletion app/src/renderer/components/common/NiSessionSignIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
field#sign-in-name(
type="select"
v-model="fields.signInName"
placeholder="Select account…"
:options="accounts")
form-msg(name='Name' type='required' v-if='!$v.fields.signInName.required')

Expand Down Expand Up @@ -73,10 +74,11 @@ export default {
},
setDefaultAccount () {
let prevAccountKey = localStorage.getItem('prevAccountKey')
let prevAccountExists = this.accounts.find(a => a.key === prevAccountKey)

if (this.accounts.length === 1) {
this.fields.signInName = this.accounts[0].key
} else if (prevAccountKey) {
} else if (prevAccountExists) {
this.fields.signInName = prevAccountKey
}

Expand Down
26 changes: 15 additions & 11 deletions app/src/renderer/components/staking/LiDelegate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
span {{ num.prettyInt(delegate.voting_power) }}
.bar(:style='vpStyles')
.li-delegate__value.bonded_by_you
span {{ num.prettyInt(amountBonded(delegate.id)) }}
.li-delegate__value.checkbox#remove-from-cart(v-if="inCart" @click='rm(delegate)')
i.material-icons check_box
.li-delegate__value.checkbox#add-to-cart(v-else @click='add(delegate)')
i.material-icons check_box_outline_blank
span {{ amountBonded }}
template(v-if="userCanDelegate")
.li-delegate__value.checkbox#remove-from-cart(v-if="inCart" @click='rm(delegate)')
i.material-icons check_box
.li-delegate__value.checkbox#add-to-cart(v-else @click='add(delegate)')
i.material-icons check_box_outline_blank
template(v-else)
.li-delegate__value
</template>

<script>
Expand All @@ -29,7 +32,10 @@ export default {
Btn
},
computed: {
...mapGetters(['shoppingCart', 'delegates', 'config', 'committedDelegations']),
...mapGetters(['shoppingCart', 'delegates', 'config', 'committedDelegations', 'user']),
amountBonded () {
return this.num.prettyInt(this.committedDelegations[this.delegate.id])
},
styles () {
let value = ''
if (this.inCart) value += 'li-delegate-active '
Expand Down Expand Up @@ -57,17 +63,15 @@ export default {
},
inCart () {
return this.shoppingCart.find(c => c.id === this.delegate.id)
}
},
userCanDelegate () { return this.user.atoms > 0 }
},
data: () => ({
num: num
}),
methods: {
add (delegate) { this.$store.commit('addToCart', delegate) },
rm (delegate) { this.$store.commit('removeFromCart', delegate.id) },
amountBonded (delegateId) {
return this.committedDelegations[delegateId]
}
rm (delegate) { this.$store.commit('removeFromCart', delegate.id) }
}
}
</script>
Expand Down
10 changes: 10 additions & 0 deletions app/src/renderer/components/staking/PageBond.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ export default {
return d
})
},
leaveIfBroke (count) {
if (count === 0) {
this.$store.commit('notifyError', {
title: 'Cannot Bond Without Atoms',
body: 'You do not have any atoms to bond to delegates.'
})
this.$router.push('/staking')
}
},
leaveIfEmpty (count) {
if (count === 0) {
this.$store.commit('notifyError', {
Expand Down Expand Up @@ -323,6 +332,7 @@ export default {
}
},
async mounted () {
this.leaveIfBroke(this.user.atoms)
this.leaveIfEmpty(this.shoppingCart.length)
this.resetFields()
this.bondBarsInput()
Expand Down
11 changes: 8 additions & 3 deletions app/src/renderer/components/staking/PageDelegates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ page#page-delegates(title='Delegates')
li-delegate(v-for='i in filteredDelegates' :key='i.id' :delegate='i')

.fixed-button-bar
.label #[strong {{ shoppingCart.length }}] delegates selected
btn.btn__primary(type="link" to="/staking/bond" :disabled="shoppingCart.length < 1" icon="chevron_right" icon-pos="right" value="Next")
template(v-if="userCanDelegate")
.label #[strong {{ shoppingCart.length }}] delegates selected
btn.btn__primary(type="link" to="/staking/bond" :disabled="shoppingCart.length < 1" icon="chevron_right" icon-pos="right" value="Next")
template(v-else)
.label You do not have any ATOMs to delegate.
btn.btn__primary(disabled icon="chevron_right" icon-pos="right" value="Next")
</template>

<script>
Expand Down Expand Up @@ -61,7 +65,8 @@ export default {
} else {
return list
}
}
},
userCanDelegate () { return this.user.atoms > 0 }
},
data: () => ({
query: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ exports[`NiSessionLoading has the expected html structure 1`] = `
<div class=\\"ni-session-footer\\">
&nbsp;
</div>
<notifications theme=\\"cosmos\\"></notifications>
</div>
</div>"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports[`NiSessionSignIn has the expected html structure 1`] = `
<div class=\\"ni-select\\" id=\\"sign-in-name\\">
<select class=\\"ni-field ni-field-select\\">
<option value=\\"\\" disabled=\\"disabled\\" selected=\\"selected\\" hidden=\\"hidden\\">
Select option...
Select account…
</option>
<!---->
<!---->
Expand Down
4 changes: 3 additions & 1 deletion test/unit/specs/components/staking/LiDelegate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('LiDelegate', () => {
wrapper = test.wrapper
store = test.store

store.commit('setAtoms', 1337)
store.commit('addDelegate', {
pub_key: {
type: 'ed25519',
Expand Down Expand Up @@ -62,7 +63,8 @@ describe('LiDelegate', () => {
})

it('should show the relative voting power as a bar', () => {
expect(wrapper.vm.$el.querySelector('.number_of_votes .bar').style.width).toBe('33%')
expect(wrapper.vm.$el.querySelector('.number_of_votes .bar')
.style.width).toBe('33%')
})

it('should add to cart', () => {
Expand Down
1 change: 1 addition & 0 deletions test/unit/specs/components/staking/PageDelegates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('PageDelegates', () => {
store = instance.store

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