some prework for graph view

This commit is contained in:
Marco van Dijk 2022-04-22 01:38:14 +02:00
parent d4212e24e6
commit 82f533d582
6 changed files with 92 additions and 4 deletions

View File

@ -13,6 +13,9 @@ import UnbondEvent from "../models/UnbondEvent";
import UpdateEvent from "../models/UpdateEvent";
import WithdrawFeesEvent from "../models/WithdrawFeesEvent";
import WithdrawStakeEvent from "../models/WithdrawStakeEvent";
import MonthlyStat from "../models/monthlyStat";
import CommissionDataPoint from "../models/CommissionDataPoint";
import TotalStakeDataPoint from "../models/TotalStakeDataPoint";
const apiRouter = express.Router();
import {
@ -38,9 +41,6 @@ const fs = require('fs');
// Used for the livepeer thegraph API
import { request, gql } from 'graphql-request';
import MonthlyStat from "../models/monthlyStat";
import CommissionDataPoint from "../models/CommissionDataPoint";
import TotalStakeDataPoint from "../models/TotalStakeDataPoint";
// Gets ETH, LPT and other coin info
let CoinMarketCap = require('coinmarketcap-api');
@ -173,6 +173,8 @@ let unbondEventCache = [];
let stakeEventCache = [];
let monthlyStatCache = [];
let commissionDataPointCache = [];
let totalStakeDataPoint = [];
apiRouter.get("/getAllMonthlyStats", async (req, res) => {
try {
@ -182,6 +184,22 @@ apiRouter.get("/getAllMonthlyStats", async (req, res) => {
}
});
apiRouter.get("/getAllCommissions", async (req, res) => {
try {
res.send(commissionDataPointCache);
} catch (err) {
res.status(400).send(err);
}
});
apiRouter.get("/getAllTotalStakes", async (req, res) => {
try {
res.send(totalStakeDataPoint);
} catch (err) {
res.status(400).send(err);
}
});
apiRouter.get("/getAllUpdateEvents", async (req, res) => {
try {
res.send(updateEventCache);
@ -1368,6 +1386,20 @@ const initSync = async function () {
testScores: 1,
_id: 0
});
// Get all graph data points
commissionDataPointCache = await CommissionDataPoint.find({}, {
address: 1,
feeCommission: 1,
rewardCommission: 1,
timestamp: 1,
_id: 0
});
totalStakeDataPoint = await TotalStakeDataPoint.find({}, {
address: 1,
totalStake: 1,
timestamp: 1,
_id: 0
});
}
// Does the actual looping over last parsed block -> latest block in chain

View File

@ -17,6 +17,8 @@ export const SET_ALL_ORCH_SCORES = "SET_ALL_ORCH_SCORES";
export const SET_ALL_ORCH_INFO = "SET_ALL_ORCH_INFO";
export const SET_ALL_DEL_INFO = "SET_ALL_DEL_INFO";
export const SET_ALL_MONTHLY_STATS = "SET_ALL_MONTHLY_STATS";
export const SET_ALL_COMMISSIONS = "SET_ALL_COMMISSIONS";
export const SET_ALL_TOTAL_STAKES = "SET_ALL_TOTAL_STAKES";
export const SET_ALL_UPDATE_EVENTS = "SET_ALL_UPDATE_EVENTS";
export const SET_ALL_REWARD_EVENTS = "SET_ALL_REWARD_EVENTS";
export const SET_ALL_CLAIM_EVENTS = "SET_ALL_CLAIM_EVENTS";
@ -79,6 +81,14 @@ const setAllMonthlyStats = message => ({
type: SET_ALL_MONTHLY_STATS, message
});
const setAllCommissions = message => ({
type: SET_ALL_COMMISSIONS, message
});
const setAllTotalStakes = message => ({
type: SET_ALL_TOTAL_STAKES, message
});
const setAllUpdateEvents = message => ({
type: SET_ALL_UPDATE_EVENTS, message
});
@ -257,6 +267,24 @@ export const getAllMonthlyStats = () => async dispatch => {
return dispatch(receiveErrors(data));
};
export const getAllCommissions = () => async dispatch => {
const response = await apiUtil.getAllCommissions();
const data = await response.json();
if (response.ok) {
return dispatch(setAllCommissions(data));
}
return dispatch(receiveErrors(data));
};
export const getAllTotalStakes = () => async dispatch => {
const response = await apiUtil.getAllTotalStakes();
const data = await response.json();
if (response.ok) {
return dispatch(setAllTotalStakes(data));
}
return dispatch(receiveErrors(data));
};
export const getAllUpdateEvents = () => async dispatch => {
const response = await apiUtil.getAllUpdateEvents();
const data = await response.json();

View File

@ -9,7 +9,7 @@ import {
getAllDelInfo, getAllMonthlyStats, getAllUpdateEvents, getAllRewardEvents,
getAllClaimEvents, getAllWithdrawStakeEvents, getAllWithdrawFeesEvents,
getAllTransferTicketEvents, getAllRedeemTicketEvents, getAllActivateEvents,
getAllUnbondEvents, getAllStakeEvents,
getAllUnbondEvents, getAllStakeEvents, getAllCommissions, getAllTotalStakes
} from "../actions/livepeer";
import { login } from "../actions/session";
@ -55,6 +55,8 @@ const Startup = (obj) => {
dispatch(getAllDelInfo());
dispatch(getAllOrchScores());
dispatch(getAllMonthlyStats());
dispatch(getAllCommissions());
dispatch(getAllTotalStakes());
dispatch(getAllUpdateEvents());
dispatch(getAllRewardEvents());
dispatch(getAllClaimEvents());

View File

@ -5,6 +5,7 @@ import { useSelector, useDispatch } from 'react-redux';
import { Accordion } from '@mantine/core';
import ScrollContainer from 'react-indiana-drag-scroll';
import WinnerMonth from '../components/WinnerMonth';
// import Graphs from '../components/Graphs';
const Stats = (obj) => {
const livepeer = useSelector((state) => state.livepeerstate);
@ -57,6 +58,7 @@ const Stats = (obj) => {
content: { padding: 0, paddingTop: '1em', paddingBottom: '1em' },
contentInner: { padding: 0 },
}}>
{/* <Graphs commissions={livepeer.allCommissions} stakes={livepeer.allTotalStakes} /> */}
{
livepeer.monthlyStats.slice(0).reverse().map(function (data, i) {
let thisMonth = "";

View File

@ -15,6 +15,8 @@ import {
SET_ALL_DEL_INFO,
CACHE_ORCHESTRATOR,
SET_ALL_MONTHLY_STATS,
SET_ALL_COMMISSIONS,
SET_ALL_TOTAL_STAKES,
SET_ALL_UPDATE_EVENTS,
SET_ALL_REWARD_EVENTS,
SET_ALL_CLAIM_EVENTS,
@ -109,6 +111,10 @@ export default (state = {
return { ...state, delInfo: message };
case SET_ALL_MONTHLY_STATS:
return { ...state, monthlyStats: message };
case SET_ALL_COMMISSIONS:
return { ...state, allCommissions: message };
case SET_ALL_TOTAL_STAKES:
return { ...state, allTotalStakes: message };
case SET_ALL_UPDATE_EVENTS:
return { ...state, updateEvents: message };
case SET_ALL_REWARD_EVENTS:

View File

@ -154,6 +154,24 @@ export const getAllMonthlyStats = () => (
})
);
export const getAllCommissions = () => (
fetch("api/livepeer/getAllCommissions", {
method: "GET",
headers: {
"Content-Type": "application/json"
}
})
);
export const getAllTotalStakes = () => (
fetch("api/livepeer/getAllTotalStakes", {
method: "GET",
headers: {
"Content-Type": "application/json"
}
})
);
export const getAllUpdateEvents = () => (
fetch("api/livepeer/getAllUpdateEvents", {
method: "GET",