113113type BigInteger = import (' big-integer' ).BigInteger ;
114114
115115import { Component , Mixins , Prop , Watch } from ' vue-property-decorator' ;
116- import { FiatApiSupportedFiatCurrency , FiatApiSupportedCryptoCurrency , getExchangeRates } from ' @nimiq/utils' ;
116+ import { FiatCurrency , CryptoCurrency , Provider as FiatApiProvider , getExchangeRates } from ' @nimiq/utils' ;
117117import Account from ' ./Account.vue' ;
118118import Timer from ' ./Timer.vue' ;
119119import Amount , { amountValidator } from ' ./Amount.vue' ;
@@ -134,6 +134,12 @@ interface FiatAmountInfo {
134134 currency: string ;
135135}
136136
137+ // As Record, such that ts will warn us if the url for a provider is missing.
138+ const FIAT_API_PROVIDER_URLS: Record <FiatApiProvider , string > = {
139+ [FiatApiProvider .CoinGecko ]: ' coingecko.com' ,
140+ [FiatApiProvider .CryptoCompare ]: ' cryptocompare.com' ,
141+ };
142+
137143function cryptoAmountInfoValidator(value : any ) {
138144 return ' amount' in value && ' currency' in value && ' decimals' in value
139145 && amountValidator (value .amount )
@@ -166,6 +172,12 @@ class PaymentInfoLine extends Mixins(I18nMixin) {
166172
167173 @Prop ({type: Object , required: true , validator: cryptoAmountInfoValidator }) public cryptoAmount! : CryptoAmountInfo ;
168174 @Prop ({type: Object , validator: fiatAmountInfoValidator }) public fiatAmount? : FiatAmountInfo ;
175+ @Prop ({
176+ type: String ,
177+ validator : (value : any ) => Object .values (FiatApiProvider ).includes (value ),
178+ default: FiatApiProvider .CoinGecko ,
179+ })
180+ public fiatApiProvider! : FiatApiProvider ;
169181 // Note that vendorMarkup and networkFee have no effect if fiatAmount is not set, as the tooltip in which they
170182 // appear is only visible when fiatAmount is set. As the fiatAmount was only introduced in the v2 checkout request
171183 // in the Hub, the tooltip and vendorMarkup and networkFee are thus never visible for v1 checkout requests. This
@@ -262,26 +274,30 @@ class PaymentInfoLine extends Mixins(I18nMixin) {
262274 || (Math .abs (this .rateDeviation ) < PaymentInfoLine .RATE_DEVIATION_THRESHOLD && ! this .isBadRate )) {
263275 return null ;
264276 }
277+ const translationVariables = {
278+ formattedRateDeviation: this .formattedRateDeviation ,
279+ provider: FIAT_API_PROVIDER_URLS [this .fiatApiProvider ],
280+ };
265281 if (this .rateDeviation < 0 && this .isBadRate ) {
266282 // False discount
267283 return this .$t (
268284 ' Your actual discount is approx. {formattedRateDeviation} compared '
269- + ' to the current market rate (coingecko.com ).' ,
270- { formattedRateDeviation: this . formattedRateDeviation } ,
285+ + ' to the current market rate ({provider} ).' ,
286+ translationVariables ,
271287 );
272288 }
273289
274290 if (this .rateDeviation > 0 ) {
275291 return this .$t (
276292 ' You are paying approx. {formattedRateDeviation} more '
277- + ' than at the current market rate (coingecko.com ).' ,
278- { formattedRateDeviation: this . formattedRateDeviation } ,
293+ + ' than at the current market rate ({provider} ).' ,
294+ translationVariables ,
279295 );
280296 } else {
281297 return this .$t (
282298 ' You are paying approx. {formattedRateDeviation} less '
283- + ' than at the current market rate (coingecko.com ).' ,
284- { formattedRateDeviation: this . formattedRateDeviation } ,
299+ + ' than at the current market rate ({provider} ).' ,
300+ translationVariables ,
285301 );
286302 }
287303
@@ -291,20 +307,18 @@ class PaymentInfoLine extends Mixins(I18nMixin) {
291307 @Watch (' fiatAmount.currency' )
292308 private async updateReferenceRate() {
293309 window .clearTimeout (this .referenceRateUpdateTimeout );
294- const cryptoCurrency = this .cryptoAmount .currency .toLowerCase () as FiatApiSupportedCryptoCurrency ;
295- const fiatCurrency = this .fiatAmount
296- ? this .fiatAmount .currency .toLowerCase () as FiatApiSupportedFiatCurrency
297- : null ;
310+ const cryptoCurrency = this .cryptoAmount .currency .toLowerCase () as CryptoCurrency ;
311+ const fiatCurrency = this .fiatAmount ?.currency .toLowerCase () as FiatCurrency | undefined ;
298312 if (! this .fiatAmount
299- || ! Object .values (FiatApiSupportedFiatCurrency ).includes (fiatCurrency )
300- || ! Object .values (FiatApiSupportedCryptoCurrency ).includes (cryptoCurrency )
313+ || ! Object .values (FiatCurrency ).includes (fiatCurrency )
314+ || ! Object .values (CryptoCurrency ).includes (cryptoCurrency )
301315 ) {
302316 this .referenceRate = null ;
303317 return ;
304318 }
305319
306320 const { [cryptoCurrency ]: { [fiatCurrency ]: referenceRate }} =
307- await getExchangeRates ([cryptoCurrency ], [fiatCurrency ]);
321+ await getExchangeRates ([cryptoCurrency ], [fiatCurrency ], this . fiatApiProvider );
308322 this .referenceRate = referenceRate || null ;
309323
310324 this .referenceRateUpdateTimeout = window .setTimeout (
0 commit comments