Updating data format & improving error handling

This commit is contained in:
Jamie Hewitt 2022-10-17 13:51:32 +03:00
parent 49af074b59
commit 5776751de0
2 changed files with 13 additions and 16 deletions

View File

@ -31,12 +31,8 @@ export default function HomePage(): ReactElement {
useEffect(() => { useEffect(() => {
async function getStatuses() { async function getStatuses() {
const statusData = await getData() const statusData = await getData()
console.log('statusData', statusData)
if (statusData) setStatuses(statusData) if (statusData) setStatuses(statusData)
console.log('statuses', statuses) const summaryData = getSummary(network, statusData)
const summaryData = getSummary(network, statuses)
console.log('summaryData', summaryData)
if (summaryData) setSummary(summaryData) if (summaryData) setSummary(summaryData)
} }
getStatuses() getStatuses()

View File

@ -9,7 +9,7 @@ export async function getData(): Promise<Status[]> {
if (!response || response.status !== 200 || !response.data) if (!response || response.status !== 200 || !response.data)
console.log('ERROR: no data recieved') console.log('ERROR: no data recieved')
const data = [...response.data] const data = response.data
console.log('1. data length', data.length) console.log('1. data length', data.length)
console.log('1. data ', data) console.log('1. data ', data)
@ -20,33 +20,34 @@ export async function getData(): Promise<Status[]> {
} }
export function getSummary(network: string, data: Status[]): Summary[] { export function getSummary(network: string, data: Status[]): Summary[] {
console.log('2. data', data) console.log('2. data', network, data)
try { try {
if (data) { if (data) {
let status: Status let status: Status
data.forEach((element) => { data.forEach((element) => {
if (element.network === network) return (status = element) if (element.network === network) return (status = element)
}) })
console.log('network status: ', status)
const summary: Summary[] = [ const summary: Summary[] = [
{ component: 'Aquarius', status: status.aquarius.status }, { component: 'Aquarius', status: status?.aquarius?.status },
{ component: 'Provider', status: status.provider.status }, { component: 'Provider', status: status?.provider?.status },
{ component: 'Subgraph', status: status.subgraph.status }, { component: 'Subgraph', status: status?.subgraph?.status },
{ component: 'Market', status: status.market }, { component: 'Market', status: status?.market },
{ component: 'Port', status: status.port }, { component: 'Port', status: status?.port },
{ {
component: 'Data Farming', component: 'Data Farming',
status: status.dataFarming status: status?.dataFarming
}, },
{ {
component: 'Operator Service', component: 'Operator Service',
status: status.operator.status status: status?.operator?.status
}, },
{ {
component: 'DAO Grants', component: 'DAO Grants',
status: status.daoGrants status: status?.daoGrants
} }
] ]
status.faucet.status && status?.faucet?.status &&
summary.push({ summary.push({
component: 'Faucet', component: 'Faucet',
status: status.faucet.status status: status.faucet.status