From 20285053676d05b26df3eec9908c0593549ec71d Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 16 Dec 2024 19:34:59 -0600 Subject: [PATCH] fix: spark coin confirmations issue --- lib/wallets/isar/models/spark_coin.dart | 15 +++++++++++++++ .../wallet_mixin_interfaces/spark_interface.dart | 4 +--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/wallets/isar/models/spark_coin.dart b/lib/wallets/isar/models/spark_coin.dart index d3ef6825c..9501bf06d 100644 --- a/lib/wallets/isar/models/spark_coin.dart +++ b/lib/wallets/isar/models/spark_coin.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:isar/isar.dart'; part 'spark_coin.g.dart'; @@ -59,6 +61,19 @@ class SparkCoin { @ignore BigInt get diversifier => BigInt.parse(diversifierIntString); + int getConfirmations(int currentChainHeight) { + if (height == null || height! <= 0) return 0; + return max(0, currentChainHeight - (height! - 1)); + } + + bool isConfirmed( + int currentChainHeight, + int minimumConfirms, + ) { + final confirmations = getConfirmations(currentChainHeight); + return confirmations >= minimumConfirms; + } + SparkCoin({ required this.walletId, required this.type, diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart index fbc294e7c..5390b66d3 100644 --- a/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart +++ b/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart @@ -1071,9 +1071,7 @@ mixin SparkInterface final spendable = Amount( rawValue: unusedCoins .where( - (e) => - e.height != null && - e.height! + cryptoCurrency.minConfirms <= currentHeight, + (e) => e.isConfirmed(currentHeight, cryptoCurrency.minConfirms), ) .map((e) => e.value) .fold(BigInt.zero, (prev, e) => prev + e),