edge-currency-monero 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.4.2 (2025-04-01)
6
+
7
+ - fixed: Small internal implementation cleanup on how transactions are saved.
8
+
9
+ ## 1.4.1 (2025-03-28)
10
+
11
+ - fixed: Fixed `saveTx` regression. Transaction sends are properly saved.
12
+
5
13
  ## 1.4.0 (2025-03-25)
6
14
 
7
15
  - fixed: Remove race condition causing missing transaction between showing address and initial login.
@@ -267,7 +267,7 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
267
267
  })
268
268
  }
269
269
 
270
- let edgeTransaction = {
270
+ const edgeTransaction = {
271
271
  blockHeight,
272
272
  currencyCode: 'XMR',
273
273
  date,
@@ -284,33 +284,9 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
284
284
  walletId: this.walletId
285
285
  }
286
286
 
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
- // 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
- }
313
- }
287
+ this.saveTransactionState(PRIMARY_CURRENCY_TOKEN_ID, edgeTransaction)
288
+ this.edgeTxLibCallbacks.onTransactions(this.transactionEventArray)
289
+ this.transactionEventArray = []
314
290
 
315
291
  return blockHeight
316
292
  }
@@ -379,11 +355,15 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
379
355
  return txs
380
356
  }
381
357
 
382
- addTransaction(tokenId, edgeTransaction) {
358
+ saveTransactionState(
359
+ tokenId,
360
+ edgeTransaction
361
+ ) {
383
362
  // Add or update tx in transactionsObj
384
363
  const idx = this.findTransaction(tokenId, edgeTransaction.txid)
385
364
 
386
365
  if (idx === -1) {
366
+ this.log(`New transaction: ${edgeTransaction.txid}`)
387
367
  this.log.warn(
388
368
  'addTransaction: adding and sorting:' +
389
369
  edgeTransaction.txid +
@@ -408,26 +388,35 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
408
388
  transaction: edgeTransaction
409
389
  })
410
390
  } else {
411
- this.updateTransaction(tokenId, edgeTransaction, idx)
412
- }
413
- }
391
+ const txs = this.getTxs(tokenId)
392
+ const edgeTx = txs[idx]
414
393
 
415
- updateTransaction(
416
- tokenId,
417
- edgeTransaction,
418
- idx
419
- ) {
420
- // Update the transaction
421
- const txs = this.getTxs(tokenId)
422
- txs[idx] = edgeTransaction
423
- this.walletLocalDataDirty = true
424
- this.transactionEventArray.push({
425
- isNew: false,
426
- transaction: edgeTransaction
427
- })
428
- this.log.warn(
429
- 'updateTransaction' + edgeTransaction.txid + edgeTransaction.nativeAmount
430
- )
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
+ )
399
+
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
+ }
406
+
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
+ }
431
420
  }
432
421
 
433
422
  // *************************************
@@ -746,7 +735,7 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
746
735
  }
747
736
 
748
737
  async saveTx(edgeTransaction) {
749
- await this.addTransaction(edgeTransaction.currencyCode, edgeTransaction)
738
+ await this.saveTransactionState(edgeTransaction.tokenId, edgeTransaction)
750
739
  }
751
740
 
752
741
  getDisplayPrivateSeed(privateKeys) {
@@ -2167,31 +2167,9 @@ var MoneroEngine = /*#__PURE__*/function () {
2167
2167
  txid: tx.hash,
2168
2168
  walletId: this.walletId
2169
2169
  };
2170
- var idx = this.findTransaction(PRIMARY_CURRENCY_TOKEN_ID, tx.hash);
2171
-
2172
- if (idx === -1) {
2173
- this.log("New transaction: ".concat(tx.hash)); // New transaction not in database
2174
-
2175
- this.addTransaction(PRIMARY_CURRENCY_TOKEN_ID, edgeTransaction);
2176
- this.edgeTxLibCallbacks.onTransactions(this.transactionEventArray);
2177
- this.transactionEventArray = [];
2178
- } else {
2179
- // Already have this tx in the database. See if anything changed
2180
- var transactionsArray = this.getTxs(PRIMARY_CURRENCY_TOKEN_ID);
2181
- var edgeTx = transactionsArray[idx];
2182
-
2183
- if (edgeTx.blockHeight !== edgeTransaction.blockHeight) {
2184
- // The native amounts returned from the API take some time before they're accurate. We can trust the amounts we saved instead.
2185
- edgeTransaction = _objectSpread(_objectSpread({}, edgeTransaction), {}, {
2186
- nativeAmount: edgeTx.nativeAmount
2187
- });
2188
- this.log("Update transaction: ".concat(tx.hash, " height:").concat(tx.height));
2189
- this.updateTransaction(PRIMARY_CURRENCY_TOKEN_ID, edgeTransaction, idx);
2190
- this.edgeTxLibCallbacks.onTransactions(this.transactionEventArray);
2191
- this.transactionEventArray = [];
2192
- }
2193
- }
2194
-
2170
+ this.saveTransactionState(PRIMARY_CURRENCY_TOKEN_ID, edgeTransaction);
2171
+ this.edgeTxLibCallbacks.onTransactions(this.transactionEventArray);
2172
+ this.transactionEventArray = [];
2195
2173
  return blockHeight;
2196
2174
  }
