Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

- changed: Some unecessary `showError` dropdowns demoted to hidden `showDevError`
- changed: Restrict Bity buy/sell to no-KYC asset
- changed: Determine Moonpay asset support using chainCode/contractAddress
- changed: Allow reverse quotes for Kado
- changed: Credit card allowed countries to add Botswana, Cambodia, Panama, and Sri Lanka
- fixed: Default swap pair logic from the trade modal was not prioritizing mainnet assets
- removed: 'fasterpayments' payment type
- fixed: "FIO Address does not exist" error after transferring a FIO name
- removed: 'fasterpayments' payment type
- removed: Turking bank transfer support

## 4.12.0

Expand Down
6 changes: 5 additions & 1 deletion src/constants/plugins/buyPluginList.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"BA",
"BV",
"BR",
"BW",
"IO",
"BN",
"BG",
Expand Down Expand Up @@ -96,6 +97,7 @@
"GN",
"GW",
"GY",
"KH",
"HT",
"HM",
"VA",
Expand Down Expand Up @@ -126,6 +128,7 @@
"LR",
"LY",
"LI",
"LK",
"LT",
"LU",
"MO",
Expand Down Expand Up @@ -165,6 +168,7 @@
"MP",
"NO",
"OM",
"PA",
"PW",
"PS",
"PG",
Expand Down Expand Up @@ -395,7 +399,7 @@
"paymentTypes": ["turkishbank"],
"title": "Turkish Bank Transfer",
"description": "Fee: 8-9%\nSettlement: Instant - 1 hour",
"forCountries": ["TR"],
"forCountries": [],
"cryptoCodes": [],
"paymentTypeLogoKey": "bank"
},
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/gui/fiatProviderTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ export interface FiatProvider<OtherMethods = null> {
}

export type FiatProviderGetTokenId = (pluginId: string, currencyCode: string) => EdgeTokenId | undefined
export type FiatProviderGetTokenIdFromContract = (params: { pluginId: string; contractAddress: string }) => EdgeTokenId | undefined
export type FiatProviderMakeUuid = () => Promise<string>
export interface FiatProviderFactoryParams {
deviceId: string
io: { store: FiatProviderStore; makeUuid: FiatProviderMakeUuid }
getTokenId: FiatProviderGetTokenId
getTokenIdFromContract: FiatProviderGetTokenIdFromContract
apiKeys?: unknown // Data specific to the requirements of each provider,
// which lets the provider know that these orders were made from within Edge.
// Typically an API key, but can be some other information like a client ID.
Expand Down
52 changes: 32 additions & 20 deletions src/plugins/gui/providers/kadoProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ const allowedPaymentTypes: AllowedPaymentTypes = {
}
}

const allowedBuyCurrencyCodes: FiatProviderAssetMap = { providerId, requiredAmountType: 'fiat', crypto: {}, fiat: {} }
const allowedSellCurrencyCodes: FiatProviderAssetMap = { providerId, requiredAmountType: 'crypto', crypto: {}, fiat: {} }
const allowedBuyCurrencyCodes: FiatProviderAssetMap = { providerId, crypto: {}, fiat: {} }
const allowedSellCurrencyCodes: FiatProviderAssetMap = { providerId, crypto: {}, fiat: {} }
const allowedCountryCodes: { [code: string]: boolean } = { US: true }

/**
Expand Down Expand Up @@ -190,10 +190,10 @@ const asBlockchains = asObject({
*/

// Define cleaners for nested objects and properties
// const asAmountCurrency = asObject({
// amount: asNumber,
// currency: asString
// })
const asAmountCurrency = asObject({
amount: asNumber,
currency: asString
})

