From 9324ba58adde7e375636a71ee1a15daf79b12ab8 Mon Sep 17 00:00:00 2001 From: ERussel Date: Tue, 15 Aug 2023 10:00:45 +0300 Subject: [PATCH 1/2] fix balance calculation logic --- .../AssetDetails/AssetDetailsPresenter.swift | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/novawallet/Modules/AssetDetails/AssetDetailsPresenter.swift b/novawallet/Modules/AssetDetails/AssetDetailsPresenter.swift index 4285db85ae..292b17d25f 100644 --- a/novawallet/Modules/AssetDetails/AssetDetailsPresenter.swift +++ b/novawallet/Modules/AssetDetails/AssetDetailsPresenter.swift @@ -37,6 +37,14 @@ final class AssetDetailsPresenter { localizationManager = localizableManager } + private func hasLocks(for balance: AssetBalance, crowdloans: [CrowdloanContributionData]) -> Bool { + balance.locked > 0 || !crowdloans.isEmpty + } + + private func calculateTotalCrowdloans(for crowdloans: [CrowdloanContributionData]) -> BigUInt { + crowdloans.reduce(0) { $0 + $1.amount } + } + private func updateView() { guard let view = view else { return @@ -54,8 +62,10 @@ final class AssetDetailsPresenter { ) view.didReceive(assetModel: assetDetailsModel) + let totalCrowdloans = calculateTotalCrowdloans(for: crowdloans) + let totalBalance = viewModelFactory.createBalanceViewModel( - value: balance.totalInPlank, + value: balance.totalInPlank + totalCrowdloans, assetDisplayInfo: chainAsset.assetDisplayInfo, priceData: priceData, locale: selectedLocale @@ -69,7 +79,7 @@ final class AssetDetailsPresenter { ) let lockedBalance = viewModelFactory.createBalanceViewModel( - value: balance.locked, + value: balance.locked + totalCrowdloans, assetDisplayInfo: chainAsset.assetDisplayInfo, priceData: priceData, locale: selectedLocale @@ -77,7 +87,10 @@ final class AssetDetailsPresenter { view.didReceive(totalBalance: totalBalance) view.didReceive(transferableBalance: transferableBalance) - view.didReceive(lockedBalance: lockedBalance, isSelectable: !locks.isEmpty || !crowdloans.isEmpty) + + let isSelectable = hasLocks(for: balance, crowdloans: crowdloans) + view.didReceive(lockedBalance: lockedBalance, isSelectable: isSelectable) + view.didReceive(availableOperations: availableOperations) } @@ -173,7 +186,7 @@ extension AssetDetailsPresenter: AssetDetailsPresenterProtocol { free: balance.freeInPlank.decimal(precision: precision), reserved: balance.reservedInPlank.decimal(precision: precision), frozen: balance.frozenInPlank.decimal(precision: precision), - crowdloans: crowdloans.reduce(0) { $0 + $1.amount }.decimal(precision: precision), + crowdloans: calculateTotalCrowdloans(for: crowdloans).decimal(precision: precision), price: priceData.map { Decimal(string: $0.price) ?? 0 } ?? 0, priceChange: priceData?.dayChange ?? 0, priceId: priceData?.currencyId, From 76e056bcd738210129ce0fa2b3a9d5caddb48bb2 Mon Sep 17 00:00:00 2001 From: ERussel Date: Tue, 15 Aug 2023 10:24:15 +0300 Subject: [PATCH 2/2] fix filters for local transaction history --- .../Common/Extension/Foundation/NSPredicate+Transaction.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/novawallet/Common/Extension/Foundation/NSPredicate+Transaction.swift b/novawallet/Common/Extension/Foundation/NSPredicate+Transaction.swift index c67011abbb..4fdc503341 100644 --- a/novawallet/Common/Extension/Foundation/NSPredicate+Transaction.swift +++ b/novawallet/Common/Extension/Foundation/NSPredicate+Transaction.swift @@ -44,7 +44,7 @@ extension NSPredicate { if let filter = filter { let filterPredicate = filterTransactionsByType(filter) - return NSCompoundPredicate(orPredicateWithSubpredicates: [filterPredicate, filterByAsset]) + return NSCompoundPredicate(andPredicateWithSubpredicates: [filterByAsset, filterPredicate]) } else { return filterByAsset } @@ -93,7 +93,7 @@ extension NSPredicate { if let filter = filter { let filterPredicate = filterTransactionsByType(filter) - return NSCompoundPredicate(orPredicateWithSubpredicates: [filterPredicate, filterByAsset]) + return NSCompoundPredicate(andPredicateWithSubpredicates: [filterByAsset, filterPredicate]) } else { return filterByAsset }