Skip to content

Commit 6ed36d2

Browse files
cursoragentpaullinator
authored andcommitted
Fix partner plugin logging, token normalization, and cache handling
1 parent 493a19f commit 6ed36d2

5 files changed

Lines changed: 54 additions & 34 deletions

File tree

src/partners/changenow.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,17 @@ function getAssetInfo(network: string, currencyCode: string): EdgeAssetInfo {
344344
// Look up contract address from cache
345345
const contractAddress = getContractFromCache(currencyCode, network)
346346

347-
// If not in cache or no contract address, it's a native token
348-
if (contractAddress == null) {
347+
// null means native token, undefined means cache miss
348+
if (contractAddress === null) {
349349
return {
350350
chainPluginId,
351351
evmChainId,
352352
tokenId: null
353353
}
354354
}
355+
if (contractAddress === undefined) {
356+
throw new Error(`Currency info not found for ${currencyCode} on ${network}`)
357+
}
355358

356359
// Create tokenId from contract address
357360
const tokenType = tokenTypes[chainPluginId]

src/partners/godex.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ async function getGodexCoinsCache(
132132
try {
133133
const url = 'https://api.godex.io/api/v1/coins'
134134
const result = await retryFetch(url, { method: 'GET' })
135+
if (!result.ok) {
136+
const text = await result.text()
137+
throw new Error(`Failed to fetch Godex coins: ${text}`)
138+
}
135139
const json = await result.json()
136140
const coins = asGodexCoinsResponse(json)
137141

@@ -149,11 +153,12 @@ async function getGodexCoinsCache(
149153
}
150154
}
151155
log(`Coins cache loaded: ${cache.size} entries`)
156+
godexCoinsCache = cache
157+
return cache
152158
} catch (e) {
153-
log.error('Error loading coins cache:', e)
159+
log.error(`Error loading coins cache: ${String(e)}`)
160+
throw e
154161
}
155-
godexCoinsCache = cache
156-
return cache
157162
}
158163

159164
interface GodexEdgeAssetInfo {

src/partners/letsexchange.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,23 @@ export const asLetsExchangePluginParams = asObject({
4545
})
4646
})
4747

48-
const asLetsExchangeStatus = asValue(
49-
'wait',
50-
'confirmation',
51-
'confirmed',
52-
'exchanging',
53-
'overdue',
54-
'refund',
55-
'sending',
56-
'transferring',
57-
'sending_confirmation',
58-
'success',
59-
'aml_check_failed',
60-
'overdue',
61-
'error',
62-
'canceled',
63-
'refund'
48+
const asLetsExchangeStatus = asMaybe(
49+
asValue(
50+
'wait',
51+
'confirmation',
52+
'confirmed',
53+
'exchanging',
54+
'overdue',
55+
'refund',
56+
'sending',
57+
'transferring',
58+
'sending_confirmation',
59+
'success',
60+
'aml_check_failed',
61+
'error',
62+
'canceled'
63+
),
64+
'other'
6465
)
6566

6667
// Cleaner for the new v2 API response
@@ -128,7 +129,8 @@ const statusMap: { [key in LetsExchangeStatus]: Status } = {
128129
success: 'complete',
129130
aml_check_failed: 'blocked',
130131
canceled: 'cancelled',
131-
error: 'failed'
132+
error: 'failed',
133+
other: 'other'
132134
}
133135

134136
// Map LetsExchange network codes to Edge pluginIds
@@ -289,14 +291,15 @@ function getAssetInfo(
289291
initialNetwork: string | null,
290292
currencyCode: string,
291293
contractAddress: string | null,
292-
log: ScopedLog
294+
isoDate: string
293295
): AssetInfo | undefined {
294-
let network = initialNetwork
295-
if (network == null) {
296-
// Try using the currencyCode as the network
297-
network = currencyCode
298-
log(`Using currencyCode as network: ${network}`)
296+
if (initialNetwork == null) {
297+
if (isoDate < NETWORK_FIELDS_AVAILABLE_DATE) {
298+
return undefined
299+
}
300+
throw new Error(`Missing network for currency ${currencyCode}`)
299301
}
302+
const network = initialNetwork
300303

301304
const networkUpper = network.toUpperCase()
302305
const chainPluginId = LETSEXCHANGE_NETWORK_TO_PLUGIN_ID[networkUpper]
@@ -500,14 +503,14 @@ export async function processLetsExchangeTx(
500503
tx.coin_from_network ?? tx.network_from_code,
501504
tx.coin_from,
502505
tx.coin_from_contract_address,
503-
log
506+
isoDate
504507
)
505508
// Get payout asset info using contract address from API response
506509
const payoutAsset = getAssetInfo(
507510
tx.coin_to_network ?? tx.network_to_code,
508511
tx.coin_to,
509512
tx.coin_to_contract_address,
510-
log
513+
isoDate
511514
)
512515

513516
const status = statusMap[tx.status]

src/partners/lifi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export function processLifiTx(
297297
}
298298
if (statusMap[tx.status] === 'complete') {
299299
const { orderId, depositCurrency, payoutCurrency } = standardTx
300-
console.log(
300+
log(
301301
`${orderId} ${depositCurrency} ${depositChainPluginId} ${depositEvmChainId} ${depositTokenId?.slice(
302302
0,
303303
6

src/partners/rango.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
Status
2020
} from '../types'
2121
import { retryFetch } from '../util'
22+
import { createTokenId, tokenTypes } from '../util/asEdgeTokenId'
2223
import { EVM_CHAIN_IDS } from '../util/chainIds'
2324

2425
// Start date for Rango transactions (first Edge transaction was 2024-06-23)
@@ -268,9 +269,17 @@ export function processRangoTx(
268269

269270
const dateStr = isoDate.split('T')[0]
270271
const depositCurrency = firstStep.fromToken.symbol
271-
const depositTokenId = firstStep.fromToken.address ?? null
272+
const depositTokenId = createTokenId(
273+
tokenTypes[depositChainPluginId],
274+
depositCurrency,
275+
firstStep.fromToken.address ?? undefined
276+
)
272277
const payoutCurrency = lastStep.toToken.symbol
273-
const payoutTokenId = lastStep.toToken.address ?? null
278+
const payoutTokenId = createTokenId(
279+
tokenTypes[payoutChainPluginId],
280+
payoutCurrency,
281+
lastStep.toToken.address ?? undefined
282+
)
274283

275284
log(
276285
`${dateStr} ${depositCurrency} ${depositAmount} ${depositChainPluginId}${
@@ -299,7 +308,7 @@ export function processRangoTx(
299308
payoutCurrency: lastStep.toToken.symbol,
300309
payoutChainPluginId,
301310
payoutEvmChainId,
302-
payoutTokenId: lastStep.toToken.address ?? null,
311+
payoutTokenId,
303312
payoutAmount,
304313
timestamp,
305314
isoDate,

0 commit comments

Comments
 (0)