2197
2175
  }, {
@@ -2283,12 +2261,13 @@ var MoneroEngine = /*#__PURE__*/function () {
2283
2261
  return txs;
2284
2262
  }
2285
2263
  }, {
2286
- key: "addTransaction",
2287
- value: function addTransaction(tokenId, edgeTransaction) {
2264
+ key: "saveTransactionState",
2265
+ value: function saveTransactionState(tokenId, edgeTransaction) {
2288
2266
  // Add or update tx in transactionsObj
2289
2267
  var idx = this.findTransaction(tokenId, edgeTransaction.txid);
2290
2268
 
2291
2269
  if (idx === -1) {
2270
+ this.log("New transaction: ".concat(edgeTransaction.txid));
2292
2271
  this.log.warn('addTransaction: adding and sorting:' + edgeTransaction.txid + edgeTransaction.nativeAmount);
2293
2272
  var txs = this.getTxs(tokenId);
2294
2273
  txs.push(edgeTransaction); // Sort
@@ -2305,21 +2284,26 @@ var MoneroEngine = /*#__PURE__*/function () {
2305
2284
  transaction: edgeTransaction
2306
2285
  });
2307
2286
  } else {
2308
- this.updateTransaction(tokenId, edgeTransaction, idx);
2287
+ var _txs2 = this.getTxs(tokenId);
2288
+
2289
+ var edgeTx = _txs2[idx]; // Already have this tx in the database. Consider a change if blockHeight changed
2290
+
2291
+ if (edgeTx.blockHeight === edgeTransaction.blockHeight) return;
2292
+ this.log("Update transaction: ".concat(edgeTransaction.txid, " height:").concat(edgeTransaction.blockHeight)); // The native amounts returned from the API take some time before they're
2293
+ // accurate. We can trust the amounts we saved instead.
2294
+
2295
+ edgeTransaction = _objectSpread(_objectSpread({}, edgeTransaction), {}, {
2296
+ nativeAmount: edgeTx.nativeAmount
2297
+ }); // Update the transaction
2298
+
2299
+ _txs2[idx] = edgeTransaction;
2300
+ this.walletLocalDataDirty = true;
2301
+ this.transactionEventArray.push({
2302
+ isNew: false,
2303
+ transaction: edgeTransaction
2304
+ });
2305
+ this.log.warn('updateTransaction' + edgeTransaction.txid + edgeTransaction.nativeAmount);
2309
2306
  }
2310
- }
2311
- }, {
2312
- key: "updateTransaction",
2313
- value: function updateTransaction(tokenId, edgeTransaction, idx) {
2314
- // Update the transaction
2315
- var txs = this.getTxs(tokenId);
2316
- txs[idx] = edgeTransaction;
2317
- this.walletLocalDataDirty = true;
2318
- this.transactionEventArray.push({
2319
- isNew: false,
2320
- transaction: edgeTransaction
2321
- });
2322
- this.log.warn('updateTransaction' + edgeTransaction.txid + edgeTransaction.nativeAmount);
2323
2307
  } // *************************************
2324
2308
  // Save the wallet data store
2325
2309
  // *************************************
@@ -3115,7 +3099,7 @@ var MoneroEngine = /*#__PURE__*/function () {
3115
3099
  switch (_context25.prev = _context25.next) {
3116
3100
  case 0:
3117
3101
  _context25.next = 2;
3118
- return this.addTransaction(edgeTransaction.currencyCode, edgeTransaction);
3102
+ return this.saveTransactionState(edgeTransaction.tokenId, edgeTransaction);
3119
3103
 
3120
3104
  case 2:
3121
3105
  case "end":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-monero",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Edge Monero currency plugin",
5
5
  "homepage": "https://edge.app",
6
6
  "repository": {