Skip to content

Commit 0da1faa

Browse files
committed
Fix Moonpay direction detection and partner config edge cases
1 parent 6ed36d2 commit 0da1faa

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/partners/bitrefill.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,9 @@ export function processBitrefillTx(
279279
const timestamp = tx.invoiceTime / 1000
280280

281281
const { paymentMethod } = tx
282-
let depositAmountStr: string | undefined
283-
if (paymentMethod === 'bitcoin') {
284-
depositAmountStr = tx.btcPrice
285-
} else if (tx.altcoinPrice != null) {
282+
// Fallback to btcPrice when altcoinPrice is unexpectedly missing.
283+
let depositAmountStr: string | undefined = tx.btcPrice
284+
if (paymentMethod !== 'bitcoin' && tx.altcoinPrice != null) {
286285
depositAmountStr = tx.altcoinPrice
287286
}
288287
if (depositAmountStr == null) {

src/partners/letsexchange.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export const asLetsExchangePluginParams = asObject({
4040
latestIsoDate: asOptional(asString, LETSEXCHANGE_START_DATE)
4141
}),
4242
apiKeys: asObject({
43-
affiliateId: asString,
44-
apiKey: asString
43+
affiliateId: asOptional(asString),
44+
apiKey: asOptional(asString)
4545
})
4646
})
4747

@@ -484,6 +484,10 @@ export async function processLetsExchangeTx(
484484
const { apiKey } = apiKeys
485485
const { log } = pluginParams
486486

487+
if (apiKey == null) {
488+
throw new Error('Missing LetsExchange apiKey')
489+
}
490+
487491
await fetchCoinCache(apiKey, log)
488492

489493
const tx = asLetsExchangeTx(rawTx)

src/partners/moonpay.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,14 @@ export function processTx(rawTx: unknown): StandardTx {
312312
// Map Moonpay status to Edge status
313313
const status: Status = statusMap[tx.status] ?? 'other'
314314

315-
// Determine direction based on paymentMethod vs payoutMethod
316-
// Buy transactions have paymentMethod, sell transactions have payoutMethod
317-
const direction = tx.paymentMethod != null ? 'buy' : 'sell'
315+
// Determine direction based on sell-specific fields.
316+
// Sell transactions can also include paymentMethod, so that field alone is insufficient.
317+
const direction =
318+
tx.quoteCurrency != null ||
319+
tx.payoutMethod != null ||
320+
tx.depositHash != null
321+
? 'sell'
322+
: 'buy'
318323

319324
// Get the payout currency - different field names for buy vs sell
320325
const payoutCurrency = direction === 'buy' ? tx.currency : tx.quoteCurrency

0 commit comments

Comments
 (0)