Skip to content

Commit 8567545

Browse files
committed
Standardize Xgram transaction processor
1 parent 38f6598 commit 8567545

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/partners/xgram.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ export const queryXgram = async (
375375
if (previousTimestamp < 0) previousTimestamp = 0
376376
const targetIsoDate = new Date(previousTimestamp).toISOString()
377377

378-
const currencies = await fetchCurrencyCache(apiKey, log)
379-
380378
// Because Xgram pages from newest to oldest, the watermark can only be
381379
// advanced once the entire newer-than-target range has been fetched and
382380
// processed without error. Track the candidate watermark separately and only
@@ -427,7 +425,7 @@ export const queryXgram = async (
427425
}
428426
let oldestIsoDate = '999999999999999999999999999999999999'
429427
for (const rawTx of txs) {
430-
const standardTx = processXgramTx(rawTx, currencies)
428+
const standardTx = await processXgramTx(rawTx, pluginParams)
431429
if (standardTx.isoDate < oldestIsoDate) {
432430
oldestIsoDate = standardTx.isoDate
433431
}
@@ -462,7 +460,20 @@ export const xgram: PartnerPlugin = {
462460
pluginId: 'xgram'
463461
}
464462

465-
export function processXgramTx(
463+
export async function processXgramTx(
464+
rawTx: unknown,
465+
pluginParams: PluginParams
466+
): Promise<StandardTx> {
467+
const { log } = pluginParams
468+
const { apiKeys } = asStandardPluginParams(pluginParams)
469+
const { apiKey } = apiKeys
470+
if (apiKey == null) throw new Error('Missing Xgram apiKey')
471+
const currencies = await fetchCurrencyCache(apiKey, log)
472+
473+
return processXgramTxWithCurrencies(rawTx, currencies)
474+
}
475+
476+
export function processXgramTxWithCurrencies(
466477
rawTx: unknown,
467478
currencies: XgramCurrencies
468479
): StandardTx {

test/xgram.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { expect } from 'chai'
22
import { describe, it } from 'mocha'
33

4-
import { processXgramTx, XgramCurrencies } from '../src/partners/xgram'
4+
import {
5+
processXgramTxWithCurrencies,
6+
XgramCurrencies
7+
} from '../src/partners/xgram'
58

69
const currencies: XgramCurrencies = {
710
BTC: {
@@ -33,7 +36,7 @@ const currencies: XgramCurrencies = {
3336

3437
describe('processXgramTx', () => {
3538
it('maps source and destination asset IDs', () => {
36-
const tx = processXgramTx(
39+
const tx = processXgramTxWithCurrencies(
3740
{
3841
id: 'dyv3a2tdbgipvh0',
3942
'x-status': 'x-completed',
@@ -67,7 +70,7 @@ describe('processXgramTx', () => {
6770
})
6871

6972
it('uses expected amounts and chain-specific token IDs for pending rows', () => {
70-
const tx = processXgramTx(
73+
const tx = processXgramTxWithCurrencies(
7174
{
7275
id: 'tmah3a2td9cp20q0',
7376
'x-status': 'x-new',
@@ -98,7 +101,7 @@ describe('processXgramTx', () => {
98101
})
99102

100103
it('maps historical native currencies missing from the currency API', () => {
101-
const tx = processXgramTx(
104+
const tx = processXgramTxWithCurrencies(
102105
{
103106
id: 'talr3a0e49fplpog',
104107
'x-status': 'x-timeout',

0 commit comments

Comments
 (0)