diff --git a/lib/models/isar/models/blockchain_data/v2/transaction_v2.dart b/lib/models/isar/models/blockchain_data/v2/transaction_v2.dart index 9acb5f9ee..5d6bfe5c5 100644 --- a/lib/models/isar/models/blockchain_data/v2/transaction_v2.dart +++ b/lib/models/isar/models/blockchain_data/v2/transaction_v2.dart @@ -68,6 +68,12 @@ class TransactionV2 { } Amount getFee({required Coin coin}) { + // try anon fee first + final fee = _getAnonFee(); + if (fee != null) { + return fee; + } + final inSum = inputs.map((e) => e.value).reduce((value, element) => value += element); final outSum = outputs @@ -99,7 +105,7 @@ class TransactionV2 { .where((e) => e.walletOwns) .fold(BigInt.zero, (p, e) => p + e.value); - return Amount( + final amount = Amount( rawValue: inSum, fractionDigits: coin.decimals, ) - @@ -107,6 +113,8 @@ class TransactionV2 { coin: coin, ) - getFee(coin: coin); + + return amount; } Set<String> associatedAddresses() => { @@ -114,7 +122,7 @@ class TransactionV2 { ...outputs.map((e) => e.addresses).expand((e) => e), }; - Amount? getAnonFee() { + Amount? _getAnonFee() { try { final map = jsonDecode(otherData!) as Map; return Amount.fromSerializedJsonString(map["anonFees"] as String); diff --git a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart index eda2f2bc0..42dd20c7a 100644 --- a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart +++ b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart @@ -96,12 +96,7 @@ class _TransactionV2DetailsViewState minConfirms = ref.read(pWallets).getWallet(walletId).cryptoCurrency.minConfirms; - if (_transaction.subType == TransactionSubType.join || - _transaction.subType == TransactionSubType.sparkSpend) { - fee = _transaction.getAnonFee()!; - } else { - fee = _transaction.getFee(coin: coin); - } + fee = _transaction.getFee(coin: coin); if (_transaction.subType == TransactionSubType.cashFusion || _transaction.type == TransactionType.sentToSelf) { diff --git a/lib/pages_desktop_specific/spark_coins/spark_coins_view.dart b/lib/pages_desktop_specific/spark_coins/spark_coins_view.dart index 5bc9bbb32..57103c80d 100644 --- a/lib/pages_desktop_specific/spark_coins/spark_coins_view.dart +++ b/lib/pages_desktop_specific/spark_coins/spark_coins_view.dart @@ -139,6 +139,14 @@ class _SparkCoinsViewState extends ConsumerState<SparkCoinsView> { textAlign: TextAlign.left, ), ), + Expanded( + flex: 9, + child: Text( + "Address", + style: STextStyles.itemSubtitle(context), + textAlign: TextAlign.left, + ), + ), Expanded( flex: 3, child: Text( @@ -213,6 +221,13 @@ class _SparkCoinsViewState extends ConsumerState<SparkCoinsView> { style: STextStyles.itemSubtitle12(context), ), ), + Expanded( + flex: 9, + child: SelectableText( + _coins[index].address, + style: STextStyles.itemSubtitle12(context), + ), + ), Expanded( flex: 3, child: SelectableText( diff --git a/lib/wallets/wallet/impl/firo_wallet.dart b/lib/wallets/wallet/impl/firo_wallet.dart index fc27072be..cf545d82c 100644 --- a/lib/wallets/wallet/impl/firo_wallet.dart +++ b/lib/wallets/wallet/impl/firo_wallet.dart @@ -435,6 +435,16 @@ class FiroWallet extends Bip39HDWallet inputs.add(input); } + final totalSpentFromWallet = inputs + .where((e) => e.walletOwns) + .map((e) => e.value) + .fold(BigInt.zero, (value, element) => value + element); + + final totalReceivedInWallet = outputs + .where((e) => e.walletOwns) + .map((e) => e.value) + .fold(BigInt.zero, (value, element) => value + element); + final totalOut = outputs .map((e) => e.value) .fold(BigInt.zero, (value, element) => value + element); @@ -458,7 +468,15 @@ class FiroWallet extends Bip39HDWallet type = TransactionType.outgoing; if (wasReceivedInThisWallet) { - if (changeAmountReceivedInThisWallet + amountReceivedInThisWallet == + if (isSparkSpend) { + if (totalSpentFromWallet - + (totalReceivedInWallet + anonFees!.raw) == + BigInt.zero) { + // definitely sent all to self + type = TransactionType.sentToSelf; + } + } else if (changeAmountReceivedInThisWallet + + amountReceivedInThisWallet == totalOut) { // definitely sent all to self type = TransactionType.sentToSelf;