Skip to content

Commit

Permalink
package.json: update FiatApi for differentiation of history supported…
Browse files Browse the repository at this point in the history
… CryptoCompare currencies

Unfortunately, not all currencies that CryptoCompare supports for current exchange rates
are also supported for historic rates.
  • Loading branch information
danimoh committed Apr 26, 2024
1 parent 563a6e4 commit e4b502b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@nimiq/rpc": "^0.4.1",
"@nimiq/style": "^0.8.2",
"@nimiq/ten31-pass-api": "^1.1.0",
"@nimiq/utils": "^0.11.0",
"@nimiq/utils": "^0.11.1",
"@nimiq/vue-components": "https://github.com/nimiq/vue-components#build/wallet",
"@opengsn/common": "^2.2.5",
"@sentry/vue": "^6.0.0",
Expand Down
34 changes: 21 additions & 13 deletions src/stores/Fiat.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createStore } from 'pinia';
import {
Provider,
RateType,
getExchangeRates,
isHistorySupportedFiatCurrency,
isProviderSupportedFiatCurrency,
isBridgedFiatCurrency,
isHistorySupportedFiatCurrency,
// setCoinGeckoApiUrl,
} from '@nimiq/utils';
import {
Expand Down Expand Up @@ -87,13 +89,13 @@ export const useFiatStore = createStore({
async updateExchangeRates(failGracefully = true) {
try {
const currentCurrency = this.state.currency;
const isCurrentCurrencyCplBridged = !isHistorySupportedFiatCurrency(
currentCurrency,
// Not FIAT_API_PROVIDER_TX_HISTORY because we're checking here whether the provider for current
// exchange rates does not hypothetically support historic rates for the current currency, in which
// case it's a currency bridged via the CPL API, which does not support historic rates.
// If a currency is bridged, but not by a bridge that supports historic rates, it's bridged via CPL Api.
const isCplBridgedFiatCurrency = (currency: FiatCurrency) => isBridgedFiatCurrency(
currency,
FIAT_API_PROVIDER_CURRENT_PRICES,
);
RateType.CURRENT,
) && !isHistorySupportedFiatCurrency(currency, FIAT_API_PROVIDER_CURRENT_PRICES);
const isCurrentCurrencyCplBridged = isCplBridgedFiatCurrency(currentCurrency);
const prioritizedFiatCurrenciesOffered: Array<FiatCurrencyOffered> = [...new Set<FiatCurrencyOffered>([
// As we limit the currencies we fetch for CryptoCompare to 25, prioritize a few currencies, we'd
// prefer to be included, roughly the highest market cap currencies according to fiatmarketcap.com,
Expand All @@ -104,8 +106,11 @@ export const useFiatStore = createStore({
// After that, prefer to include currencies CryptoCompare supports historic rates for, because it is
// for CryptoCompare that we limit the number of currencies to update. For CoinGecko, all currencies
// can be updated in a single request.
...FIAT_CURRENCIES_OFFERED
.filter((currency) => isProviderSupportedFiatCurrency(currency, Provider.CryptoCompare)),
...FIAT_CURRENCIES_OFFERED.filter((currency) => isProviderSupportedFiatCurrency(
currency,
Provider.CryptoCompare,
RateType.HISTORIC,
)),
// Finally, all the remaining currencies
...FIAT_CURRENCIES_OFFERED,
])];
Expand All @@ -116,11 +121,14 @@ export const useFiatStore = createStore({
// provider api, either because it's a directly supported currency, or because it's a currency
// bridged via USD, also fetched from the provider, and fetching multiple currencies vs. only
// one still counts as only one api request.
&& !isProviderSupportedFiatCurrency(currency, FIAT_API_PROVIDER_CURRENT_PRICES)
&& !isProviderSupportedFiatCurrency(
currency,
FIAT_API_PROVIDER_CURRENT_PRICES,
RateType.CURRENT,
)
// If current currency is a CPL bridged currency, we can include other CPL bridged currencies
// (checked via isHistorySupportedFiatCurrency, see above) without additional API request.
&& !(isCurrentCurrencyCplBridged
&& /* is CPL */ !isHistorySupportedFiatCurrency(currency, FIAT_API_PROVIDER_CURRENT_PRICES))
// without additional API request.
&& !(isCurrentCurrencyCplBridged && isCplBridgedFiatCurrency(currency))
) continue; // omit currency
currenciesToUpdate.push(currency);
// @ts-expect-error provider check on purpose as we might want to change it in the future
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1552,10 +1552,10 @@
resolved "https://registry.yarnpkg.com/@nimiq/ten31-pass-api/-/ten31-pass-api-1.1.0.tgz#4e013dd23302304965ac032e521d38a25b186a24"
integrity sha512-YLxzRyJcg/0xPMMBl+TcIugm8SdSitWZXEhotXK8wIj/wbtRQEbUoo052JCfpWJXVTsGDNS0VbS9oLA+fuFm1A==

"@nimiq/utils@^0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@nimiq/utils/-/utils-0.11.0.tgz#ef4a14025d2ebfcf66c95c797e615a52afed0149"
integrity sha512-/2T6sezu515PjmTVezVGC3+IHivwumT2oLZuRErRpEywC+J2RTiEt/elWSkK/a5RtAFtGdXgTIAhW5g8jB3fqQ==
"@nimiq/utils@^0.11.1":
version "0.11.1"
resolved "https://registry.yarnpkg.com/@nimiq/utils/-/utils-0.11.1.tgz#fe9c61fdead9b8e25a892a539b2b870cdd9cc51c"
integrity sha512-jwRInTkMPzyPsQN3iyf8s82mO/ChnbVtj5IzqXj9EO0PSOPd4Ix2ApIN/3NClfDfWo6HzE6NkSZOgry18p4jow==
dependencies:
big-integer "^1.6.44"

Expand Down

0 comments on commit e4b502b

Please sign in to comment.