Skip to content

Commit

Permalink
feat: migrate ui package to nuxt3
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Feb 22, 2024
1 parent 038ce62 commit 3ed77b4
Show file tree
Hide file tree
Showing 135 changed files with 8,370 additions and 10,498 deletions.
21 changes: 6 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,19 @@
"@commitlint/config-conventional": "^11.0.0",
"@commitlint/config-lerna-scopes": "^11.0.0",
"commitlint": "^11.0.0",
"husky": "^4.3.0",
"lerna": "^3.22.1",
"prettier-standard": "^16.4.1",
"babel-eslint": "^10.1.0",
"eslint": "^7.18.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-nuxt": "^2.0.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^7.5.0",
"prettier": "^2.2.1",
"@typescript-eslint/parser": "^6.17.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.2",
"prettier": "^3.1.1",
"migrate-mongo": "^9.0.0",
"stylelint": "^13.9.0",
"stylelint-config-prettier": "^8.0.2",
"stylelint-config-standard": "^20.0.0"
},
"volta": {
"node": "16.20.0",
"node": "18.17.0",
"yarn": "1.22.19"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
7 changes: 2 additions & 5 deletions packages/api/src/dataFeedsRouter.json
Original file line number Diff line number Diff line change
Expand Up @@ -1472,9 +1472,7 @@
"color": "#66ff00",
"name": "Optimism Goerli (testnet)",
"pollingPeriod": 120000,
"feeds": {

}
"feeds": {}
},
"optimism.mainnet": {
"legacy": true,
Expand Down Expand Up @@ -1808,8 +1806,7 @@
"color": "#66ff00",
"name": "Syscoin Rollux Testnet",
"pollingPeriod": 90000,
"feeds": {
}
"feeds": {}
}
}
},
Expand Down
23 changes: 16 additions & 7 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { MongoManager } from './database'
import { FeedRepository } from './repository/Feed'
import { ResultRequestRepository } from './repository/ResultRequest'
import { createServer } from './server'
import { RouterDataFeedsConfig, Repositories, FeedInfo, NetworksConfig } from './types'
import {
RouterDataFeedsConfig,
Repositories,
FeedInfo,
NetworksConfig
} from './types'
import { Web3Middleware } from './web3Middleware/index'
import { normalizeNetworkConfig } from './utils/index'
import {
Expand All @@ -23,7 +28,9 @@ async function main () {
const configurationFile: RouterDataFeedsConfig = await fetchDataFeedsRouterConfig()
const configuration = new Configuration(configurationFile)

const legacyFeeds: Array<FeedInfo> = normalizeAndValidateDataFeedConfig(configurationFile)
const legacyFeeds: Array<FeedInfo> = normalizeAndValidateDataFeedConfig(
configurationFile
)
const networksConfigPartial: Array<Omit<
NetworksConfig,
'logo'
Expand All @@ -44,15 +51,17 @@ async function main () {
logo: networksLogos[logosToFetch[index]]
}))

const routers = configuration.listNetworksUsingPriceFeedsContract()
const routers = configuration
.listNetworksUsingPriceFeedsContract()
.filter(config => {
if (!config.provider) {
console.warn("No provider found for ", config.key)
console.warn('No provider found for ', config.key)
}
return config.provider
})
.map(networkInfo => new NetworkRouter(configuration, repositories, networkInfo))

.map(
networkInfo => new NetworkRouter(configuration, repositories, networkInfo)
)

const newFeeds: Array<FeedInfo> = []

