Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aseet details and locks #787

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
21 changes: 17 additions & 4 deletions novawallet/Modules/AssetDetails/AssetDetailsPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -69,15 +79,18 @@ final class AssetDetailsPresenter {
)

let lockedBalance = viewModelFactory.createBalanceViewModel(
value: balance.locked,
value: balance.locked + totalCrowdloans,
assetDisplayInfo: chainAsset.assetDisplayInfo,
priceData: priceData,
locale: selectedLocale
)

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)
}

Expand Down Expand Up @@ -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,
Expand Down
Loading