Skip to content

Commit b62fa6b

Browse files
committed
Move Monero specific tx update logic into updateTransaction
The purpose of this is to avoid the foot-gun: calling `addTransaction` when the transaction exists in the database will result in `updateTransaction` being invoked without the Monero specific tx update logic.
1 parent 5c04af7 commit b62fa6b

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/MoneroEngine.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export class MoneroEngine implements EdgeCurrencyEngine {
267267
})
268268
}
269269

270-
let edgeTransaction: EdgeTransaction = {
270+
const edgeTransaction: EdgeTransaction = {
271271
blockHeight,
272272
currencyCode: 'XMR',
273273
date,
@@ -294,22 +294,9 @@ export class MoneroEngine implements EdgeCurrencyEngine {
294294
this.edgeTxLibCallbacks.onTransactions(this.transactionEventArray)
295295
this.transactionEventArray = []
296296
} else {
297-
// Already have this tx in the database. See if anything changed
298-
const transactionsArray = this.getTxs(PRIMARY_CURRENCY_TOKEN_ID)
299-
const edgeTx = transactionsArray[idx]
300-
301-
if (edgeTx.blockHeight !== edgeTransaction.blockHeight) {
302-
// The native amounts returned from the API take some time before they're accurate. We can trust the amounts we saved instead.
303-
edgeTransaction = {
304-
...edgeTransaction,
305-
nativeAmount: edgeTx.nativeAmount
306-
}
307-
308-
this.log(`Update transaction: ${tx.hash} height:${tx.height}`)
309-
this.updateTransaction(PRIMARY_CURRENCY_TOKEN_ID, edgeTransaction, idx)
310-
this.edgeTxLibCallbacks.onTransactions(this.transactionEventArray)
311-
this.transactionEventArray = []
312-
}
297+
this.updateTransaction(PRIMARY_CURRENCY_TOKEN_ID, edgeTransaction, idx)
298+
this.edgeTxLibCallbacks.onTransactions(this.transactionEventArray)
299+
this.transactionEventArray = []
313300
}
314301

315302
return blockHeight
@@ -417,8 +404,23 @@ export class MoneroEngine implements EdgeCurrencyEngine {
417404
edgeTransaction: EdgeTransaction,
418405
idx: number
419406
): void {
420-
// Update the transaction
407+
// Already have this tx in the database. See if anything changed
421408
const txs = this.getTxs(tokenId)
409+
const edgeTx = txs[idx]
410+
411+
// Already have this tx in the database. Consider a change if blockHeight changed
412+
if (edgeTx.blockHeight === edgeTransaction.blockHeight) return
413+
this.log(
414+
`Update transaction: ${edgeTransaction.txid} height:${edgeTransaction.blockHeight}`
415+
)
416+
// The native amounts returned from the API take some time before they're
417+
// accurate. We can trust the amounts we saved instead.
418+
edgeTransaction = {
419+
...edgeTransaction,
420+
nativeAmount: edgeTx.nativeAmount
421+
}
422+
423+
// Update the transaction
422424
txs[idx] = edgeTransaction
423425
this.walletLocalDataDirty = true
424426
this.transactionEventArray.push({

0 commit comments

Comments
 (0)