This commit is contained in:
mihaisc 2022-10-18 10:15:40 +03:00
parent d7afe55abc
commit 09e25b9eed
4 changed files with 21 additions and 7 deletions

1
.nvmrc Normal file
View File

@ -0,0 +1 @@
16

View File

@ -1,6 +1,7 @@
module.exports = {
statusApiUri: process.env.NEXT_STATUS_API_URI || 'http://localhost:8000',
statusApiUri:
process.env.NEXT_PUBLIC_STATUS_API_URI || 'http://localhost:8000',
availableNetworks:
process.env.NEXT_NETWORKS ||
process.env.NEXT_PUBLIC_NETWORKS ||
'["mainnet","polygon","bsc","moonriver","energyweb","mumbai","moonbase","goerli"]'
}

View File

@ -41,8 +41,10 @@ export default function HomePage(): ReactElement {
async function getStatuses() {
const statusData = await getData()
const summaryData = getSummary(network, statusData)
console.log('summaryData', summaryData)
if (summaryData) setSummary(summaryData)
const networkSummary = getNetworkSUmmary(statusData)
console.log('networkSummary', networkSummary)
if (networkSummary) setNetworks(networkSummary)
}
getStatuses()

View File

@ -3,13 +3,22 @@ import { NetworkSummary, State, Status, Summary } from '../@types'
import { statusApiUri } from '../../app.config'
import { availableNetworks } from '../../app.config'
export async function getData(): Promise<Status[]> {
export async function getData(): Promise<Status[][]> {
try {
const response: AxiosResponse<Status[]> = await axios.get(`${statusApiUri}`)
console.log(
'statusApiUri',
process.env,
process.env.NEXT_PUBLIC_STATUS_API_URI,
statusApiUri
)
const response: AxiosResponse<Status[][]> = await axios.get(
`${statusApiUri}`
)
if (!response || response.status !== 200 || !response.data)
console.log('ERROR: no data recieved')
const data = response.data
console.log('data', data)
return data
} catch (error) {
@ -17,12 +26,13 @@ export async function getData(): Promise<Status[]> {
}
}
export function getSummary(network: string, data: Status[]): Summary[] {
export function getSummary(network: string, data: Status[][]): Summary[] {
try {
if (data) {
let status: Status
data.forEach((element) => {
if (element.network === network) return (status = element)
if (element[0].network === network) return (status = element[0])
})
const summary: Summary[] = [
@ -57,7 +67,7 @@ export function getSummary(network: string, data: Status[]): Summary[] {
}
}
export function getNetworkSUmmary(data: Status[]): NetworkSummary[] {
export function getNetworkSUmmary(data: Status[][]): NetworkSummary[] {
const networks: string[] = JSON.parse(availableNetworks)
const networkSummary: NetworkSummary[] = []
networks.forEach((network) => {