@@ -8,7 +8,7 @@ import { HomeAddress, SepaInfo } from '../../../types/FormTypes'
8
8
import { StringMap } from '../../../types/types'
9
9
import { utf8 } from '../../../util/encoding'
10
10
import { removeIsoPrefix } from '../../../util/utils'
11
- import { FiatPaymentType , FiatPluginUi } from '../fiatPluginTypes'
11
+ import { FiatDirection , FiatPaymentType , FiatPluginUi } from '../fiatPluginTypes'
12
12
import {
13
13
FiatProvider ,
14
14
FiatProviderApproveQuoteParams ,
@@ -31,7 +31,32 @@ const supportEmail = 'support_edge@bity.com'
31
31
const supportedPaymentType : FiatPaymentType = 'sepa'
32
32
const partnerFee = 0.005
33
33
34
- const allowedCurrencyCodes : FiatProviderAssetMap = { providerId, crypto : { } , fiat : { } }
34
+ const allowedCurrencyCodes : Record < FiatDirection , FiatProviderAssetMap > = {
35
+ buy : { providerId, fiat : { } , crypto : { } } ,
36
+ sell : { providerId, fiat : { } , crypto : { } }
37
+ }
38
+
39
+ const noKycCurrencyCodes : Record < FiatDirection , FiatProviderAssetMap > = {
40
+ buy : {
41
+ providerId,
42
+ fiat : { } ,
43
+ crypto : {
44
+ bitcoin : [ { tokenId : null } ] ,
45
+ ethereum : [ { tokenId : null } ] ,
46
+ litecoin : [ { tokenId : null } ]
47
+ }
48
+ } ,
49
+ sell : {
50
+ providerId,
51
+ fiat : { } ,
52
+ crypto : {
53
+ bitcoin : [ { tokenId : null } ] ,
54
+ // Add USDT and USDC for no-KYC sell
55
+ ethereum : [ { tokenId : null } , { tokenId : 'dac17f958d2ee523a2206206994597c13d831ec7' } , { tokenId : 'a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' } ]
56
+ }
57
+ }
58
+ }
59
+
35
60
const allowedCountryCodes : { readonly [ code : string ] : boolean } = {
36
61
AT : true ,
37
62
BE : true ,
@@ -68,7 +93,9 @@ const allowedCountryCodes: { readonly [code: string]: boolean } = {
68
93
const CURRENCY_PLUGINID_MAP : StringMap = {
69
94
BTC : 'bitcoin' ,
70
95
ETH : 'ethereum' ,
71
- LTC : 'litecoin'
96
+ LTC : 'litecoin' ,
97
+ USDC : 'ethereum' ,
98
+ USDT : 'ethereum'
72
99
}
73
100
74
101
const EDGE_CLIENT_ID = '4949bf59-c23c-4d71-949e-f5fd56ff815b'
@@ -346,14 +373,14 @@ export const bityProvider: FiatProviderFactory = {
346
373
providerId,
347
374
partnerIcon,
348
375
pluginDisplayName,
349
- getSupportedAssets : async ( { paymentTypes } ) : Promise < FiatProviderAssetMap > => {
376
+ getSupportedAssets : async ( { direction , paymentTypes } ) : Promise < FiatProviderAssetMap > => {
350
377
// Return nothing if 'sepa' is not included in the props
351
378
if ( ! paymentTypes . includes ( supportedPaymentType ) ) throw new FiatProviderError ( { providerId, errorType : 'paymentUnsupported' } )
352
379
353
380
const response = await fetch ( `https://exchange.api.bity.com/v2/currencies` ) . catch ( e => undefined )
354
381
if ( response == null || ! response . ok ) {
355
382
console . error ( `Bity getSupportedAssets response error: ${ await response ?. text ( ) } ` )
356
- return allowedCurrencyCodes
383
+ return allowedCurrencyCodes [ direction ]
357
384
}
358
385
359
386
const result = await response . json ( )
@@ -362,23 +389,23 @@ export const bityProvider: FiatProviderFactory = {
362
389
bityCurrencies = asBityCurrencyResponse ( result ) . currencies
363
390
} catch ( error : any ) {
364
391
console . error ( error )
365
- return allowedCurrencyCodes
392
+ return allowedCurrencyCodes [ direction ]
366
393
}
367
394
for ( const currency of bityCurrencies ) {
368
395
let isAddCurrencySuccess = false
369
396
if ( currency . tags . length === 1 && currency . tags [ 0 ] === 'fiat' ) {
370
- allowedCurrencyCodes . fiat [ 'iso:' + currency . code . toUpperCase ( ) ] = currency
397
+ allowedCurrencyCodes [ direction ] . fiat [ 'iso:' + currency . code . toUpperCase ( ) ] = currency
371
398
isAddCurrencySuccess = true
372
399
} else if ( currency . tags . includes ( 'crypto' ) ) {
373
400
// Bity reports cryptos with a set of multiple tags such that there is
374
401
// overlap, such as USDC being 'crypto', 'ethereum', 'erc20'.
375
402
if ( currency . tags . includes ( 'erc20' ) && currency . tags . includes ( 'ethereum' ) ) {
376
403
// ETH tokens
377
- addToAllowedCurrencies ( getTokenId , 'ethereum' , currency , currency . code )
404
+ addToAllowedCurrencies ( direction , getTokenId , 'ethereum' , currency , currency . code )
378
405
isAddCurrencySuccess = true
379
406
} else if ( Object . keys ( CURRENCY_PLUGINID_MAP ) . includes ( currency . code ) ) {
380
407
// Mainnet currencies
381
- addToAllowedCurrencies ( getTokenId , CURRENCY_PLUGINID_MAP [ currency . code ] , currency , currency . code )
408
+ addToAllowedCurrencies ( direction , getTokenId , CURRENCY_PLUGINID_MAP [ currency . code ] , currency , currency . code )
382
409
isAddCurrencySuccess = true
383
410
}
384
411
}
@@ -387,7 +414,7 @@ export const bityProvider: FiatProviderFactory = {
387
414
if ( ! isAddCurrencySuccess ) console . log ( 'Unhandled Bity supported currency: ' , currency )
388
415
}
389
416
390
- return allowedCurrencyCodes
417
+ return allowedCurrencyCodes [ direction ]
391
418
} ,
392
419
getQuote : async ( params : FiatProviderGetQuoteParams ) : Promise < FiatProviderQuote > => {
393
420
const {
@@ -405,9 +432,9 @@ export const bityProvider: FiatProviderFactory = {
405
432
if ( ! allowedCountryCodes [ regionCode . countryCode ] ) throw new FiatProviderError ( { providerId, errorType : 'regionRestricted' , displayCurrencyCode } )
406
433
if ( ! paymentTypes . includes ( supportedPaymentType ) ) throw new FiatProviderError ( { providerId, errorType : 'paymentUnsupported' } )
407
434
408
- const bityCurrency = allowedCurrencyCodes . crypto [ pluginId ] . find ( t => t . tokenId === tokenId )
435
+ const bityCurrency = allowedCurrencyCodes [ direction ] . crypto [ pluginId ] . find ( t => t . tokenId === tokenId )
409
436
const cryptoCurrencyObj = asBityCurrency ( bityCurrency ?. otherInfo )
410
- const fiatCurrencyObj = asBityCurrency ( allowedCurrencyCodes . fiat [ fiatCurrencyCode ] )
437
+ const fiatCurrencyObj = asBityCurrency ( allowedCurrencyCodes [ direction ] . fiat [ fiatCurrencyCode ] )
411
438
412
439
if ( cryptoCurrencyObj == null || fiatCurrencyObj == null ) throw new Error ( 'Bity: Could not query supported currencies' )
413
440
const cryptoCode = cryptoCurrencyObj . code
@@ -603,12 +630,24 @@ export const bityProvider: FiatProviderFactory = {
603
630
}
604
631
}
605
632
606
- const addToAllowedCurrencies = ( getTokenId : FiatProviderGetTokenId , pluginId : string , currency : BityCurrency , currencyCode : string ) => {
607
- if ( allowedCurrencyCodes . crypto [ pluginId ] == null ) allowedCurrencyCodes . crypto [ pluginId ] = [ ]
633
+ const addToAllowedCurrencies = (
634
+ direction : FiatDirection ,
635
+ getTokenId : FiatProviderGetTokenId ,
636
+ pluginId : string ,
637
+ currency : BityCurrency ,
638
+ currencyCode : string
639
+ ) => {
640
+ if ( allowedCurrencyCodes [ direction ] . crypto [ pluginId ] == null ) allowedCurrencyCodes [ direction ] . crypto [ pluginId ] = [ ]
608
641
const tokenId = getTokenId ( pluginId , currencyCode )
609
642
if ( tokenId === undefined ) return
610
643
611
- const tokens = allowedCurrencyCodes . crypto [ pluginId ]
644
+ const tokens = allowedCurrencyCodes [ direction ] . crypto [ pluginId ]
645
+
646
+ // If token is not in the no-KYC list do not add it
647
+ const list = noKycCurrencyCodes [ direction ] . crypto [ pluginId ]
648
+ if ( list == null || ! list . some ( t => t . tokenId === tokenId ) ) {
649
+ return
650
+ }
612
651
addTokenToArray ( { tokenId, otherInfo : currency } , tokens )
613
652
}
614
653
0 commit comments