Skip to content

Commit

Permalink
Change prices request url
Browse files Browse the repository at this point in the history
  • Loading branch information
samchuk-vlad committed Jan 19, 2024
1 parent f66e55d commit ee7c62e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export const validatorsStakingNetworks = [
]

export const VALIDATOR_STAKING_REWARDS_API_KEY = 'f00511ab0c5e422796b8f5d9c7029fbe'
export const ONFINALITY_API_KEY = 'e75486ad-bbb5-4b93-8699-3123f8dbabc5'
// export const ONFINALITY_API_KEY = 'e75486ad-bbb5-4b93-8699-3123f8dbabc5'

// export const ONFINALITY_API_KEY = '28209e0e-fc76-481e-a80f-745ffdf477d7' // test api key for localhost
export const ONFINALITY_API_KEY = '28209e0e-fc76-481e-a80f-745ffdf477d7' // test api key for localhost


export const SUBSOCIAL_GRAPHQL_CLIENT = 'https://squid.subsquid.io/subsocial/graphql'
Expand Down
34 changes: 17 additions & 17 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ export const startHttpServer = (apis: Connections) => {

app.use(express.static('public'))

app.use(
cors((req, callback) => {
const corsOptions = { origin: true }
const origin = req.header('Origin')
const isAllowedOrigin = allowedOrigins.some((allowedOrigin) =>
origin?.includes(allowedOrigin)
)
if (!isAllowedOrigin) {
corsOptions.origin = false
}
callback(null, corsOptions)
})
)

// For localhost testing
// app.use(
// cors((req, callback) => {
// const origin = req.method === 'GET' ? '*' : '*'
// callback(null, { origin })
// const corsOptions = { origin: true }
// const origin = req.header('Origin')
// const isAllowedOrigin = allowedOrigins.some((allowedOrigin) =>
// origin?.includes(allowedOrigin)
// )
// if (!isAllowedOrigin) {
// corsOptions.origin = false
// }
// callback(null, corsOptions)
// })
// )

// For localhost testing
app.use(
cors((req, callback) => {
const origin = req.method === 'GET' ? '*' : '*'
callback(null, { origin })
})
)

function haltOnTimedout(req: express.Request, _res: express.Response, next) {
if (!req.timedout) next()
}
Expand Down
18 changes: 2 additions & 16 deletions src/services/prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FIVE_MINUTES } from '../constant/index'
import Cache from '../cache'

const cacheKey = 'prices'
const coingeckoUrl = 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd'
const coingeckoUrl = 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&price_change_percentage==24h'

const pricesCache = new Cache<any>('prices', FIVE_MINUTES)

Expand All @@ -19,23 +19,9 @@ const fetchPrices = async (ids: string) => {

const newPrices = await axiosGetRequest(`${coingeckoUrl}&ids=${ids}`, { timeout: 5000 })

const subsocialTokenPrice = await axiosGetRequest(
'https://api.hydradx.io/hydradx-ui/v1/stats/price/24',
{ timeout: 5000 }
)

const subsocialTokenPriceObj = subsocialTokenPrice
? {
id: 'subsocial',
symbol: 'sub',
name: 'Subsocial',
current_price: subsocialTokenPrice?.[0]?.price_usd
}
: {}

const newData = newPrices
? {
values: [ ...newPrices, subsocialTokenPriceObj ],
values: newPrices,
isCachedData: false,
lastUpdate: new Date().getTime()
}
Expand Down

0 comments on commit ee7c62e

Please sign in to comment.