Skip to content

Commit ef24faa

Browse files
committed
Restrict bity to no-KYC assets
1 parent 27192d0 commit ef24faa

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- changed: Restrict Bity buy/sell to no-KYC asset
6+
57
## 4.12.0
68

79
- added: `CryptoIcon` logo support to displayed request QR codes

src/plugins/gui/providers/bityProvider.ts

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { HomeAddress, SepaInfo } from '../../../types/FormTypes'
88
import { StringMap } from '../../../types/types'
99
import { utf8 } from '../../../util/encoding'
1010
import { removeIsoPrefix } from '../../../util/utils'
11-
import { FiatPaymentType, FiatPluginUi } from '../fiatPluginTypes'
11+
import { FiatDirection, FiatPaymentType, FiatPluginUi } from '../fiatPluginTypes'
1212
import {
1313
FiatProvider,
1414
FiatProviderApproveQuoteParams,
@@ -31,7 +31,32 @@ const supportEmail = 'support_edge@bity.com'
3131
const supportedPaymentType: FiatPaymentType = 'sepa'
3232
const partnerFee = 0.005
3333

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+
3560
const allowedCountryCodes: { readonly [code: string]: boolean } = {
3661
AT: true,
3762
BE: true,
@@ -68,7 +93,9 @@ const allowedCountryCodes: { readonly [code: string]: boolean } = {
6893
const CURRENCY_PLUGINID_MAP: StringMap = {
6994
BTC: 'bitcoin',
7095
ETH: 'ethereum',
71-
LTC: 'litecoin'
96+
LTC: 'litecoin',
97+
USDC: 'ethereum',
98+
USDT: 'ethereum'
7299
}
73100

74101
const EDGE_CLIENT_ID = '4949bf59-c23c-4d71-949e-f5fd56ff815b'
@@ -346,14 +373,14 @@ export const bityProvider: FiatProviderFactory = {
346373
providerId,
347374
partnerIcon,
348375
pluginDisplayName,
349-
getSupportedAssets: async ({ paymentTypes }): Promise<FiatProviderAssetMap> => {
376+
getSupportedAssets: async ({ direction, paymentTypes }): Promise<FiatProviderAssetMap> => {
350377
// Return nothing if 'sepa' is not included in the props
351378
if (!paymentTypes.includes(supportedPaymentType)) throw new FiatProviderError({ providerId, errorType: 'paymentUnsupported' })
352379

353380
const response = await fetch(`https://exchange.api.bity.com/v2/currencies`).catch(e => undefined)
354381
if (response == null || !response.ok) {
355382
console.error(`Bity getSupportedAssets response error: ${await response?.text()}`)
356-
return allowedCurrencyCodes
383+
return allowedCurrencyCodes[direction]
357384
}
358385

359386
const result = await response.json()
@@ -362,23 +389,23 @@ export const bityProvider: FiatProviderFactory = {
362389
bityCurrencies = asBityCurrencyResponse(result).currencies
363390
} catch (error: any) {
364391
console.error(error)
365-
return allowedCurrencyCodes
392+
return allowedCurrencyCodes[direction]
366393
}
367394
for (const currency of bityCurrencies) {
368395
let isAddCurrencySuccess = false
369396
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
371398
isAddCurrencySuccess = true
372399
} else if (currency.tags.includes('crypto')) {
373400
// Bity reports cryptos with a set of multiple tags such that there is
374401
// overlap, such as USDC being 'crypto', 'ethereum', 'erc20'.
375402
if (currency.tags.includes('erc20') && currency.tags.includes('ethereum')) {
376403
// ETH tokens
377-
addToAllowedCurrencies(getTokenId, 'ethereum', currency, currency.code)
404+
addToAllowedCurrencies(direction, getTokenId, 'ethereum', currency, currency.code)
378405
isAddCurrencySuccess = true
379406
} else if (Object.keys(CURRENCY_PLUGINID_MAP).includes(currency.code)) {
380407
// 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)
382409
isAddCurrencySuccess = true
383410
}
384411
}
@@ -387,7 +414,7 @@ export const bityProvider: FiatProviderFactory = {
387414
if (!isAddCurrencySuccess) console.log('Unhandled Bity supported currency: ', currency)
388415
}
389416

390-
return allowedCurrencyCodes
417+
return allowedCurrencyCodes[direction]
391418
},
392419
getQuote: async (params: FiatProviderGetQuoteParams): Promise<FiatProviderQuote> => {
393420
const {
@@ -405,9 +432,9 @@ export const bityProvider: FiatProviderFactory = {
405432
if (!allowedCountryCodes[regionCode.countryCode]) throw new FiatProviderError({ providerId, errorType: 'regionRestricted', displayCurrencyCode })
406433
if (!paymentTypes.includes(supportedPaymentType)) throw new FiatProviderError({ providerId, errorType: 'paymentUnsupported' })
407434

408-
const bityCurrency = allowedCurrencyCodes.crypto[pluginId].find(t => t.tokenId === tokenId)
435+
const bityCurrency = allowedCurrencyCodes[direction].crypto[pluginId].find(t => t.tokenId === tokenId)
409436
const cryptoCurrencyObj = asBityCurrency(bityCurrency?.otherInfo)
410-
const fiatCurrencyObj = asBityCurrency(allowedCurrencyCodes.fiat[fiatCurrencyCode])
437+
const fiatCurrencyObj = asBityCurrency(allowedCurrencyCodes[direction].fiat[fiatCurrencyCode])
411438

412439
if (cryptoCurrencyObj == null || fiatCurrencyObj == null) throw new Error('Bity: Could not query supported currencies')
413440
const cryptoCode = cryptoCurrencyObj.code
@@ -603,12 +630,24 @@ export const bityProvider: FiatProviderFactory = {
603630
}
604631
}
605632

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] = []
608641
const tokenId = getTokenId(pluginId, currencyCode)
609642
if (tokenId === undefined) return
610643

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+
}
612651
addTokenToArray({ tokenId, otherInfo: currency }, tokens)
613652
}
614653

0 commit comments

Comments
 (0)