Skip to content

Commit 7239a9b

Browse files
committed
fixup! fixup! Use ratex v3 if transactions has full pluginId/tokenId values
1 parent 4f95ce1 commit 7239a9b

1 file changed

Lines changed: 73 additions & 57 deletions

File tree

src/ratesEngine.ts

Lines changed: 73 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -242,90 +242,106 @@ async function updateTxValues(
242242
const hasPayoutPluginInfo =
243243
transaction.payoutChainPluginId != null &&
244244
transaction.payoutTokenId !== undefined
245+
let success = false
246+
const needsPayoutAmount = transaction.depositAmount > 0
245247

246248
if (
247249
(hasDepositPluginInfo && hasPayoutPluginInfo) ||
248250
(hasDepositPluginInfo && isFiatCurrency(transaction.payoutCurrency)) ||
249251
(isFiatCurrency(transaction.depositCurrency) && hasPayoutPluginInfo)
250252
) {
251-
return await updateTxValuesV3(transaction)
252-
}
253+
const hadUsdValue = transaction.usdValue != null && transaction.usdValue > 0
254+
const hadPayoutAmount = transaction.payoutAmount !== 0 || !needsPayoutAmount
253255

254-
let success = false
255-
const date: string = transaction.isoDate
256-
if (mappings[transaction.depositCurrency] != null) {
257-
transaction.depositCurrency = mappings[transaction.depositCurrency]
258-
}
259-
if (mappings[transaction.payoutCurrency] != null) {
260-
transaction.payoutCurrency = mappings[transaction.payoutCurrency]
261-
}
256+
try {
257+
await updateTxValuesV3(transaction)
258+
} catch (e) {
259+
datelog('updateTxValuesV3 failed', e)
260+
}
262261

263-
if (transaction.payoutAmount === 0) {
264-
const exchangeRate = await getExchangeRate(
265-
transaction.depositCurrency,
266-
transaction.payoutCurrency,
267-
date
268-
)
269-
if (exchangeRate > 0) {
270-
transaction.payoutAmount = transaction.depositAmount * exchangeRate
271-
success = true
262+
const hasUsdValue = transaction.usdValue != null && transaction.usdValue > 0
263+
const hasPayoutAmount = transaction.payoutAmount !== 0 || !needsPayoutAmount
264+
const madeProgress =
265+
(!hadUsdValue && hasUsdValue) || (!hadPayoutAmount && hasPayoutAmount)
266+
267+
success = madeProgress
268+
} else {
269+
const date: string = transaction.isoDate
270+
if (mappings[transaction.depositCurrency] != null) {
271+
transaction.depositCurrency = mappings[transaction.depositCurrency]
272272
}
273-
}
274-
if (transaction.payoutAmount === 0) {
275-
const exchangeRate = await getExchangeRate(
276-
transaction.payoutCurrency,
277-
transaction.depositCurrency,
278-
date
279-
)
280-
if (exchangeRate > 0) {
281-
transaction.payoutAmount = transaction.depositAmount * (1 / exchangeRate)
282-
success = true
273+
if (mappings[transaction.payoutCurrency] != null) {
274+
transaction.payoutCurrency = mappings[transaction.payoutCurrency]
283275
}
284-
}
285-
if (
286-
transaction.payoutAmount === 0 &&
287-
transaction.usdValue !== undefined &&
288-
transaction.usdValue > 0
289-
) {
290-
const exchangeRate = await getExchangeRate(
291-
'USD',
292-
transaction.payoutCurrency,
293-
date
294-
)
295-
if (exchangeRate > 0) {
296-
transaction.payoutAmount = transaction.usdValue * exchangeRate
297-
success = true
276+
277+
if (transaction.payoutAmount === 0) {
278+
const exchangeRate = await getExchangeRate(
279+
transaction.depositCurrency,
280+
transaction.payoutCurrency,
281+
date
282+
)
283+
if (exchangeRate > 0) {
284+
transaction.payoutAmount = transaction.depositAmount * exchangeRate
285+
success = true
286+
}
298287
}
299288
if (transaction.payoutAmount === 0) {
300289
const exchangeRate = await getExchangeRate(
301290
transaction.payoutCurrency,
302-
'USD',
291+
transaction.depositCurrency,
303292
date
304293
)
305294
if (exchangeRate > 0) {
306-
transaction.payoutAmount = transaction.usdValue * (1 / exchangeRate)
295+
transaction.payoutAmount =
296+
transaction.depositAmount * (1 / exchangeRate)
307297
success = true
308298
}
309299
}
310-
}
311-
if (transaction.usdValue == null || transaction.usdValue <= 0) {
312-
const exchangeRate = await getExchangeRate(
313-
transaction.depositCurrency,
314-
'USD',
315-
date
316-
)
317-
if (exchangeRate > 0) {
318-
transaction.usdValue = transaction.depositAmount * exchangeRate
319-
success = true
320-
} else if (transaction.payoutAmount !== 0) {
300+
if (
301+
transaction.payoutAmount === 0 &&
302+
transaction.usdValue !== undefined &&
303+
transaction.usdValue > 0
304+
) {
321305
const exchangeRate = await getExchangeRate(
306+
'USD',
322307
transaction.payoutCurrency,
308+
date
309+
)
310+
if (exchangeRate > 0) {
311+
transaction.payoutAmount = transaction.usdValue * exchangeRate
312+
success = true
313+
}
314+
if (transaction.payoutAmount === 0) {
315+
const exchangeRate = await getExchangeRate(
316+
transaction.payoutCurrency,
317+
'USD',
318+
date
319+
)
320+
if (exchangeRate > 0) {
321+
transaction.payoutAmount = transaction.usdValue * (1 / exchangeRate)
322+
success = true
323+
}
324+
}
325+
}
326+
if (transaction.usdValue == null || transaction.usdValue <= 0) {
327+
const exchangeRate = await getExchangeRate(
328+
transaction.depositCurrency,
323329
'USD',
324330
date
325331
)
326332
if (exchangeRate > 0) {
327-
transaction.usdValue = transaction.payoutAmount * exchangeRate
333+
transaction.usdValue = transaction.depositAmount * exchangeRate
328334
success = true
335+
} else if (transaction.payoutAmount !== 0) {
336+
const exchangeRate = await getExchangeRate(
337+
transaction.payoutCurrency,
338+
'USD',
339+
date
340+
)
341+
if (exchangeRate > 0) {
342+
transaction.usdValue = transaction.payoutAmount * exchangeRate
343+
success = true
344+
}
329345
}
330346
}
331347
}

0 commit comments

Comments
 (0)