@@ -66,6 +66,16 @@ export function guessUserCurrency(regionOverwrite?: string) {
66
66
return FiatCurrency . USD ;
67
67
}
68
68
69
+ export type UpdateExchangeRatesOptions = {
70
+ // The currency to load
71
+ // @default this.state.currency
72
+ fiatCurrency ?: FiatCurrencyOffered ,
73
+
74
+ // If true, the function will not throw an error if the exchange rate update fails.
75
+ // @default true
76
+ failGracefully ?: boolean ,
77
+ }
78
+
69
79
export const useFiatStore = createStore ( {
70
80
id : 'fiat' ,
71
81
state : ( ) : FiatState => ( {
@@ -86,21 +96,21 @@ export const useFiatStore = createStore({
86
96
useBtcTransactionsStore ( ) . calculateFiatAmounts ( ) ;
87
97
useUsdcTransactionsStore ( ) . calculateFiatAmounts ( ) ;
88
98
} ,
89
- async updateExchangeRates ( failGracefully = true ) {
99
+ async updateExchangeRates ( options : UpdateExchangeRatesOptions = { } ) {
100
+ const { failGracefully = true , fiatCurrency = this . state . currency } = options ;
90
101
try {
91
- const currentCurrency = this . state . currency ;
92
102
// If a currency is bridged, but not by a bridge that supports historic rates, it's bridged via CPL Api.
93
103
const isCplBridgedFiatCurrency = ( currency : FiatCurrency ) => isBridgedFiatCurrency (
94
104
currency ,
95
105
FIAT_API_PROVIDER_CURRENT_PRICES ,
96
106
RateType . CURRENT ,
97
107
) && ! isHistorySupportedFiatCurrency ( currency , FIAT_API_PROVIDER_CURRENT_PRICES ) ;
98
- const isCurrentCurrencyCplBridged = isCplBridgedFiatCurrency ( currentCurrency ) ;
108
+ const isCurrentCurrencyCplBridged = isCplBridgedFiatCurrency ( fiatCurrency ) ;
99
109
const prioritizedFiatCurrenciesOffered : Array < FiatCurrencyOffered > = [ ...new Set < FiatCurrencyOffered > ( [
100
110
// As we limit the currencies we fetch for CryptoCompare to 25, prioritize a few currencies, we'd
101
111
// prefer to be included, roughly the highest market cap currencies according to fiatmarketcap.com,
102
112
// plus some smaller currencies for which Nimiq has strong communities.
103
- currentCurrency ,
113
+ fiatCurrency ,
104
114
...( [ 'USD' , 'CNY' , 'EUR' , 'JPY' , 'GBP' , 'KRW' , 'INR' , 'CAD' , 'HKD' , 'BRL' , 'AUD' , 'CRC' , 'GMD' ,
105
115
'XOF' ] as const ) . map ( ( ticker ) => FiatCurrency [ ticker ] ) ,
106
116
// After that, prefer to include currencies CryptoCompare supports historic rates for, because it is
@@ -116,7 +126,7 @@ export const useFiatStore = createStore({
116
126
] ) ] ;
117
127
const currenciesToUpdate : Array < FiatCurrencyOffered > = [ ] ;
118
128
for ( const currency of prioritizedFiatCurrenciesOffered ) {
119
- if ( currency !== currentCurrency
129
+ if ( currency !== fiatCurrency
120
130
// Include all provider supported currencies, as at least one always has to be fetched via the
121
131
// provider api, either because it's a directly supported currency, or because it's a currency
122
132
// bridged via USD, also fetched from the provider, and fetching multiple currencies vs. only
0 commit comments