Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Refactor the Znode list.
Browse files Browse the repository at this point in the history
  • Loading branch information
sproxet committed Aug 29, 2019
1 parent eee9ffd commit b643c14
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 1,139 deletions.
40 changes: 40 additions & 0 deletions src/daemon/modules/znodeList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Zcoind } from '../zcoind';

import { createLogger } from '../../lib/logger';
const logger = createLogger('zcoin:daemon:znodeUpdate');

// In addition to initializing the znode list, this function goes into an infinite loop refreshing the data every 5
// minutes.
export async function initialize(store: any, zcoind: Zcoind) {
while (true) {
try {
const data = await zcoind.send(null, 'initial', 'znodeList', null);
logger.info("Got initial znodeList data");

if (Object.keys(data.nodes).length) {
store.dispatch('Znode/setStateWithZnodeList', data.nodes);
store.dispatch('Znode/setZnodeCount', data.total);

if (Object.keys(data.nodes).length < data.total) {
// The list still hasn't loaded yet, and is showing only our own Znodes. Refresh in 5s.
await new Promise((resolve) => setTimeout(resolve, 5000));
} else {
// The list has loaded. Refresh again in 5 minutes.
await new Promise((resolve) => setTimeout(resolve, 5 * 60 * 1000));
}
} else {
store.dispatch('Znode/setZnodeCount', data.total);
await new Promise((resolve) => setTimeout(resolve, 5000));
}
} catch (e) {
// Error -28 is "Loading block index..."
if (e.error && e.error.code === -28) {
logger.warn("initial/znodeList returned error -28, loading block index. Trying again in 1s.");
store.dispatch('Znode/setStateWithZnodeList', {});
await new Promise((resolve) => setTimeout(resolve, 2000));
} else {
throw e;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<th
v-if="isHeader"
class="vuetable-th-component-active-since"
@click="$emit('click', rowField, $event)"
v-html="title"
/>
<td
v-else
class="vuetable-td-component-active-since"
:title="absoluteDateString"
>
<timeago
v-if="date"
:datetime="date"
:auto-update="30"
/>
<span v-else>
~
</span>
</td>
</template>

<script>
import VuetableFieldMixin from 'vuetable-2/src/components/VuetableFieldMixin.vue'
import { format } from 'date-fns'
export default {
name: 'ZnodeActiveSince',
mixins: [
VuetableFieldMixin
],
computed: {
date () {
return this.rowData.activeSince
},
absoluteDateString () {
return format(new Date(this.date), "HH:MM, D MMM YYYY")
}
}
}
</script>

<style scoped>
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<th
v-if="isHeader"
class="vuetable-th-component-last-seen"
@click="$emit('click', rowField, $event)"
v-html="title"
/>
<td
v-else
class="vuetable-td-component-last-seen"
:title="absoluteDateString"
>
<timeago
v-if="date"
:datetime="date"
:auto-update="30"
/>
<span v-else>
~
</span>
</td>
</template>

<script>
import VuetableFieldMixin from 'vuetable-2/src/components/VuetableFieldMixin.vue'
import { format } from 'date-fns'
export default {
name: 'ZnodeLastSeen',
mixins: [
VuetableFieldMixin
],
computed: {
date () {
return this.rowData.lastSeen
},
absoluteDateString () {
return format(new Date(this.date), "HH:MM, D MMM YYYY")
}
}
}
</script>

<style scoped>
</style>
101 changes: 44 additions & 57 deletions src/renderer/components/ZnodePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,19 @@

<div class="search-form">
<base-filter-input
v-model="urlFilter"
v-model="searchQuery"
type="text"
class="table-filter-input"
theme="dark"
:placeholder="$t('znodes.overview.table__znodes.placeholder__filter')"
/>
<!--<div class="internal-only">
For Internal Use Only!!!
</div>-->
</div>
</section>

<znode-map
v-if="displayZnodeMap"
class="znodes-map"
:remote-znodes="remoteZnodes"
:my-znodes="filteredMyZnodes"
/>

<section
class="stats"
:class="{'znode-map-displayed': displayZnodeMap}"
>
<section class="stats">
<div class="stat">
<div class="value">
{{ totalZnodes }}
{{ znodeCount }}
</div>
<div class="desc">
{{ $t('znodes.overview.stats.description__total-nodes') }}
Expand All @@ -62,18 +49,18 @@
<template v-else>
<div class="stat">
<div class="value">
{{ Math.ceil(znodePaymentCycleInDays) }}
{{ paymentPeriodInDays }}
</div>
<div class="desc">
{{ $t('znodes.overview.stats.description__average-days-for-payout') }}
</div>
</div>
<div
v-if="enabledMyZnodes.length && roundedDaysUntilNextPayout > 0"
v-if="enabledMyZnodes.length && daysUntilNextPayout > 0"
class="stat"
>
<div class="value">
{{ roundedDaysUntilNextPayout }}
{{ daysUntilNextPayout }}
</div>
<div class="desc">
{{ $t('znodes.overview.stats.description__days-until-next-payout') }}
Expand All @@ -86,7 +73,7 @@
<my-znode
v-for="(znode, index) in filteredMyZnodes"
:key="index"
v-bind="znode"
:znode="znode"
/>
</section>

Expand All @@ -100,12 +87,8 @@

<script>
import { mapGetters } from 'vuex'
// import types from '~/types'
import FilterByUrlParamMixin from '@/mixins/FilterByUrlParamMixin'
import MyZnode from '@/components/ZnodePage/MyZnode'
import ZnodeMap from '@/components/ZnodePage/ZnodeMap'
import RemoteZnodesList from '@/components/ZnodePage/RemoteZnodesList'
import LoadingBounce from "./Icons/LoadingBounce";
Expand All @@ -115,56 +98,65 @@ export default {
components: {
LoadingBounce,
RemoteZnodesList,
MyZnode,
ZnodeMap
MyZnode
},
mixins: [
FilterByUrlParamMixin
],
data () {
return {
searchQuery: ''
}
},
computed: {
...mapGetters({
isWinnersListSynced: 'Blockchain/isWinnersListSynced',
myZnodes: 'Znode/myZnodes',
remoteZnodes: 'Znode/remoteZnodes',
totalZnodes: 'Znode/totalZnodes',
znodePaymentCycleInDays: 'Znode/znodePaymentCycleInDays'
znodeCount: 'Znode/znodeCount',
paymentPeriod: 'Znode/paymentPeriod'
}),
displayZnodeMap () {
return false
},
enabledMyZnodes () {
return this.myZnodes.filter((znode) => znode.status === 'ENABLED')
return this.myZnodes.filter(znode => znode.status === 'ENABLED')
},
filteredMyZnodes () {
return this.getFilteredByUrl(this.myZnodes, ['status', 'payeeAddress', 'authorityIp', 'id', 'label'])
return this.myZnodes.filter(znode => {
for (const data of [znode.status, znode.payeeAddress, znode.authority.ip, znode.outpoint.txid, znode.label]) {
if (data && data.indexOf(this.searchQuery) !== -1) {
return true;
}
}
});
},
filteredRemoteZnodes () {
return this.getFilteredByUrl(this.remoteZnodes, ['status', 'payeeAddress', 'authorityIp', 'id'])
return this.remoteZnodes.filter(znode => {
for (const data of [znode.status, znode.payeeAddress, znode.authority.ip, znode.outpoint.txid]) {
if (data && data.indexOf(this.searchQuery) !== -1) {
return true;
}
}
});
},
paymentPeriodInDays () {
return Math.ceil(this.paymentPeriod / 1000 / 24 / 60 / 60)
},
daysUntilNextPayout () {
if (!this.myZnodes.length) {
const oldestUnpaidTime = this.myZnodes
.map(znode => znode.lastPaidTime || znode.activeSince )
.sort() // false is sorted last
[0];
if (!oldestUnpaidTime) {
return false
}
const now = Date.now()
const nextEstimatedPayout = this.myZnodes.reduce((aggregator, znode) => {
const { nextEstimatedPayout } = znode
return !nextEstimatedPayout || aggregator < nextEstimatedPayout ? aggregator : nextEstimatedPayout
}, Infinity)
return (nextEstimatedPayout - now) / 1000 / 60 / 60 / 24
},
const estimatedNextPayout = oldestUnpaidTime + this.paymentPeriod;
roundedDaysUntilNextPayout () {
return Math.round(this.daysUntilNextPayout)
return (estimatedNextPayout - Date.now()) / 1000 / 24 / 60 / 60;
},
statsLoaded () {
Expand Down Expand Up @@ -241,13 +233,7 @@ export default {
justify-content: space-evenly;
z-index: 10;
&.znode-map-displayed {
margin-top: emRhythm(-10);
margin-bottom: emRhythm(7);
}
&:not(.znode-map-displayed) {
margin-top: emRhythm(12);
}
margin-top: emRhythm(12);
.stat {
max-width: 15rem;
Expand Down Expand Up @@ -287,6 +273,7 @@ export default {
grid-template-columns: repeat(2, 1fr);
grid-column-gap: emRhythm(4);
grid-row-gap: emRhythm(6);
padding-top: 2em;
}
.remote-znodes {
Expand Down
Loading

0 comments on commit b643c14

Please sign in to comment.