Skip to content

Commit

Permalink
Merge branch 'dev' into lacchain
Browse files Browse the repository at this point in the history
  • Loading branch information
xavier506 committed Apr 26, 2021
2 parents d612a6c + 306876d commit 1e882bd
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 7 deletions.
29 changes: 28 additions & 1 deletion hapi/src/services/stats.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ const getTransactionsInTimeRage = async payload => {
return data.block.info.sum.transactions_length || 0
}

const getNodesSummary = async payload => {
const query = `
query {
producers: producer {
bp_json
}
}
`
const data = await hasuraUtil.request(query, payload)
let total = 0
const totalByType = {}

data.producers.forEach(producer => {
producer.bp_json.nodes.forEach(node => {
if (!totalByType[node.node_type]) {
totalByType[node.node_type] = 0
}

totalByType[node.node_type]++
total++
})
})

return { total, ...totalByType }
}

const getBlockDistribution = async (range = '1 day') => {
try {
let totalBloks = 0
Expand Down Expand Up @@ -120,7 +146,8 @@ const sync = async () => {
end: moment()
}),
transactions_in_last_week: transactionsInLastWeek,
average_daily_transactions_in_last_week: transactionsInLastWeek / 7
average_daily_transactions_in_last_week: transactionsInLastWeek / 7,
nodes_summary: await getNodesSummary()
}

const stats = await getStats()
Expand Down
1 change: 1 addition & 0 deletions hasura/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,5 @@
- average_daily_transactions_in_last_week
- created_at
- updated_at
- nodes_summary
filter: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."stat" add column "nodes_summary" jsonb
null default jsonb_build_object();
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."stat" add column "nodes_summary" jsonb
null default jsonb_build_object();
83 changes: 83 additions & 0 deletions webapp/src/components/NodesSummary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* eslint camelcase: 0 */
import React, { memo, useEffect, useState } from 'react'
import PropTypes from 'prop-types'
import Card from '@material-ui/core/Card'
import Grid from '@material-ui/core/Grid'
import CardContent from '@material-ui/core/CardContent'
import Typography from '@material-ui/core/Typography'
import LinearProgress from '@material-ui/core/LinearProgress'
import { useQuery } from '@apollo/react-hooks'

import { NODES_SUMMARY_QUERY } from '../gql'

const BodyGraphValue = ({ loading, value }) => {
if (loading) return <LinearProgress />

return (
<Typography component="p" variant="h6">
{value}
</Typography>
)
}

BodyGraphValue.propTypes = {
loading: PropTypes.bool,
value: PropTypes.number
}

BodyGraphValue.defaultProps = {
value: 0,
loading: false
}

const NodesSummary = ({ t }) => {
const { data, loading } = useQuery(NODES_SUMMARY_QUERY)
const [total, setTotal] = useState()
const [nodes, setNodes] = useState()

useEffect(() => {
if (!data?.stats) {
return
}

const { total, ...nodes } = data?.stats[0]?.nodes_summary

setTotal(total)
setNodes(nodes)
}, [data])

return (
<>
<Grid item xs={12}>
<Card>
<CardContent>
<Typography>{`${t('total')} ${t('nodes')}`}</Typography>
<BodyGraphValue value={total} loading={loading} />
</CardContent>
</Card>
</Grid>

{nodes &&
Object.keys(nodes).map((type) => (
<Grid item xs={12} key={type}>
<Card>
<CardContent>
<Typography>{`${t(type)} ${t('nodes')}`}</Typography>
<BodyGraphValue value={nodes[type] || 0} loading={loading} />
</CardContent>
</Card>
</Grid>
))}
</>
)
}

NodesSummary.propTypes = {
t: PropTypes.func
}

NodesSummary.defaultProps = {
t: (text) => text
}

export default memo(NodesSummary)
10 changes: 10 additions & 0 deletions webapp/src/gql/producer.gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ export const BLOCK_TRANSACTIONS_HISTORY = gql`
}
`

export const NODES_SUMMARY_QUERY = gql`
query {
stats: stat(limit: 1) {
id
nodes_summary
updated_at
}
}
`

export const BLOCK_DISTRIBUTION_QUERY = gql`
query($range: String!) {
items: block_distribution(range: $range) {
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"itemsPerPage": "Items per page",
"api": "API",
"ssl": "SSL",
"p2p": "P2P"
"p2p": "P2P",
"nodes": "Nodes",
"total": "Total"
},
"routes": {
"/>sidebar": "Dashboard",
Expand Down Expand Up @@ -166,7 +168,6 @@
"ownershipDisclosure": "Ownership Disclosure",
"chainResources": "Chain Resources",
"otherResources": "Other Resources",
"nodes": "Nodes",
"email": "Email"
},
"nodeCardComponent": {
Expand Down
6 changes: 5 additions & 1 deletion webapp/src/language/en.lacchain.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
"common": {
"producerName": "Entity name",
"producers": "Entities",
"producer": "Entity"
"producer": "Entity",
"boot": "Boot",
"writer": "Writer",
"observer": "Observer",
"validator": "Validator"
},
"producerCardComponent": {
"entityType": "Entity type",
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/language/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"itemsPerPage": "Elementos por página",
"api": "API",
"ssl": "SSL",
"p2p": "P2P"
"p2p": "P2P",
"nodes": "Nodos",
"total": "Total"
},
"routes": {
"/>sidebar": "Panel",
Expand Down Expand Up @@ -164,7 +166,6 @@
"ownershipDisclosure": "Divulgación de propiedad",
"chainResources": "Recursos de la cadena",
"otherResources": "Otros recursos",
"nodes": "Nodos",
"email": "Correo electrónico"
},
"nodeCardComponent": {
Expand Down
6 changes: 5 additions & 1 deletion webapp/src/language/es.lacchain.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
"common": {
"producerName": "Nombre de la entidad",
"producers": "Entidades",
"producer": "Entidad"
"producer": "Entidad",
"boot": "Boot",
"writer": "Escritor",
"observer": "Observador",
"validator": "Validador"
},
"producerCardComponent": {
"entityType": "Tipo de entidad",
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/routes/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const ProducersChart = lazy(() => import('../components/ProducersChart'))
const TransactionsHistory = lazy(() =>
import('../components/TransactionsHistory')
)
const NodesSummary = lazy(() => import('../components/NodesSummary'))
const TransactionsLineChart = lazy(() =>
import('../components/TransactionsLineChart')
)
Expand Down Expand Up @@ -181,6 +182,7 @@ const Home = () => {
</Card>
</Grid>
<TransactionsHistory t={t} />
<NodesSummary t={t} />
</Grid>
{loading && <LinearProgress />}
<Grid item xs={12} md={9} className={classes.rightColumn}>
Expand Down

0 comments on commit 1e882bd

Please sign in to comment.