minimal-xec-wallet 1.0.3 → 1.0.4

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.
@@ -91,8 +91,8 @@ class ConsolidateUtxos {
91
91
 
92
92
  // Filter UTXOs that should be consolidated (smaller ones first)
93
93
  const utxosToConsolidate = pureXecUtxos
94
- .filter(utxo => utxo.value <= options.consolidationThreshold)
95
- .sort((a, b) => a.value - b.value) // Sort by value ascending
94
+ .filter(utxo => this._getUtxoValue(utxo) <= options.consolidationThreshold)
95
+ .sort((a, b) => this._getUtxoValue(a) - this._getUtxoValue(b)) // Sort by value ascending
96
96
 
97
97
  if (utxosToConsolidate.length < this.minUtxosForConsolidation) {
98
98
  return {
@@ -267,7 +267,17 @@ class ConsolidateUtxos {
267
267
  // Helper methods
268
268
 
269
269
  _calculateTotalValue (utxos) {
270
- return utxos.reduce((total, utxo) => total + utxo.value, 0)
270
+ return utxos.reduce((total, utxo) => total + this._getUtxoValue(utxo), 0)
271
+ }
272
+
273
+ _getUtxoValue (utxo) {
274
+ if (utxo.sats !== undefined) {
275
+ return typeof utxo.sats === 'bigint' ? Number(utxo.sats) : parseInt(utxo.sats)
276
+ }
277
+ if (utxo.value !== undefined) {
278
+ return typeof utxo.value === 'bigint' ? Number(utxo.value) : parseInt(utxo.value)
279
+ }
280
+ return 0
271
281
  }
272
282
 
273
283
  _calculateConsolidationFee (numInputs, numOutputs, satsPerByte) {
@@ -317,11 +327,12 @@ class ConsolidateUtxos {
317
327
 
318
328
  // Only analyze pure XEC UTXOs for consolidation
319
329
  for (const utxo of pureXecUtxos) {
320
- if (utxo.value < 1000) {
330
+ const value = this._getUtxoValue(utxo)
331
+ if (value < 1000) {
321
332
  distribution.dust++
322
- } else if (utxo.value < 10000) {
333
+ } else if (value < 10000) {
323
334
  distribution.small++
324
- } else if (utxo.value < 100000) {
335
+ } else if (value < 100000) {
325
336
  distribution.medium++
326
337
  } else {
327
338
  distribution.large++
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimal-xec-wallet",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A minimalist eCash (XEC) wallet npm library, for use in web apps. Supports eTokens.",
5
5
  "main": "./index.js",
6
6
  "module": "./dist/minimal-xec-wallet.min.js",