Skip to content

Commit

Permalink
Add affiliateAddress and xClientId params
Browse files Browse the repository at this point in the history
- xClientId helps prevent timeouts
- snooze to also help prevent timeouts
- use affiliateAddress to filter txs not created in app
  • Loading branch information
paullinator committed Nov 1, 2024
1 parent 7cb6f19 commit 9467e9b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/partners/thorchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ const asThorchainResult = asObject({
})

const asThorchainPluginParams = asObject({
apiKeys: asObject({ thorchainAddress: asString }),
apiKeys: asObject({
thorchainAddress: asString,
affiliateAddress: asString,
xClientId: asOptional(asString)
}),
settings: asObject({
latestIsoDate: asOptional(asString, '1970-01-01T00:00:00.000Z')
})
Expand All @@ -79,7 +83,7 @@ const makeThorchainPlugin = (info: ThorchainInfo): PartnerPlugin => {
const ssFormatTxs: StandardTx[] = []

const { settings, apiKeys } = asThorchainPluginParams(pluginParams)
const { thorchainAddress } = apiKeys
const { affiliateAddress, thorchainAddress, xClientId } = apiKeys
let { latestIsoDate } = settings

let previousTimestamp = new Date(latestIsoDate).getTime() - QUERY_LOOKBACK
Expand All @@ -91,12 +95,21 @@ const makeThorchainPlugin = (info: ThorchainInfo): PartnerPlugin => {

let offset = 0

let headers: HeadersInit | undefined
if (xClientId != null) {
headers = {
'x-client-id': xClientId
}
}

while (!done) {
const url = `https://${midgardUrl}/v2/actions?address=${thorchainAddress}&type=swap,refund&affiliate=ej&offset=${offset}&limit=${LIMIT}`
let jsonObj: ThorchainResult
try {
const result = await fetch(url, {
method: 'GET'
await snooze(500)
const result = await retryFetch(url, {
method: 'GET',
headers
})
if (!result.ok) {
const text = await result.text()
Expand All @@ -112,12 +125,17 @@ const makeThorchainPlugin = (info: ThorchainInfo): PartnerPlugin => {
for (const rawTx of txs) {
const {
date,
metadata,
in: txIns,
out: txOuts,
pools,
status: txStatus
} = asThorchainTx(rawTx) // Check RAW trasaction

const { swap } = metadata
if (swap?.affiliateAddress !== affiliateAddress) {
continue
}
const status = 'complete'
if (txStatus !== 'success') {
continue
Expand Down

0 comments on commit 9467e9b

Please sign in to comment.