Skip to content

Commit 868a00c

Browse files
committed
fixup! Fix partner plugin logging, token normalization, and cache handling
1 parent aeb8625 commit 868a00c

5 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/partners/banxa.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ interface CachedAssetInfo {
9393
pluginId: string | undefined
9494
}
9595
let banxaCoinsCache: Map<string, CachedAssetInfo> | null = null
96+
let banxaCoinsCacheTimestamp = 0
97+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000 // 24 hours
9698

9799
// Static fallback for historical coins no longer in the v2 API
98100
const BANXA_HISTORICAL_COINS: Record<string, CachedAssetInfo> = {
@@ -122,7 +124,10 @@ async function fetchBanxaCoins(
122124
apiKeyV2: string,
123125
log: ScopedLog
124126
): Promise<Map<string, CachedAssetInfo>> {
125-
if (banxaCoinsCache != null) {
127+
if (
128+
banxaCoinsCache != null &&
129+
Date.now() - banxaCoinsCacheTimestamp < CACHE_TTL_MS
130+
) {
126131
return banxaCoinsCache
127132
}
128133

@@ -196,6 +201,7 @@ async function fetchBanxaCoins(
196201
}
197202

198203
banxaCoinsCache = cache
204+
banxaCoinsCacheTimestamp = Date.now()
199205
log(`Loaded ${cache.size} coin/blockchain combinations from API`)
200206
return cache
201207
}

src/partners/changenow.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ const currencyCache: CurrencyCache = {
124124
currencies: new Map(),
125125
loaded: false
126126
}
127+
let currencyCacheTimestamp = 0
128+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000 // 24 hours
127129

128130
/**
129131
* Fetch all currencies from ChangeNow API and populate the cache
@@ -132,7 +134,10 @@ async function loadCurrencyCache(
132134
log: ScopedLog,
133135
apiKey?: string
134136
): Promise<void> {
135-
if (currencyCache.loaded) {
137+
if (
138+
currencyCache.loaded &&
139+
Date.now() - currencyCacheTimestamp < CACHE_TTL_MS
140+
) {
136141
return
137142
}
138143

@@ -166,6 +171,7 @@ async function loadCurrencyCache(
166171
}
167172

168173
currencyCache.loaded = true
174+
currencyCacheTimestamp = Date.now()
169175
log(`Currency cache loaded with ${currencies.length} entries`)
170176
} catch (e) {
171177
log.error(`Error loading currency cache: ${e}`)

src/partners/godex.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,16 @@ interface GodexAssetInfo {
114114
}
115115

116116
let godexCoinsCache: Map<string, GodexAssetInfo> | null = null
117+
let godexCoinsCacheTimestamp = 0
118+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000 // 24 hours
117119

118120
async function getGodexCoinsCache(
119121
log: ScopedLog
120122
): Promise<Map<string, GodexAssetInfo>> {
121-
if (godexCoinsCache != null) {
123+
if (
124+
godexCoinsCache != null &&
125+
Date.now() - godexCoinsCacheTimestamp < CACHE_TTL_MS
126+
) {
122127
return godexCoinsCache
123128
}
124129

@@ -154,6 +159,7 @@ async function getGodexCoinsCache(
154159
}
155160
log(`Coins cache loaded: ${cache.size} entries`)
156161
godexCoinsCache = cache
162+
godexCoinsCacheTimestamp = Date.now()
157163
return cache
158164
} catch (e) {
159165
log.error(`Error loading coins cache: ${String(e)}`)

src/partners/letsexchange.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,15 @@ interface CoinInfo {
236236

237237
let coinCache: Map<string, CoinInfo> | null = null
238238
let coinCacheApiKey: string | null = null
239+
let coinCacheTimestamp = 0
240+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000 // 24 hours
239241

240242
async function fetchCoinCache(apiKey: string, log: ScopedLog): Promise<void> {
241-
if (coinCache != null && coinCacheApiKey === apiKey) {
243+
if (
244+
coinCache != null &&
245+
coinCacheApiKey === apiKey &&
246+
Date.now() - coinCacheTimestamp < CACHE_TTL_MS
247+
) {
242248
return // Already cached
243249
}
244250

@@ -278,6 +284,7 @@ async function fetchCoinCache(apiKey: string, log: ScopedLog): Promise<void> {
278284
}
279285

280286
coinCacheApiKey = apiKey
287+
coinCacheTimestamp = Date.now()
281288
log(`Cached ${coinCache.size} coins`)
282289
}
283290

src/partners/sideshift.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,14 @@ const asSideshiftCoinsResponse = asArray(asSideshiftCoin)
9999
// Cache for Sideshift coins data
100100
// Key: `${coin}-${network}` -> contract address or null for mainnet coins
101101
let sideshiftCoinsCache: Map<string, string | null> | null = null
102+
let sideshiftCoinsCacheTimestamp = 0
103+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000 // 24 hours
102104

103105
async function fetchSideshiftCoins(): Promise<Map<string, string | null>> {
104-
if (sideshiftCoinsCache != null) {
106+
if (
107+
sideshiftCoinsCache != null &&
108+
Date.now() - sideshiftCoinsCacheTimestamp < CACHE_TTL_MS
109+
) {
105110
return sideshiftCoinsCache
106111
}
107112

@@ -124,6 +129,7 @@ async function fetchSideshiftCoins(): Promise<Map<string, string | null>> {
124129
}
125130

126131
sideshiftCoinsCache = cache
132+
sideshiftCoinsCacheTimestamp = Date.now()
127133
return cache
128134
}
129135

0 commit comments

Comments
 (0)