Expand All @@ -71,7 +80,7 @@ async function main () {
const web3Middleware = new Web3Middleware(
configuration,
{ repositories, Web3: Web3 },
legacyFeeds,
legacyFeeds
)

web3Middleware.listen()
Expand Down
34 changes: 17 additions & 17 deletions packages/api/src/repository/ResultRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,25 @@ export class ResultRequestRepository {
feedFullName: string
): Promise<ResultRequestDbObjectNormalized | null> {
console.log('inside getLastResult with feedFullname', feedFullName)
const lastResultRequest = await this.collection.findOne(
{
feedFullName
},
{
sort: {
timestamp: -1
const lastResultRequest = await this.collection
.findOne(
{
feedFullName
},
collation: {
locale: 'en_US',
numericOrdering: true
{
sort: {
timestamp: -1
},
collation: {
locale: 'en_US',
numericOrdering: true
}
}
}
).catch(e => {
console.log(`Error in getLastResult: ${feedFullName}`, e)
return null
})
)
.catch(e => {
console.log(`Error in getLastResult: ${feedFullName}`, e)
return null
})
console.log(lastResultRequest)
return this.normalizeId(lastResultRequest)
}
Expand All @@ -110,7 +112,6 @@ export class ResultRequestRepository {
async insertIfLatest (
resultRequest: WithoutId<ResultRequestDbObject>
): Promise<ResultRequestDbObjectNormalized | null> {

let storedResult = this.latestResults[resultRequest.feedFullName]
if (!storedResult) {
storedResult = await this.getLastResult(resultRequest.feedFullName)
Expand All @@ -129,7 +130,6 @@ export class ResultRequestRepository {
}
}


private normalizeId (
resultRequest: ResultRequestDbObject
): ResultRequestDbObjectNormalized | null {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type ConfigByFullName = {
}

export enum Network {
ArbitrumOne = 'arbitrum-one' ,
ArbitrumOne = 'arbitrum-one',
ArbitrumGoerli = 'arbitrum-goerli',
AvalancheMainnet = 'avalanche-mainnet',
AvalancheFuji = 'avalanche-fuji',
Expand Down Expand Up @@ -195,7 +195,7 @@ export type FeedParsedParams = {
}

export type FeedConfig = {
legacy?: boolean,
legacy?: boolean
address: string
blockExplorer: string
hide?: boolean
Expand Down
80 changes: 50 additions & 30 deletions packages/api/src/web3Middleware/Configuration.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { FeedParamsConfig, Network, NetworksConfig, RouterDataFeedsConfig } from "../types";
import { getNetworksListByChain, sortAlphabeticallyByLabel } from "../utils";
import { NetworkInfo } from "./NetworkRouter";
import { getProvider } from "./provider";
import {
FeedParamsConfig,
Network,
NetworksConfig,
RouterDataFeedsConfig
} from '../types'
import { getNetworksListByChain, sortAlphabeticallyByLabel } from '../utils'
import { NetworkInfo } from './NetworkRouter'
import { getProvider } from './provider'

export class Configuration {
private configurationFile: RouterDataFeedsConfig

constructor(json: RouterDataFeedsConfig) {
constructor (json: RouterDataFeedsConfig) {
this.configurationFile = json
}

Expand Down Expand Up @@ -35,65 +40,80 @@ export class Configuration {
}

// return networks using the new price feeds router contract
public listNetworksUsingPriceFeedsContract(): Array<NetworkInfo> {
public listNetworksUsingPriceFeedsContract (): Array<NetworkInfo> {
return Object.values(this.configurationFile.chains)
.flatMap(chain => Object.entries(chain.networks))
.filter(([_, network])=> network.legacy === false)
.filter(([_, network]) => network.legacy === false)
.map(([networkKey, network]) => {
return {
provider: getProvider(networkKey.replaceAll('.', '-') as Network),
address: network.address,
pollingPeriod: network.pollingPeriod,
key: this.fromNetworkKeyToNetwork(networkKey),
networkName: network.name,
networkName: network.name
}
})
}

public getLegacyConfigurationFile(): RouterDataFeedsConfig {
const chains = Object.entries(this.configurationFile.chains).reduce((acc, [chainKey, chain]) => {

if (chain.hide) {
return acc
}

const networks = Object.entries(chain.networks).reduce((accNetworks, [networkKey, network]) => {
// add the network entry if it's legacy
return network.legacy ? { ...accNetworks, [networkKey]: network } : accNetworks;
}, {})
public getLegacyConfigurationFile (): RouterDataFeedsConfig {
const chains = Object.entries(this.configurationFile.chains).reduce(
(acc, [chainKey, chain]) => {
if (chain.hide) {
return acc
}

return Object.keys(networks).length > 0 ? { ...acc, [chainKey]: { ...chain, networks } } : acc
}, {})
const networks = Object.entries(chain.networks).reduce(
(accNetworks, [networkKey, network]) => {
// add the network entry if it's legacy
return network.legacy
? { ...accNetworks, [networkKey]: network }
: accNetworks
},
{}
)

return Object.keys(networks).length > 0
? { ...acc, [chainKey]: { ...chain, networks } }
: acc
},
{}
)

return {
...this.configurationFile,
chains,
chains
}
}

public getFeedConfiguration(priceFeedName: string, network: Network): FeedParamsConfig {
public getFeedConfiguration (
priceFeedName: string,
network: Network
): FeedParamsConfig {
const defaultFeed = this.configurationFile.feeds[priceFeedName]
const specificFeedConfiguration = this.getNetworkConfiguration(network).feeds[priceFeedName]
const specificFeedConfiguration = this.getNetworkConfiguration(network)
.feeds[priceFeedName]

return { ...defaultFeed, ...specificFeedConfiguration }
}

public isFeedActive(caption: string): boolean {
public isFeedActive (caption: string): boolean {
return Object.keys(this.configurationFile.feeds).includes(caption)
}

public getNetworkConfiguration(network: Network) {
return this.configurationFile.chains[getChain(network)].networks[networkToKey(network)]
public getNetworkConfiguration (network: Network) {
return this.configurationFile.chains[getChain(network)].networks[
networkToKey(network)
]
}

private fromNetworkKeyToNetwork(networkKey: string): Network {
private fromNetworkKeyToNetwork (networkKey: string): Network {
return networkKey.replace('.', '-') as Network
}
}

export function getChain(network: Network) {
export function getChain (network: Network) {
return network.split('-')[0]
}
export function networkToKey(network: Network) {
export function networkToKey (network: Network) {
return network.replaceAll('-', '.')
}
Loading

0 comments on commit 3ed77b4

Please sign in to comment.