Skip to content

Commit

Permalink
Add partnerUrl to banxa settings
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Oct 10, 2023
1 parent de645a6 commit 4dfe3e9
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/partners/banxa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
asMaybe,
asNumber,
asObject,
asOptional,
asString,
asUnknown,
asValue
Expand All @@ -11,7 +12,6 @@ import crypto from 'crypto'
import { Response } from 'node-fetch'

import {
asStandardPluginParams,
PartnerPlugin,
PluginParams,
PluginResult,
Expand All @@ -20,6 +20,16 @@ import {
} from '../types'
import { datelog, retryFetch, smartIsoDateFromTimestamp, snooze } from '../util'

export const asBanxaParams = asObject({
settings: asObject({
latestIsoDate: asOptional(asString, '2018-01-01T00:00:00.000Z')
}),
apiKeys: asObject({
apiKey: asString,
partnerUrl: asString
})
})

const asBanxaStatus = asMaybe(
asValue(
'complete',
Expand Down Expand Up @@ -72,8 +82,8 @@ export async function queryBanxa(
pluginParams: PluginParams
): Promise<PluginResult> {
const ssFormatTxs: StandardTx[] = []
const { settings, apiKeys } = asStandardPluginParams(pluginParams)
const { apiKey } = apiKeys
const { settings, apiKeys } = asBanxaParams(pluginParams)
const { apiKey, partnerUrl } = apiKeys
const { latestIsoDate } = settings

if (apiKey == null) {
Expand All @@ -100,6 +110,7 @@ export async function queryBanxa(
`BANXA: Querying ${startDate}->${endDate}, limit=${PAGE_LIMIT} page=${page} attempt=${attempt}`
)
const response = await fetchBanxaAPI(
partnerUrl,
startDate,
endDate,
PAGE_LIMIT,
Expand Down Expand Up @@ -161,6 +172,7 @@ export const banxa: PartnerPlugin = {
}

async function fetchBanxaAPI(
partnerUrl: string,
startDate: string,
endDate: string,
pageLimit: number,
Expand All @@ -185,7 +197,7 @@ async function fetchBanxaAPI(
'Content-Type': 'application/json'
}

return retryFetch(`https://edge.banxa.com${apiQuery}`, { headers: headers })
return retryFetch(`${partnerUrl}${apiQuery}`, { headers: headers })
}

function processBanxaOrders(rawtxs, ssFormatTxs): void {
Expand Down

0 comments on commit 4dfe3e9

Please sign in to comment.