Skip to content

Commit

Permalink
Use Paybis public api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Oct 24, 2023
1 parent cbb9be1 commit cfedc25
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/plugins/gui/providers/paybisProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { locale } from '../../../locales/intl'
import { lstrings } from '../../../locales/strings'
import { EdgeTokenId, StringMap } from '../../../types/types'
import { makeUuid } from '../../../util/utils'
import { SendErrorBackPressed, SendErrorNoTransaction } from '../fiatPlugin'
import { SendErrorNoTransaction } from '../fiatPlugin'
import { FiatDirection, FiatPaymentType } from '../fiatPluginTypes'
import {
FiatProvider,
Expand Down Expand Up @@ -392,7 +392,7 @@ export const paybisProvider: FiatProviderFactory = {
paymentMethod: direction === 'buy' ? paymentMethod : undefined,
payoutMethod: direction === 'sell' ? paymentMethod : undefined
}
const response = await paybisFetch({ method: 'POST', url, path: 'v2/quote', apiKey, bodyParams })
const response = await paybisFetch({ method: 'POST', url, path: 'v2/public/quote', apiKey, bodyParams })
const { id: quoteId, paymentMethods, paymentMethodErrors, payoutMethods, payoutMethodErrors } = asQuote(response)

const pmErrors = paymentMethodErrors ?? payoutMethodErrors
Expand Down Expand Up @@ -485,7 +485,7 @@ export const paybisProvider: FiatProviderFactory = {
}
}

const response = await paybisFetch({ method: 'POST', url, path: 'v2/request', apiKey, bodyParams })
const response = await paybisFetch({ method: 'POST', url, path: 'v2/public/request', apiKey, bodyParams })
const { requestId } = response

const widgetUrl = isWalletTestnet(coreWallet) ? WIDGET_URL_SANDBOX : WIDGET_URL
Expand Down Expand Up @@ -606,21 +606,19 @@ const paybisFetch = async (params: {
path: string
apiKey: string
bodyParams?: object
queryParams?: object
queryParams?: JsonObject
}): Promise<JsonObject> => {
const { method, url, path, apiKey, bodyParams, queryParams } = params
const { method, url, path, apiKey, bodyParams, queryParams = {} } = params
const urlObj = new URL(url + '/' + path, true)
const body = bodyParams != null ? JSON.stringify(bodyParams) : undefined

if (method === 'GET' && typeof queryParams === 'object') {
urlObj.set('query', queryParams)
}
queryParams.apikey = apiKey
urlObj.set('query', queryParams)

const options: EdgeFetchOptions = {
method,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`
'Content-Type': 'application/json'
}
}
if (body != null) {
Expand All @@ -639,7 +637,7 @@ const paybisFetch = async (params: {
const initializeBuyPairs = async ({ url, apiKey }: InitializePairs): Promise<void> => {
if (paybisPairs.buy == null) {
const promises = [
paybisFetch({ method: 'GET', url, path: `v1/currency/pairs`, apiKey })
paybisFetch({ method: 'GET', url, path: `v2/public/currency/pairs/buy-crypto`, apiKey })
.then(response => {
paybisPairs.buy = asPaybisBuyPairs(response)
})
Expand Down Expand Up @@ -695,7 +693,7 @@ const initializeBuyPairs = async ({ url, apiKey }: InitializePairs): Promise<voi
const initializeSellPairs = async ({ url, apiKey }: InitializePairs): Promise<void> => {
if (paybisPairs.sell == null) {
const promises = [
paybisFetch({ method: 'GET', url, path: `v2/currency/pairs/sell-crypto`, apiKey })
paybisFetch({ method: 'GET', url, path: `v2/public/currency/pairs/sell-crypto`, apiKey })
.then(response => {
paybisPairs.sell = asPaybisSellPairs(response)
})
Expand Down

0 comments on commit cfedc25

Please sign in to comment.