Skip to content

Commit

Permalink
Filter out zeroRates and fallbackConstantRates
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodluckH committed Jul 11, 2022
1 parent 0e6c055 commit a3398cd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/rates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ const sanitizeNewRates = (

const getRatesFromProviders = async (
rateObj: ReturnGetRate,
edgeAssetMap: DbDoc
edgeAssetMap: DbDoc,
excludedProviders: string[] = []
): Promise<ReturnGetRate> => {
const currentTime = normalizeDate(new Date().toISOString())
if (typeof currentTime !== 'string') throw new Error('malformed date')
Expand All @@ -140,7 +141,10 @@ const getRatesFromProviders = async (
if (constantCurrencyCodes == null)
({ constantCurrencyCodes = {} } = edgeAssetMap)

for (const provider of rateProviders) {
const eligibleProviders = rateProviders.filter(
provider => !excludedProviders.includes(provider.name)
)
for (const provider of eligibleProviders) {
const remainingRequests = getNullRateArray(rateObj.data)
if (remainingRequests.length === 0) break

Expand Down Expand Up @@ -196,7 +200,8 @@ export const getExchangeRates = async (

const out = await getRatesFromProviders(
{ data, documents: documents.slice(1) },
documents[0]
documents[0],
['zeroRates', 'fallbackConstantRates']
)

const redisPromises: Array<Promise<number>> = []
Expand Down

0 comments on commit a3398cd

Please sign in to comment.