mirror of
https://github.com/oceanprotocol/status-frontend.git
synced 2024-06-28 08:47:48 +02:00
24 lines
816 B
TypeScript
24 lines
816 B
TypeScript
import axios, { AxiosResponse } from 'axios'
|
|
import { Status } from '../@types'
|
|
|
|
export async function getData(url: string): Promise<{ [key: string]: Status }> {
|
|
try {
|
|
const response: AxiosResponse<Status[]> = await axios.get(url)
|
|
console.log('Got response', response)
|
|
console.log('Got data', response.data)
|
|
if (!response?.data || response.status !== 200)
|
|
throw Error('ERROR: no data recieved')
|
|
|
|
// transform data into object with network names as keys
|
|
let output = Object.fromEntries(
|
|
response.data?.map((item) => [item.network, item])
|
|
)
|
|
// make sure 'general' is always the first key
|
|
output = Object.assign({ general: output['general'] }, output)
|
|
console.log('Got new data', output)
|
|
return output
|
|
} catch (error) {
|
|
console.error(error.message)
|
|
}
|
|
}
|