From 468efc495ca0f2df2a1ae5aaa9c8ef4ad242dbfe Mon Sep 17 00:00:00 2001 From: Radmir Date: Thu, 26 Mar 2026 21:44:42 +0500 Subject: [PATCH] Extract TransactionsSheetType to unify sheet presentation state --- .../Sources/Types/TransactionsSheetType.swift | 16 ++++++++ .../ViewModels/TransactionsViewModel.swift | 10 ++--- .../TransactionsNavigationStack.swift | 38 ++++++++++--------- 3 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 Features/Transactions/Sources/Types/TransactionsSheetType.swift diff --git a/Features/Transactions/Sources/Types/TransactionsSheetType.swift b/Features/Transactions/Sources/Types/TransactionsSheetType.swift new file mode 100644 index 000000000..dfcbeaf5b --- /dev/null +++ b/Features/Transactions/Sources/Types/TransactionsSheetType.swift @@ -0,0 +1,16 @@ +// Copyright (c). Gem Wallet. All rights reserved. + +import Foundation +import Primitives + +public enum TransactionsSheetType: Identifiable { + case filter + case selectAsset(SelectAssetType) + + public var id: String { + switch self { + case .filter: "filter" + case .selectAsset(let type): "selectAsset-\(type.id)" + } + } +} diff --git a/Features/Transactions/Sources/ViewModels/TransactionsViewModel.swift b/Features/Transactions/Sources/ViewModels/TransactionsViewModel.swift index b63f6033c..269ebd908 100644 --- a/Features/Transactions/Sources/ViewModels/TransactionsViewModel.swift +++ b/Features/Transactions/Sources/ViewModels/TransactionsViewModel.swift @@ -26,9 +26,7 @@ public final class TransactionsViewModel { public var transactions: [TransactionExtended] { filterModel.query.value } public var filterModel: TransactionsFilterViewModel - // TODO: - separate presenting sheet state logic to separate type - public var isPresentingFilteringView: Bool = false - public var isPresentingSelectAssetType: SelectAssetType? + public var isPresentingSheet: TransactionsSheetType? public init( transactionsService: TransactionsService, @@ -70,7 +68,7 @@ extension TransactionsViewModel { } public func onSelectFilterButton() { - isPresentingFilteringView.toggle() + isPresentingSheet = .filter } public func fetch() async { @@ -95,10 +93,10 @@ extension TransactionsViewModel { } private func onSelectReceive() { - isPresentingSelectAssetType = .receive(.asset) + isPresentingSheet = .selectAsset(.receive(.asset)) } private func onSelectBuy() { - isPresentingSelectAssetType = .buy + isPresentingSheet = .selectAsset(.buy) } } diff --git a/Gem/Navigation/Transactions/TransactionsNavigationStack.swift b/Gem/Navigation/Transactions/TransactionsNavigationStack.swift index 058880bd3..7c387b760 100644 --- a/Gem/Navigation/Transactions/TransactionsNavigationStack.swift +++ b/Gem/Navigation/Transactions/TransactionsNavigationStack.swift @@ -52,25 +52,27 @@ struct TransactionsNavigationStack: View { ) ) } - .sheet(isPresented: $model.isPresentingFilteringView) { - NavigationStack { - TransactionsFilterScene(model: $model.filterModel) - } - .presentationDetentsForCurrentDeviceSize(expandable: true) - .presentationDragIndicator(.visible) - .presentationBackground(Colors.grayBackground) - } - .sheet(item: $model.isPresentingSelectAssetType) { - SelectAssetSceneNavigationStack( - model: SelectAssetViewModel( - wallet: model.wallet, - selectType: $0, - searchService: assetSearchService, - assetsEnabler: assetsEnabler, - priceAlertService: priceAlertService, - activityService: activityService + .sheet(item: $model.isPresentingSheet) { type in + switch type { + case .filter: + NavigationStack { + TransactionsFilterScene(model: $model.filterModel) + } + .presentationDetentsForCurrentDeviceSize(expandable: true) + .presentationDragIndicator(.visible) + .presentationBackground(Colors.grayBackground) + case .selectAsset(let selectType): + SelectAssetSceneNavigationStack( + model: SelectAssetViewModel( + wallet: model.wallet, + selectType: selectType, + searchService: assetSearchService, + assetsEnabler: assetsEnabler, + priceAlertService: priceAlertService, + activityService: activityService + ) ) - ) + } } } }