Skip to content

Commit

Permalink
fix(api): getting provider from config
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Mar 15, 2022
1 parent 354190d commit 4b4a8af
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 45 deletions.
18 changes: 9 additions & 9 deletions packages/api/src/repository/ResultRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export class ResultRequestRepository {

constructor (db: Db, _dataFeeds: Array<FeedInfo>) {
this.collection = db.collection('result_request')
// this.collection.createIndex(
// { feedFullName: 1, timestamp: -1 },
// {
// collation: {
// locale: 'en_US',
// numericOrdering: true
// }
// }
// )
this.collection.createIndex(
{ feedFullName: 1, timestamp: -1 },
{
collation: {
locale: 'en_US',
numericOrdering: true
}
}
)
}

async getFeedRequests (
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const resolvers = {
},

feed: async (_parent, args, { feedRepository }: Context) => {
console.log('query?????', args.feedFullName)
return await feedRepository.get(args.feedFullName)
}
},
Expand Down
14 changes: 11 additions & 3 deletions packages/api/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export function normalizeNetworkConfig (
const chains: Array<string> = Object.keys(config.chains)

// get list of networks
const networks: any = Object.values(config.chains).map(chain =>
Object.values(chain.networks).map((value, index) => {
const networks: any = Object.values(config.chains).map(chain => {
const networks = Object.values(chain.networks).map((value, index) => {
return {
key: Object.keys(chain.networks)
[index].split('.')
Expand All @@ -50,7 +50,15 @@ export function normalizeNetworkConfig (
label: value.name
}
})
)
const testnetNetworks = networks.filter(
network => !network.label.includes('Mainnet')
)
const mainnetNetworks = networks.filter(network =>
network.label.includes('Mainnet')
)

return [...mainnetNetworks, ...testnetNetworks]
})

// add chain to each of the networks

Expand Down
28 changes: 7 additions & 21 deletions packages/api/src/web3Middleware/provider.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { Network } from './../types'

export function getProvider (network: Network) {
const providers: Record<Network, string> = {
[Network.EthereumMainnet]: process.env.ETHEREUM_MAINNET_PROVIDER,
[Network.EthereumGoerli]: process.env.ETHEREUM_GOERLI_PROVIDER,
[Network.EthereumRinkeby]: process.env.ETHEREUM_RINKEBY_PROVIDER,
[Network.ConfluxTestnet]: process.env.CONFLUX_TESTNET_PROVIDER,
[Network.ConfluxTethys]: process.env.CONFLUX_TETHYS_PROVIDER,
[Network.BobaRinkeby]: process.env.BOBA_RINKEBY_PROVIDER,
[Network.BobaMainnet]: process.env.BOBA_MAINNET_PROVIDER,
[Network.CeloAlfajores]: process.env.CELO_ALFAJORES_PROVIDER,
[Network.CeloMainnet]: process.env.CELO_MAINNET_PROVIDER,
[Network.MetisMainnet]: process.env.METIS_MAINNET_PROVIDER,
[Network.MetisRinkeby]: process.env.METIS_RINKEBY_PROVIDER,
[Network.HarmonyTestnet]: process.env.HARMONY_TESTNET_PROVIDER,
[Network.KCCTestnet]: process.env.KCC_TESTNET_PROVIDER,
[Network.KCCMainnet]: process.env.KCC_MAINNET_PROVIDER,
[Network.MoonbeamMoonbase]: process.env.MOONBASE_ALPHA_PROVIDER,
[Network.PolygonMainnet]: process.env.POLYGON_MAINNET_PROVIDER,
[Network.PolygonGoerli]: process.env.POLYGON_GOERLI_PROVIDER,
[Network.AvalancheFuji]: process.env.AVALANCHE_FUJI_PROVIDER
}
return providers[network]
// The provider env variable name should be the network name specified in the config plus '_PROVIDER' ex.MOONBEAM_MOONBASE_PROVIDER
return process.env[
`${network
.split('-')
.map(network => network.toUpperCase())
.join('_')}_PROVIDER`
]
}
1 change: 0 additions & 1 deletion packages/ui/apollo/queries/feed.gql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ query feed($feedFullName: String!, $timestamp: Int!) {
network
label
deviation
chain
proxyAddress
heartbeat
finality
Expand Down
4 changes: 0 additions & 4 deletions packages/ui/components/DataFeedDescription.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ export default {
type: String,
required: true,
},
chain: {
type: String,
required: true,
},
network: {
type: String,
required: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/ui/components/DataFeedDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<DataFeedDescription
:feed-name="normalizedFeed.name"
:network="normalizedFeed.network"
:chain="normalizedFeed.chain"
:last-result-value="lastResultValue"
:last-result-date="lastResultDate"
:feed-time-to-update="feedTimeToUpdate"
Expand All @@ -31,7 +30,6 @@
<Fieldset :title="$t('data_feed_details.contract_address')">
<IntegrationDetails
:network="normalizedFeed.network"
:chain="normalizedFeed.chain"
:proxy-address="normalizedFeed.proxyAddress"
:feed-address="normalizedFeed.address"
:contract-id="normalizedFeed.contractId"
Expand Down Expand Up @@ -74,6 +72,7 @@ export default {
prefetch: true,
query: feed,
variables() {
console.log(this.feedFullName)
return {
timestamp: this.timestamp,
feedFullName: this.feedFullName,
Expand Down Expand Up @@ -119,7 +118,6 @@ export default {
deviation: this.feed.deviation,
heartbeat: Number(this.feed.heartbeat),
decimals: this.feed.feedFullName.split('_').pop() || 3,
chain: this.feed.chain.split('.').map(capitalizeFirstLetter)[0],
network: this.feed.network
.split('-')
.map(capitalizeFirstLetter)
Expand Down
5 changes: 1 addition & 4 deletions packages/ui/components/NetworkOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ export default {
return this.$store.state.selectedNetwork
},
selectedOption() {
return (
this.$route.params.network ||
this.$store.state.selectedNetwork[0]?.network.toLowerCase()
)
return this.$route.params.network || 'ethereum'
},
},
methods: {
Expand Down

0 comments on commit 4b4a8af

Please sign in to comment.