// const asRequest = asObject({
// transactionType: asValue('buy', 'sell'),
Expand All @@ -219,14 +219,14 @@ const asMinMaxValue = asObject({

const asQuote = asObject({
// asset: asString,
// baseAmount: asAmountCurrency,
baseAmount: asAmountCurrency,
// pricePerUnit: asNumber,
// price: asPrice,
// processingFee: asAmountCurrency,
// bridgeFee: asAmountCurrency,
// networkFee: asAmountCurrency,
// smartContractFee: asAmountCurrency,
// totalFee: asAmountCurrency,
totalFee: asAmountCurrency,
// receiveAmountAfterFees: asAmountCurrency,
// receiveUnitCountAfterFees: asAmountCurrency,
receive: asObject({
Expand Down Expand Up @@ -397,6 +397,7 @@ interface GetQuoteParams {
amount: number
blockchain: string
currency: string
reverse: boolean
asset: string
}

Expand Down Expand Up @@ -505,12 +506,6 @@ export const kadoProvider: FiatProviderFactory = {
const allowedCurrencyCodes = direction === 'buy' ? allowedBuyCurrencyCodes : allowedSellCurrencyCodes

if (!allowedCountryCodes[regionCode.countryCode]) throw new FiatProviderError({ providerId, errorType: 'regionRestricted', displayCurrencyCode })
if (direction === 'buy' && amountType !== 'fiat') {
throw new FiatProviderError({ providerId, errorType: 'assetUnsupported' })
}
if (direction === 'sell' && amountType !== 'crypto') {
throw new FiatProviderError({ providerId, errorType: 'assetUnsupported' })
}
if (!paymentTypes.some(paymentType => allowedPaymentTypes[direction][paymentType] === true))
throw new FiatProviderError({ providerId, errorType: 'paymentUnsupported' })

Expand All @@ -533,12 +528,15 @@ export const kadoProvider: FiatProviderFactory = {
throw new FiatProviderError({ providerId, errorType: 'paymentUnsupported' })
}

const reverse = (direction === 'sell' && amountType === 'fiat') || (direction === 'buy' && amountType === 'crypto')

const queryParams: GetQuoteParams = {
transactionType: direction,
fiatMethod,
amount: Number(exchangeAmount),
blockchain,
currency: 'USD',
reverse,
asset
}

Expand All @@ -561,17 +559,31 @@ export const kadoProvider: FiatProviderFactory = {

const { amount: minAmount, unit: minUnit } = quote.data.quote.minValue
const { amount: maxAmount, unit: maxUnit } = quote.data.quote.maxValue
const { baseAmount } = quote.data.quote

let fiatAmount: string
let cryptoAmount: string
const { totalFee } = quote.data.quote
const { amount, unitCount } = quote.data.quote.receive
if (direction === 'buy') {
const { unitCount } = quote.data.quote.receive
cryptoAmount = unitCount.toString()
fiatAmount = exchangeAmount
if (amountType === 'fiat') {
cryptoAmount = unitCount.toString()
fiatAmount = exchangeAmount
} else {
// For some reason, the totalFee is not included in the fiatAmount on buy reverse quotes
fiatAmount = (amount + totalFee.amount).toString()
cryptoAmount = exchangeAmount
}
} else {
const { amount } = quote.data.quote.receive
cryptoAmount = exchangeAmount
fiatAmount = amount.toString()
if (amountType === 'crypto') {
cryptoAmount = exchangeAmount
fiatAmount = amount.toString()
} else {
fiatAmount = exchangeAmount
// The unitCount is 0 for sell reverse quotes but seems to be in
// the baseAmount.amount so use that
cryptoAmount = baseAmount.amount.toString()
}
Comment on lines +562 to +586
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const quote = asQuoteResponse(result).data
// ...
cryptoAmount = quote.baseAmount.amount.toString()

Removing the destructuring will keep the context of where baseAmount came from.

It would also avoid the need to rename things like minAmount and minUnit when you can just use quote.minValue.amount and quote.minValue.unit. It's more to read where it's used, but it avoids needing to read paragraphs of destructuring and renaming.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I left the minAmount and minUnit as is to reduce modification of the existing code. For the baseAmount, the destructuring seems harmless as there is no ambiguity as to where it came from.

}
if (lt(fiatAmount, minAmount.toString()))
throw new FiatProviderError({ providerId, errorType: 'underLimit', errorAmount: minAmount, displayCurrencyCode: minUnit })
Expand Down
Loading
Loading