Browse Source

variance

master
yuriy0803 3 years ago
parent
commit
45ad487799
  1. 11
      new-web/layouts/default.vue
  2. 88
      new-web/store/index.js

11
new-web/layouts/default.vue

@ -211,6 +211,17 @@
}}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item class="stats-item ma-1">
<v-list-item-avatar>
<v-icon>mdi-lock</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{
$t('pages.blocks.variance')
}}</v-list-item-title>
<v-list-item-subtitle>{{ stats.percent }}%</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item class="stats-item ma-1">
<v-list-item-avatar>
<v-icon>mdi-timer-sand</v-icon>

88
new-web/store/index.js

@ -1,11 +1,11 @@
import axios from 'axios'
import consola from 'consola'
import config from '@/params/config.json'
import networks from '@/params/networks.json'
import axios from 'axios';
import consola from 'consola';
import config from '@/params/config.json';
import networks from '@/params/networks.json';
const TARGET_TIME = networks[config.network].blockTime
const EPOCH_LENGTH = networks[config.network].epochLength
const API_URL = config.api + '/api'
const TARGET_TIME = networks[config.network].blockTime;
const EPOCH_LENGTH = networks[config.network].epochLength;
const API_URL = config.api + '/api';
export const state = () => ({
env: {
@ -40,39 +40,44 @@ export const state = () => ({
epoch: 0,
dagSize: 0, // in MB
now: Date.now(), // global now Date for time since calcs
})
percent: 0,
});
export const mutations = {
SET_STATS(state, info) {
state.minersOnline = info.minersOnline || state.minersOnline
state.poolHashRate = info.poolHashRate || state.poolHashRate
state.lastBlockFound = info.lastBlockFound || state.lastBlockFound
state.roundShares = info.roundShares || state.roundShares
state.poolFee = info.poolFee || state.poolFee
state.height = info.height || state.height
state.difficulty = info.difficulty || state.difficulty
state.networkHashrate = state.difficulty / info.blocktime // Verwenden Sie die blocktime von der API
state.epoch = Math.trunc(info.height / EPOCH_LENGTH)
state.dagSize = state.epoch * 8192 / 1024 / 1024 + 1
state.minersOnline = info.minersOnline || state.minersOnline;
state.poolHashRate = info.poolHashRate || state.poolHashRate;
state.lastBlockFound = info.lastBlockFound || state.lastBlockFound;
state.roundShares = info.roundShares || state.roundShares;
state.poolFee = info.poolFee || state.poolFee;
state.height = info.height || state.height;
state.difficulty = info.difficulty || state.difficulty;
state.networkHashrate = state.difficulty / info.blocktime; // Use the blocktime from the API
state.epoch = Math.trunc(info.height / EPOCH_LENGTH);
state.dagSize = (state.epoch * 8192) / 1024 / 1024 + 1;
// Calculate the percent
const percent = (state.roundShares / state.difficulty) * 100;
state.percent = percent.toFixed(0); // Store the result in the state
},
SET_MINERS(state, miners) {
state.miners = miners
state.miners = miners;
},
SET_BLOCKS(state, blocks) {
state.blocks = blocks
state.blocks = blocks;
},
SET_PAYMENTS(state, txns) {
state.payments = txns
state.payments = txns;
},
SET_NOW(state, now) {
state.now = now
state.now = now;
},
}
};
export const actions = {
async stats({ commit }) {
try {
const { data } = await axios.get(API_URL + '/stats')
const { data } = await axios.get(`${API_URL}/stats`);
if (data) {
const info = {
minersOnline: data.minersTotal,
@ -80,45 +85,50 @@ export const actions = {
height: data.nodes[0].height,
difficulty: data.nodes[0].difficulty,
lastBlockFound: data.stats.lastBlockFound,
blocktime: data.nodes[0].blocktime, // Hinzufügen der blocktime von der API
}
commit('SET_STATS', info)
blocktime: data.nodes[0].blocktime, // Add the blocktime from the API
roundShares: data.stats.roundShares, // Extrahieren Sie den Wert von roundShares aus den API-Daten
};
commit('SET_STATS', info);
}
} catch (error) {
consola.error(new Error(error))
consola.error(error);
throw new Error('Failed to fetch stats');
}
},
async miners({ commit }) {
try {
const { data } = await axios.get(API_URL + '/miners')
const { data } = await axios.get(`${API_URL}/miners`);
if (data) {
commit('SET_MINERS', data.miners)
commit('SET_MINERS', data.miners);
}
} catch (error) {
consola.error(new Error(error))
consola.error(error);
throw new Error('Failed to fetch miners');
}
},
async blocks({ commit }) {
try {
const { data } = await axios.get(API_URL + '/blocks')
const { data } = await axios.get(`${API_URL}/blocks`);
if (data) {
commit('SET_BLOCKS', data)
commit('SET_BLOCKS', data);
}
} catch (error) {
consola.error(new Error(error))
consola.error(error);
throw new Error('Failed to fetch blocks');
}
},
async payments({ commit }) {
try {
const { data } = await axios.get(API_URL + '/payments')
const { data } = await axios.get(`${API_URL}/payments`);
if (data) {
commit('SET_PAYMENTS', data)
commit('SET_PAYMENTS', data);
}
} catch (error) {
consola.error(new Error(error))
consola.error(error);
throw new Error('Failed to fetch payments');
}
},
now({ commit }) {
commit('SET_NOW', Date.now())
commit('SET_NOW', Date.now());
},
}
};

Loading…
Cancel
Save