@@ -284,20 +284,9 @@ export class MoneroEngine implements EdgeCurrencyEngine {
284284 walletId : this . walletId
285285 }
286286
287- const idx = this . findTransaction ( PRIMARY_CURRENCY_TOKEN_ID , tx . hash )
288- if ( idx === - 1 ) {
289- this . log ( `New transaction: ${ tx . hash } ` )
290-
291- // New transaction not in database
292- this . addTransaction ( PRIMARY_CURRENCY_TOKEN_ID , edgeTransaction )
293-
294- this . edgeTxLibCallbacks . onTransactions ( this . transactionEventArray )
295- this . transactionEventArray = [ ]
296- } else {
297- this . updateTransaction ( PRIMARY_CURRENCY_TOKEN_ID , edgeTransaction , idx )
298- this . edgeTxLibCallbacks . onTransactions ( this . transactionEventArray )
299- this . transactionEventArray = [ ]
300- }
287+ this . saveTransactionState ( PRIMARY_CURRENCY_TOKEN_ID , edgeTransaction )
288+ this . edgeTxLibCallbacks . onTransactions ( this . transactionEventArray )
289+ this . transactionEventArray = [ ]
301290
302291 return blockHeight
303292 }
@@ -366,11 +355,15 @@ export class MoneroEngine implements EdgeCurrencyEngine {
366355 return txs as EdgeTransaction [ ]
367356 }
368357
369- addTransaction ( tokenId : EdgeTokenId , edgeTransaction : EdgeTransaction ) : void {
358+ saveTransactionState (
359+ tokenId : EdgeTokenId ,
360+ edgeTransaction : EdgeTransaction
361+ ) : void {
370362 // Add or update tx in transactionsObj
371363 const idx = this . findTransaction ( tokenId , edgeTransaction . txid )
372364
373365 if ( idx === - 1 ) {
366+ this . log ( `New transaction: ${ edgeTransaction . txid } ` )
374367 this . log . warn (
375368 'addTransaction: adding and sorting:' +
376369 edgeTransaction . txid +
@@ -395,41 +388,35 @@ export class MoneroEngine implements EdgeCurrencyEngine {
395388 transaction : edgeTransaction
396389 } )
397390 } else {
398- this . updateTransaction ( tokenId , edgeTransaction , idx )
399- }
400- }
391+ const txs = this . getTxs ( tokenId )
392+ const edgeTx = txs [ idx ]
401393
402- updateTransaction (
403- tokenId : EdgeTokenId ,
404- edgeTransaction : EdgeTransaction ,
405- idx : number
406- ) : void {
407- // Already have this tx in the database. See if anything changed
408- const txs = this . getTxs ( tokenId )
409- const edgeTx = txs [ idx ]
394+ // Already have this tx in the database. Consider a change if blockHeight changed
395+ if ( edgeTx . blockHeight === edgeTransaction . blockHeight ) return
396+ this . log (
397+ `Update transaction: ${ edgeTransaction . txid } height:${ edgeTransaction . blockHeight } `
398+ )
410399
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- }
400+ // The native amounts returned from the API take some time before they're
401+ // accurate. We can trust the amounts we saved instead.
402+ edgeTransaction = {
403+ ...edgeTransaction ,
404+ nativeAmount : edgeTx . nativeAmount
405+ }
422406
423- // Update the transaction
424- txs [ idx ] = edgeTransaction
425- this . walletLocalDataDirty = true
426- this . transactionEventArray . push ( {
427- isNew : false ,
428- transaction : edgeTransaction
429- } )
430- this . log . warn (
431- 'updateTransaction' + edgeTransaction . txid + edgeTransaction . nativeAmount
432- )
407+ // Update the transaction
408+ txs [ idx ] = edgeTransaction
409+ this . walletLocalDataDirty = true
410+ this . transactionEventArray . push ( {
411+ isNew : false ,
412+ transaction : edgeTransaction
413+ } )
414+ this . log . warn (
415+ 'updateTransaction' +
416+ edgeTransaction . txid +
417+ edgeTransaction . nativeAmount
418+ )
419+ }
433420 }
434421
435422 // *************************************
@@ -748,7 +735,7 @@ export class MoneroEngine implements EdgeCurrencyEngine {
748735 }
749736
750737 async saveTx ( edgeTransaction : EdgeTransaction ) : Promise < void > {
751- await this . addTransaction ( edgeTransaction . tokenId , edgeTransaction )
738+ await this . saveTransactionState ( edgeTransaction . tokenId , edgeTransaction )
752739 }
753740
754741 getDisplayPrivateSeed ( privateKeys : JsonObject ) : string {
0 commit comments