@@ -20,6 +20,7 @@ import {
2020 FiatProviderGetQuoteParams ,
2121 FiatProviderQuote
2222} from '../fiatProviderTypes'
23+ import { makeCheckDue } from './common'
2324import { ProviderSupportStore } from './ProviderSupportStore'
2425
2526const providerId = 'bity'
@@ -364,6 +365,7 @@ export const bityProvider: FiatProviderFactory = {
364365 const { apiKeys, getTokenId } = params
365366 const clientId = asBityApiKeys ( apiKeys ) . clientId
366367
368+ const isCheckDue = makeCheckDue ( 1000 * 60 * 60 ) // 1 hour
367369 const supportedAssets = new ProviderSupportStore ( providerId )
368370
369371 // Bit supports buy and sell directions
@@ -397,55 +399,58 @@ export const bityProvider: FiatProviderFactory = {
397399 throw new FiatProviderError ( { providerId, errorType : 'paymentUnsupported' } )
398400 }
399401
400- const response = await fetch ( `https://exchange.api.bity.com/v2/currencies` ) . catch ( e => undefined )
401- if ( response == null || ! response . ok ) {
402- console . error ( `Bity getSupportedAssets response error: ${ await response ?. text ( ) } ` )
403- return supportedAssets . getFiatProviderAssetMap ( {
404- direction,
405- region,
406- payment
407- } )
408- }
402+ if ( isCheckDue ( ) ) {
403+ const response = await fetch ( `https://exchange.api.bity.com/v2/currencies` ) . catch ( e => undefined )
404+ if ( response == null || ! response . ok ) {
405+ console . error ( `Bity getSupportedAssets response error: ${ await response ?. text ( ) } ` )
406+ isCheckDue ( true )
407+ return supportedAssets . getFiatProviderAssetMap ( {
408+ direction,
409+ region,
410+ payment
411+ } )
412+ }
409413
410- const result = await response . json ( )
411- let bityCurrencies : BityCurrency [ ] = [ ]
412- try {
413- bityCurrencies = asBityCurrencyResponse ( result ) . currencies
414- } catch ( error : any ) {
415- console . error ( error )
416- return supportedAssets . getFiatProviderAssetMap ( {
417- direction,
418- region,
419- payment
420- } )
421- }
414+ const result = await response . json ( )
415+ let bityCurrencies : BityCurrency [ ] = [ ]
416+ try {
417+ bityCurrencies = asBityCurrencyResponse ( result ) . currencies
418+ } catch ( error : any ) {
419+ console . error ( error )
420+ return supportedAssets . getFiatProviderAssetMap ( {
421+ direction,
422+ region,
423+ payment
424+ } )
425+ }
422426
423- for ( const currency of bityCurrencies ) {
424- if ( currency . tags . length === 1 && currency . tags [ 0 ] === 'fiat' ) {
425- const fiatCurrencyCode = 'iso:' + currency . code . toUpperCase ( )
426- supportedAssets . add . direction ( '*' ) . region ( '*' ) . fiat ( fiatCurrencyCode ) . payment ( '*' )
427- supportedAssets . addFiatInfo ( fiatCurrencyCode , currency )
428- } else if ( currency . tags . includes ( 'crypto' ) ) {
429- // Bity reports cryptos with a set of multiple tags such that there is
430- // overlap, such as USDC being 'crypto', 'ethereum', 'erc20'.
431- const pluginId = currency . tags . includes ( 'erc20' ) && currency . tags . includes ( 'ethereum' ) ? 'ethereum' : CURRENCY_PLUGINID_MAP [ currency . code ]
432- if ( pluginId == null ) continue
433-
434- const tokenId = getTokenId ( pluginId , currency . code )
435- if ( tokenId === undefined ) continue
436-
437- // If token is not in the no-KYC list do not add it
438- const list = noKycCurrencyCodes [ direction ] . crypto [ pluginId ]
439- if ( list == null || ! list . some ( t => t . tokenId === tokenId ) ) {
440- continue
427+ for ( const currency of bityCurrencies ) {
428+ if ( currency . tags . length === 1 && currency . tags [ 0 ] === 'fiat' ) {
429+ const fiatCurrencyCode = 'iso:' + currency . code . toUpperCase ( )
430+ supportedAssets . add . direction ( '*' ) . region ( '*' ) . fiat ( fiatCurrencyCode ) . payment ( '*' )
431+ supportedAssets . addFiatInfo ( fiatCurrencyCode , currency )
432+ } else if ( currency . tags . includes ( 'crypto' ) ) {
433+ // Bity reports cryptos with a set of multiple tags such that there is
434+ // overlap, such as USDC being 'crypto', 'ethereum', 'erc20'.
435+ const pluginId = currency . tags . includes ( 'erc20' ) && currency . tags . includes ( 'ethereum' ) ? 'ethereum' : CURRENCY_PLUGINID_MAP [ currency . code ]
436+ if ( pluginId == null ) continue
437+
438+ const tokenId = getTokenId ( pluginId , currency . code )
439+ if ( tokenId === undefined ) continue
440+
441+ // If token is not in the no-KYC list do not add it
442+ const list = noKycCurrencyCodes [ direction ] . crypto [ pluginId ]
443+ if ( list == null || ! list . some ( t => t . tokenId === tokenId ) ) {
444+ continue
445+ }
446+
447+ const crypto = `${ pluginId } :${ tokenId } `
448+ supportedAssets . add . direction ( '*' ) . region ( '*' ) . fiat ( '*' ) . payment ( '*' ) . crypto ( crypto )
449+ supportedAssets . addCryptoInfo ( crypto , currency )
450+ } else {
451+ // Unhandled combination not caught by cleaner. Skip to be safe.
452+ console . log ( 'Unhandled Bity supported currency: ' , currency )
441453 }
442-
443- const crypto = `${ pluginId } :${ tokenId } `
444- supportedAssets . add . direction ( '*' ) . region ( '*' ) . fiat ( '*' ) . payment ( '*' ) . crypto ( crypto )
445- supportedAssets . addCryptoInfo ( crypto , currency )
446- } else {
447- // Unhandled combination not caught by cleaner. Skip to be safe.
448- console . log ( 'Unhandled Bity supported currency: ' , currency )
449454 }
450455 }
451456
0 commit comments