Skip to content

Commit

Permalink
fix(ui): fix tests and responsive
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Mar 2, 2022
1 parent 1f7f9bf commit f2c0bf0
Show file tree
Hide file tree
Showing 47 changed files with 433 additions and 151 deletions.
6 changes: 3 additions & 3 deletions packages/api/src/repository/Feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export class FeedRepository {

updateFeedAddress (
feedFullName: string,
address: string,
contractId: string
{ address, contractId }: { address: string; contractId: string }
): FeedInfo {
const hasSameFeedFullName = (feed: FeedInfo) =>
feed.feedFullName === feedFullName
Expand All @@ -62,13 +61,14 @@ export class FeedRepository {
const feed = this.sortedDataFeeds[sortedDataFeedIndex]
feed.address = address
feed.contractId = contractId
// Update address in dataFeedsByNetwork
// Update address in dataFeedsByNetwork cache
const dataFeedsByNetworkIndex = this.dataFeedsByNetwork[
feed.network
].findIndex(hasSameFeedFullName)
this.dataFeedsByNetwork[feed.network][
dataFeedsByNetworkIndex
].address = address
// Update contractId in dataFeedsByNetwork cache
this.dataFeedsByNetwork[feed.network][
dataFeedsByNetworkIndex
].contractId = contractId
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const resolvers = {
)
},
lastResult: async (parent, _args, { resultRequestRepository }: Context) => {
// FIXME: add dataloader library to avoid overfetching
return (await resultRequestRepository.getLastResult(parent.feedFullName))
?.result
},
Expand All @@ -37,6 +38,7 @@ const resolvers = {
_args,
{ resultRequestRepository }: Context
) => {
// FIXME: add dataloader library to avoid overfetching
return (await resultRequestRepository.getLastResult(parent.feedFullName))
?.timestamp
},
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export function normalizeConfig (
return feeds
}

export function isZeroAddress (address: string) {
return address === '0x0000000000000000000000000000000000000000'
}

export function sleep (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
31 changes: 14 additions & 17 deletions packages/api/src/web3Middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ObjectId,
ContractInfo
} from '../types'
import { isZeroAddress } from '../utils/index'
import { getProvider } from './provider'

export class Web3Middleware {
Expand All @@ -29,26 +30,25 @@ export class Web3Middleware {
}

public async initializeAddresses (): Promise<Array<FeedInfo>> {
const promises = this.dataFeeds.map(feed => this.updateAddress(feed))
const promises = this.dataFeeds.map(feed => this.updateFeed(feed))

return await Promise.all(promises)
}

async updateAddress (feedInfo: FeedInfo) {
const contractInfo = await this.getContractAddress(feedInfo)
console.log('contractInfo in updateAddress', contractInfo)
async updateFeed (feedInfo: FeedInfo) {
const contractInfo = await this.getContractInfo(feedInfo)
const feed = this.repositories.feedRepository.get(feedInfo.feedFullName)

if (
feed &&
contractInfo &&
contractInfo.contractAddress &&
contractInfo.contractAddress !== feed.address
contractInfo?.contractAddress &&
contractInfo?.contractAddress !== feed?.address
) {
return this.repositories.feedRepository.updateFeedAddress(
feedInfo.feedFullName,
contractInfo.contractAddress,
contractInfo.contractId
{
address: contractInfo.contractAddress,
contractId: contractInfo.contractId
}
)
}

Expand Down Expand Up @@ -76,7 +76,7 @@ export class Web3Middleware {
feeds.forEach(feed => {
const feedInfo = feedDictionary[feed?.feedFullName]?.feedInfo
if (feedInfo) {
this.updateAddress(feedInfo)
this.updateFeed(feedInfo)
}
})

Expand All @@ -97,7 +97,7 @@ export class Web3Middleware {
this.intervals = []
}

async getContractAddress (feedInfo: FeedInfo): Promise<ContractInfo | null> {
async getContractInfo (feedInfo: FeedInfo): Promise<ContractInfo | null> {
try {
return await new Promise(async (resolve, reject) => {
try {
Expand All @@ -117,7 +117,6 @@ export class Web3Middleware {
const contractIdentifier = await feedContract.methods
.currencyPairId(feedInfo.id)
.call()
console.log('contract Identifier!!!', feedInfo.id, contractIdentifier)
const address = await feedContract.methods
.getPriceFeed(contractIdentifier)
.call()
Expand All @@ -139,15 +138,13 @@ export class Web3Middleware {
}

async listenToDataFeed (feedInfo: FeedInfo) {
const contractInfo = await this.getContractAddress(feedInfo)
const contractInfo = await this.getContractInfo(feedInfo)
const provider = getProvider(feedInfo.network)
if (provider) {
console.log('contractInfo in listenToDataFeed', contractInfo)
if (
contractInfo &&
contractInfo.contractAddress &&
contractInfo.contractAddress !==
'0x0000000000000000000000000000000000000000'
!isZeroAddress(contractInfo.contractAddress)
) {
try {
const web3 = new this.Web3(provider)
Expand Down
Loading

0 comments on commit f2c0bf0

Please sign in to comment.