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

Jordan/1869 network page #1925

Merged
merged 12 commits into from
Feb 5, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [\#1804](https://github.com/cosmos/voyager/issues/1804) Moved Voyager to the web @faboweb
- [\#1835](https://github.com/cosmos/voyager/issues/1835) allow user to use different signing methods @faboweb
- [\#1338](https://github.com/cosmos/voyager/issues/1338) Add Ledger Nano S support for signing transactions @fedekunze
- [\#1869](https://github.com/cosmos/voyager/issues/1869) Added PageNetwork @jbibla
- [\#1894](https://github.com/cosmos/voyager/issues/1894) Added favicons for all the browsers and devices @jbibla

### Changed
Expand Down
10 changes: 10 additions & 0 deletions app/src/renderer/components/common/AppMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
<h2 class="app-menu-title">Governance</h2>
<i class="material-icons">chevron_right</i>
</router-link>
<router-link
id="app-menu__network"
class="app-menu-item"
to="/network"
title="Network"
@click.native="close"
>
<h2 class="app-menu-title">Network</h2>
<i class="material-icons">chevron_right</i>
</router-link>
</div>
<connected-network />
</menu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default {
.tm-connected-network .chain-id {
font-weight: 500;
padding-right: 1rem;
background: none !important;
}

.tm-connected-network .exit {
Expand Down
112 changes: 112 additions & 0 deletions app/src/renderer/components/network/PageNetwork.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<template>
<tm-page data-title="Network">
<template slot="menu-body">
<tm-balance />
<tool-bar />
</template>

<tm-data-error v-if="!connected" />

<template v-else>
<div class="page-profile__header page-profile__section network">
<div class="row">
<div class="page-profile__header__info">
<div class="page-profile__status-and-title">
<span
v-tooltip.top="status.message"
:class="status.color"
class="page-profile__status"
/>
<h2 class="page-profile__title">{{ lastHeader.chain_id }}</h2>
<h3 v-if="config.devMode">
Proposer: {{ lastHeader.proposer_address }}
</h3>
</div>
</div>
</div>
<div class="row">
<dl class="info_dl colored_dl">
<dt>Height</dt>
<dd>{{ lastHeader.height }}</dd>
</dl>
<dl class="info_dl colored_dl">
<dt>Last Block</dt>
<dd>{{ lastBlock }}</dd>
</dl>
<dl class="info_dl colored_dl">
<dt>Transactions</dt>
<dd>{{ lastHeader.total_txs }}</dd>
</dl>
<dl class="info_dl colored_dl">
<dt>Number of Validators</dt>
<dd>{{ delegates.delegates.length }}</dd>
</dl>
</div>
<div class="row">
<div class="column">
<dl class="info_dl">
<dt>Total Liquid {{ bondDenom }}</dt>
<dd id="loose_tokens">
{{ pool.pool.loose_tokens ? pool.pool.loose_tokens : `n/a` }}
</dd>
</dl>
</div>
<div class="column">
<dl class="info_dl">
<dt>Total Delegated {{ bondDenom }}</dt>
<dd id="bonded_tokens">
{{ pool.pool.bonded_tokens ? pool.pool.bonded_tokens : `n/a` }}
</dd>
</dl>
</div>
</div>
</div>
</template>
</tm-page>
</template>

<script>
import moment from "moment"
import { mapGetters } from "vuex"
import TmBtn from "common/TmBtn"
import ToolBar from "common/ToolBar"
import TmBalance from "common/TmBalance"
import TmDataError from "common/TmDataError"
import TmPage from "common/TmPage"
export default {
name: `page-network`,
components: {
TmBalance,
TmBtn,
ToolBar,
TmDataError,
TmPage
},
computed: {
...mapGetters([
`connected`,
`lastHeader`,
`delegates`,
`config`,
`pool`,
`bondDenom`
]),
status() {
const color = this.connected ? `green` : `red`
const message = this.connected
? `Network is up and running`
: `Network is down`
return { color, message }
},
lastBlock() {
moment.relativeTimeThreshold(`ss`, 1)
return moment(this.lastHeader.time).fromNow()
}
}
}
</script>
<style>
.network .page-profile__header__info {
padding: 2rem;
}
</style>
59 changes: 3 additions & 56 deletions app/src/renderer/components/staking/TabParameters.vue
Original file line number Diff line number Diff line change
@@ -1,50 +1,9 @@
<template>
<tm-data-connecting
v-if="(!stakingParameters.loaded || !pool.loaded) && !connected"
/>
<tm-data-connecting v-if="!connected && !stakingParameters.loaded" />
<tm-data-loading
v-else-if="
(!stakingParameters.loaded && stakingParameters.loading) ||
(!pool.loaded && pool.loading)
"
v-else-if="!stakingParameters.loaded && stakingParameters.loading"
/>
<div v-else>
<div>
<div class="parameters__details parameters__section">
<div class="row">
<div class="column">
<dl class="info_dl">
<dt>
Total Liquid {{ bondDenom }}
<i
v-tooltip.top="poolTooltips.loose_tokens"
class="material-icons info-button"
>info_outline</i
>
</dt>
<dd id="loose_tokens">
{{ pool.pool.loose_tokens ? pool.pool.loose_tokens : `n/a` }}
</dd>
</dl>
</div>
<div class="column">
<dl class="info_dl">
<dt>
Total Delegated {{ bondDenom }}
<i
v-tooltip.top="poolTooltips.bonded_tokens"
class="material-icons info-button"
>info_outline</i
>
</dt>
<dd id="bonded_tokens">
{{ pool.pool.bonded_tokens ? pool.pool.bonded_tokens : `n/a` }}
</dd>
</dl>
</div>
</div>
</div>
</div>
<div>
<div class="parameters__details parameters__section">
<div class="row">
Expand Down Expand Up @@ -115,21 +74,10 @@ export default {
unbonding_time: `Time to complete an undelegation transaction and claim rewards`,
max_validators: `Maximum number of validators in the validator set`,
bond_denom: `The token being used for staking`
},
poolTooltips: {
description: `The staking pool represents the dynamic parameters of the Cosmos Hub`,
loose_tokens: `Total tokens which are not currently delegated to a validator`,
bonded_tokens: `Total tokens which are currently delegated to a validator`
}
}),
computed: {
...mapGetters([
`config`,
`stakingParameters`,
`pool`,
`connected`,
`bondDenom`
]),
...mapGetters([`config`, `stakingParameters`, `connected`, `bondDenom`]),
unbondingTimeInDays() {
return (
parseInt(this.stakingParameters.parameters.unbonding_time) /
Expand All @@ -139,7 +87,6 @@ export default {
},
async mounted() {
this.$store.dispatch(`getStakingParameters`)
this.$store.dispatch(`getPool`)
}
}
</script>
6 changes: 5 additions & 1 deletion app/src/renderer/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ export default [
name: `transactions`,
component: require(`./components/wallet/PageTransactions`).default
},

{
path: `/network`,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be the default route

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

interesting idea @fedekunze! i don't want to make this change right now, but we should talk about it at the next team meeting. i've added it to the agenda.

remember, eventually we will have a dashboard as the default route - but this might be a good interim solution.

name: `network`,
component: require(`./components/network/PageNetwork`).default
},
{ path: `/404`, component: require(`./components/common/Page404`).default },
{ path: `*`, component: require(`./components/common/Page404`).default }
]
6 changes: 4 additions & 2 deletions app/src/renderer/vuex/modules/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function({ node }) {
},
approvalRequired: null,
mocked: node.mocked,
nodeUrl: config.node_lcd,
nodeUrl: config.stargate,
externals: {
node,
config
Expand Down Expand Up @@ -96,7 +96,9 @@ export default function({ node }) {
})

node.rpc.subscribe(
{ query: `tm.event = 'NewBlockHeader'` },
{
query: `tm.event = 'NewBlockHeader'`
},
({ header }) => {
dispatch(`setLastHeader`, header)
}
Expand Down
5 changes: 0 additions & 5 deletions test/unit/helpers/fixed_time.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
"use strict"

/* globals jest */
require(`moment`)
const mockMomentTz = require(`moment-timezone`)
jest.mock(`moment`, () => time => mockMomentTz(time).tz(`Etc/UTC`))

const DATE_TO_USE = new Date(Date.UTC(1970, 0, 1, 0, 0, 42))
global._Date = Date
global.Date = jest.fn(() => new global._Date(DATE_TO_USE.toISOString()))
Expand Down
78 changes: 78 additions & 0 deletions test/unit/specs/components/network/PageNetwork.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { shallowMount, createLocalVue } from "@vue/test-utils"
import PageNetwork from "renderer/components/network/PageNetwork"

const localVue = createLocalVue()
localVue.directive(`tooltip`, () => {})

describe(`PageNetwork`, () => {
let wrapper, $store

beforeEach(() => {
$store = {
getters: {
connected: true,
lastHeader: {
chain_id: `gaia-20k`,
proposer_address: `EFH47FH723HDHSH`,
height: `6001`,
total_txs: `108`,
time: Date.now()
},
delegates: {
delegates: [
{
a: `b`,
c: `d`
}
]
},
config: {
devMode: true
},
pool: {
pool: {
bonded_tokens: 125,
loose_tokens: 10
}
},
bondDenom: `stake`
}
}

wrapper = shallowMount(PageNetwork, {
localVue,
mocks: {
$store
}
})
})

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

it(`sets the status correctly`, () => {
expect(wrapper.vm.status).toEqual({
color: `green`,
message: `Network is up and running`
})

$store = {
getters: {
connected: false
}
}

wrapper = shallowMount(PageNetwork, {
localVue,
mocks: {
$store
}
})

expect(wrapper.vm.status).toEqual({
color: `red`,
message: `Network is down`
})
})
})
Loading