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

Added undelegation transactions to TabMyDelegation #1743

Merged
merged 19 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from 18 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added compatibility to Gaia/SDK version 0.28.0-rc2 @faboweb
- [\#1673](https://github.com/cosmos/voyager/issues/1673) Documentation and single command to run one or all tests with fallback for end to end test @sabau
- [\#1683](https://github.com/cosmos/voyager/issues/1683) Governance: block voting twice for the same option @sabau
- [\#1387](https://github.com/cosmos/voyager/issues/1387) Staking: Added list of undelegation transactions @sabau
- [\#1661](https://github.com/cosmos/voyager/issues/1661) Boot: multinode available for local-testnet @sabau
- [\#1748](https://github.com/cosmos/voyager/issues/1748) display governance parameters on tab @fedekunze
- [\#1660](https://github.com/cosmos/voyager/issues/1660) Add parameters and pool to store @fedekunze
Expand Down Expand Up @@ -85,6 +86,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [\#1638](https://github.com/cosmos/voyager/issues/1638) removed account password from the state and now user has to input it on every transaction @fedekunze
- [\#1655](https://github.com/cosmos/voyager/issues/1655) Text and Textarea fields trimmed @sabau
- [\#1686](https://github.com/cosmos/voyager/issues/1686) Changed proposals from array to object @sabau
- [\#1387](https://github.com/cosmos/voyager/issues/1387) Delegation: modifiers simplified, setUnbondingDelegations takes an array as input now as the name suggest and replace the current dictionary with a new one @sabau
- [\#1626](https://github.com/cosmos/voyager/issues/1626) upgraded from raven to sentry/browser @jbibla
- [\#1724](https://github.com/cosmos/voyager/issues/1724) set tabindex attribute to -1 for readonly denom on ModalProposals. tab navgiation now skips element @enyan94
- [\#1277](https://github.com/cosmos/voyager/issues/1277) change name of VmToolBar to ToolBar, update all snapshots and import statements @coreycosman
Expand Down
6 changes: 3 additions & 3 deletions app/src/renderer/components/staking/PageValidator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@
/>
<tm-modal v-if="showCannotModal" :close="closeCannotModal">
<div slot="title">
Cannot {{ action == `delegate` ? `Delegate` : `Undelegate` }}
Cannot {{ action === `delegate` ? `Delegate` : `Undelegate` }}
</div>
<p>
You have no {{ bondingDenom }}s
{{ action == `undelegate` ? ` delegated ` : ` ` }}to
{{ action == `delegate` ? ` delegate.` : ` this validator.` }}
{{ action === `undelegate` ? ` delegated ` : ` ` }}to
{{ action === `delegate` ? ` delegate.` : ` this validator.` }}
</p>
<div slot="footer">
<tmBtn
Expand Down
91 changes: 74 additions & 17 deletions app/src/renderer/components/staking/TabMyDelegations.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<template>
<div>
<div v-if="delegation.loaded && yourValidators.length > 0">
<h3 class="tab-header">
My active validators
<i v-tooltip.top="unbondInfo" class="material-icons info-button">
info_outline
</i>
</h3>
<table-validators :validators="yourValidators" />
</div>
<tm-data-connecting v-if="!delegation.loaded && !connected" />
Expand All @@ -22,52 +28,85 @@
<router-link :to="{ name: 'Validators' }">the validator list</router-link>
to find other validators to delegate to.
</div>
<div v-if="delegation.loaded && undelegatedValidators.length > 0">
<h3 class="tab-header">
Inactive Delegations
<i v-tooltip.top="unbondInfo" class="material-icons info-button"
>info_outline</i
<div v-if="delegation.loaded && unbondingTransactions.length > 0">
<h3 class="tab-header transactions">
Unbonding transactions
<i
v-tooltip.top="unbondTransactions"
class="material-icons info-button"
>
info_outline
</i>
</h3>
<table-validators :validators="undelegatedValidators" />
<div class="transactions">
<template v-for="transaction in unbondingTransactions">
<tm-li-stake-transaction
:transaction="transaction"
:validators="yourValidators"
:bonding-denom="bondingDenom"
:key="transaction.hash"
:url="validatorURL"
/>
</template>
</div>
</div>
</div>
</template>

<script>
import { mapGetters } from "vuex"
import TmLiStakeTransaction from "../transactions/TmLiStakeTransaction"
import TmDataMsg from "common/TmDataMsg"
import TmDataLoading from "common/TmDataLoading"
import TableValidators from "staking/TableValidators"
import TmDataConnecting from "common/TmDataConnecting"
import moment from "moment"

export default {
name: `tab-my-delegations`,
components: { TableValidators, TmDataMsg, TmDataConnecting, TmDataLoading },
components: {
TableValidators,
TmDataMsg,
TmDataConnecting,
TmDataLoading,
TmLiStakeTransaction
},
data: () => ({
bondInfo: `Validators you are currently bonded to`,
unbondInfo: `Your bonded validators in unbonding process`
unbondInfo: `Your bonded validators in unbonding process`,
unbondTransactions: `The transactions currently in unbonding period`,
validatorURL: `/staking/validators`
}),
computed: {
...mapGetters([
`allTransactions`,
`delegates`,
`delegation`,
`committedDelegations`,
`bondingDenom`,
`connected`
]),
undelegatedValidators(
{ delegates: { delegates }, delegation: { unbondingDelegations } } = this
) {
return delegates.filter(
({ operator_address }) => operator_address in unbondingDelegations
)
},
yourValidators({ committedDelegations, delegates: { delegates } } = this) {
return delegates.filter(
({ operator_address }) => operator_address in committedDelegations
)
}
},
unbondingTransactions: ({ allTransactions, delegation } = this) =>
allTransactions
faboweb marked this conversation as resolved.
Show resolved Hide resolved
.filter(
transaction =>
transaction.tx.value.msg[0].type === `cosmos-sdk/BeginUnbonding`
)
.map(transaction => ({
...transaction,
unbondingDelegation:
delegation.unbondingDelegations[
transaction.tx.value.msg[0].value.validator_addr
]
}))
},
methods: {
timeDiff: min_time => moment(min_time).fromNow()
}
}
</script>
Expand All @@ -78,6 +117,9 @@ export default {
font-weight: 500;
margin: 1rem 1rem 0 2rem;
}
.tab-header.transactions {
margin: 2rem 0 1rem 2rem;
}

.info-button {
color: var(--link);
Expand All @@ -88,9 +130,24 @@ export default {
border: 1px solid var(--bc-dim);
border-radius: 0.25rem;
font-size: var(--sm);
margin-bottom: 4rem;
margin-left: 2rem;
padding: 0.5rem;
text-align: center;
}

.transactions {
margin-left: 2rem;
counter-reset: transaction;
}
.transactions .tm-li-tx {
counter-increment: transaction;
}
.tm-li-tx::before {
content: counter(transaction);
position: absolute;
width: 2rem;
text-align: right;
color: var(--dim);
left: 0;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
s<template>
<template>
<tm-li-bank-transaction
v-if="bankTx"
:transaction="transaction"
:address="address"
></tm-li-bank-transaction>
/>
<tm-li-stake-transaction
v-else-if="stakingTx"
:transaction="transaction"
Expand All @@ -12,20 +12,21 @@ s<template>
:unbonding-time="unbondingTime"
:bonding-denom="bondingDenom"
@end-unbonding="$emit('end-unbonding')"
></tm-li-stake-transaction>
/>
<tm-li-gov-transaction
v-else-if="governanceTx"
:transaction="transaction"
:bonding-denom="bondingDenom"
:url="proposalsUrl"
></tm-li-gov-transaction>
/>
<tm-li-transaction
v-else
:color="colors.grey"
:time="transaction.time"
:block="transaction.height"
><span slot="caption">Unknown Transaction Type</span></tm-li-transaction
>
<span slot="caption">Unknown Transaction Type</span>
</tm-li-transaction>
</template>

<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</div>
<div slot="details">
On&nbsp;
<router-link :to="URL + '/' + tx.proposal_id">
<router-link :to="url + '/' + tx.proposal_id">
Proposal &#35;{{ tx.proposal_id }}
</router-link>
</div>
Expand All @@ -45,7 +45,7 @@ export default {
type: Object,
required: true
},
URL: {
url: {
type: String,
required: true
},
Expand Down
61 changes: 21 additions & 40 deletions app/src/renderer/vuex/modules/delegation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Sentry from "@sentry/browser"
import { calculateShares } from "scripts/common"
import Vue from "vue"

export default ({ node }) => {
let emptyState = {
Expand Down Expand Up @@ -33,32 +34,29 @@ export default ({ node }) => {
state.delegates = state.delegates.filter(c => c.id !== delegate)
},
setCommittedDelegation(state, { candidateId, value }) {
let committedDelegates = Object.assign({}, state.committedDelegates)
Vue.set(state.committedDelegates, candidateId, value)
if (value === 0) {
delete committedDelegates[candidateId]
} else {
committedDelegates[candidateId] = value
delete state.committedDelegates[candidateId]
Vue.set(state, `committedDelegates`, state.committedDelegates)
}
state.committedDelegates = committedDelegates
},
setUnbondingDelegations(
state,
{ validator_addr, min_time, balance, creation_height }
) {
let unbondingDelegations = Object.assign({}, state.unbondingDelegations)
if (balance.amount === 0) {
delete unbondingDelegations[validator_addr]
} else {
unbondingDelegations[validator_addr] = {
min_time,
balance,
creation_height
}
}
setUnbondingDelegations(state, unbondingDelegations) {
state.unbondingDelegations = unbondingDelegations
? unbondingDelegations
// building a dict from the array and taking out the transactions with amount 0
.reduce(
(dict, { validator_addr, ...delegation }) => ({
...dict,
// filtering out the transactions with amount 0
...(delegation.balance.amount > 0 && {
[validator_addr]: delegation
})
}),
{}
)
: {}
}
}

let actions = {
reconnected({ state, dispatch }) {
if (state.loading) {
Expand All @@ -82,11 +80,11 @@ export default ({ node }) => {

try {
let delegations = await node.getDelegations(address)
let unbonding_delegations = await node.getUndelegations(address)
let unbondingDelegations = await node.getUndelegations(address)
let redelegations = await node.getRedelegations(address)
let delegator = {
delegations,
unbonding_delegations,
unbondingDelegations,
redelegations
}
state.error = null
Expand Down Expand Up @@ -126,24 +124,7 @@ export default ({ node }) => {
})
})

if (delegator.unbonding_delegations) {
delegator.unbonding_delegations.forEach(ubd => {
commit(`setUnbondingDelegations`, ubd)
})
}
// delete undelegations not present anymore
Object.keys(state.unbondingDelegations).forEach(validatorAddr => {
if (
!delegator.unbonding_delegations ||
!delegator.unbonding_delegations.find(
({ validator_addr }) => validator_addr === validatorAddr
)
)
commit(`setUnbondingDelegations`, {
validator_addr: validatorAddr,
balance: { amount: 0 }
})
})
commit(`setUnbondingDelegations`, unbondingDelegations)
} catch (error) {
commit(`notifyError`, {
title: `Error fetching delegations`,
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/delegation.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ test(`delegation`, async function(t) {
.$(`.header-balance .unbonded-atoms h2`)
.getText()).split(`.`)[0] // 30.000...

await t.equal(totalAtoms, `130`, `i have 130 Atoms`)
await t.equal(unbondedAtoms, `30`, `i have 30 unbounded Atoms`)
// Select the second validator.
await app.client.click(`//*[. = 'local_2']`)

Expand Down Expand Up @@ -97,13 +99,13 @@ test(`delegation`, async function(t) {
console.log(`Testing total balance`)
await waitForText(
() => app.client.$(`.header-balance .total-atoms h2`),
`${totalAtoms}.0000…`,
`${parseInt(totalAtoms) - 10}.0000…`,
10 * 1000
)
console.log(`Testing unbonded balance`)
await waitForText(
() => app.client.$(`.header-balance .unbonded-atoms h2`),
`${unbondedAtoms - 10}.0000…`,
`${parseInt(unbondedAtoms) - 10}.0000…`,
10 * 1000
)
await closeNotifications(app)
Expand Down
Loading