Skip to content

Commit

Permalink
feat(ui): fetch config file from github repo
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon authored and Tommytrg committed May 11, 2022
1 parent 7c4649f commit ea517da
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"dependencies": {
"apollo-server": "^2.22.1",
"axios": "^0.26.1",
"dataloader": "2.0.0",
"dotenv": "^10.0.0",
"graphql": "^15.5.0",
Expand Down
35 changes: 26 additions & 9 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,32 @@ import {
} from './types'
import { Web3Middleware } from './web3Middleware/index'
import { normalizeConfig, normalizeNetworkConfig } from './utils/index'
import dataFeedsRouterConfig from './dataFeedsRouter.json'
import axios from 'axios'

async function getDataFeedsRouterConfig (): Promise<
RouterDataFeedsConfig | null
> {
return await axios
.get(
'https://raw.github.com/witnet/data-feeds-explorer/main/packages/api/src/dataFeedsRouter.json'
)
.then(res => {
return res.data
})
.catch(err => {
console.log('There was an error fetching the config file', err)
return null
})
}

async function main () {
const mongoManager = new MongoManager()
const db = await mongoManager.start()
const dataFeeds = readDataFeeds()
const networksConfig = readNetworks()
const dataFeedsRouterConfig: RouterDataFeedsConfig = await getDataFeedsRouterConfig()
const dataFeeds = await readDataFeeds(dataFeedsRouterConfig)
const networksConfig: Array<NetworksConfig> = normalizeNetworkConfig(
dataFeedsRouterConfig
)

const repositories: Repositories = {
feedRepository: new FeedRepository(dataFeeds),
Expand All @@ -48,15 +67,13 @@ async function main () {
})
}

export function readNetworks (): Array<NetworksConfig> {
return normalizeNetworkConfig(dataFeedsRouterConfig as RouterDataFeedsConfig)
}

export function readDataFeeds (): Array<FeedInfo> {
export async function readDataFeeds (
config: RouterDataFeedsConfig
): Promise<Array<FeedInfo>> {
const dataFeeds: Array<Omit<
FeedInfoConfig,
'abi' | 'routerAbi'
>> = normalizeConfig(dataFeedsRouterConfig as RouterDataFeedsConfig)
>> = normalizeConfig(config)

// Throw and error if config file is not valid
validateDataFeeds(dataFeeds)
Expand Down

0 comments on commit ea517da

Please sign in to comment.