From 3f5ebee2eeaff96aaaedf349eaf59521a132bae5 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 4 Jul 2024 15:44:45 -0600 Subject: [PATCH] probable fix for some transaction creation bug --- lib/wallets/models/tx_data.dart | 48 +++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/lib/wallets/models/tx_data.dart b/lib/wallets/models/tx_data.dart index 774d85e06..99a28a138 100644 --- a/lib/wallets/models/tx_data.dart +++ b/lib/wallets/models/tx_data.dart @@ -133,21 +133,41 @@ class TxData { .reduce((total, amount) => total += amount) : null; - Amount? get amountWithoutChange => - recipients != null && recipients!.isNotEmpty - ? recipients! - .where((e) => !e.isChange) - .map((e) => e.amount) - .reduce((total, amount) => total += amount) - : null; + Amount? get amountWithoutChange { + if (recipients != null && recipients!.isNotEmpty) { + if (recipients!.where((e) => !e.isChange).isEmpty) { + return Amount( + rawValue: BigInt.zero, + fractionDigits: recipients!.first.amount.fractionDigits, + ); + } else { + return recipients! + .where((e) => !e.isChange) + .map((e) => e.amount) + .reduce((total, amount) => total += amount); + } + } else { + return null; + } + } - Amount? get amountSparkWithoutChange => - sparkRecipients != null && sparkRecipients!.isNotEmpty - ? sparkRecipients! - .where((e) => !e.isChange) - .map((e) => e.amount) - .reduce((total, amount) => total += amount) - : null; + Amount? get amountSparkWithoutChange { + if (sparkRecipients != null && sparkRecipients!.isNotEmpty) { + if (sparkRecipients!.where((e) => !e.isChange).isEmpty) { + return Amount( + rawValue: BigInt.zero, + fractionDigits: sparkRecipients!.first.amount.fractionDigits, + ); + } else { + return sparkRecipients! + .where((e) => !e.isChange) + .map((e) => e.amount) + .reduce((total, amount) => total += amount); + } + } else { + return null; + } + } int? get estimatedSatsPerVByte => fee != null && vSize != null ? (fee!.raw ~/ BigInt.from(vSize!)).toInt()