Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.
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
16 changes: 16 additions & 0 deletions Features/Transactions/Sources/Types/TransactionsSheetType.swift
Original file line number Diff line number Diff line change
@@ -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)"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -70,7 +68,7 @@ extension TransactionsViewModel {
}

public func onSelectFilterButton() {
isPresentingFilteringView.toggle()
isPresentingSheet = .filter
}

public func fetch() async {
Expand All @@ -95,10 +93,10 @@ extension TransactionsViewModel {
}

private func onSelectReceive() {
isPresentingSelectAssetType = .receive(.asset)
isPresentingSheet = .selectAsset(.receive(.asset))
}

private func onSelectBuy() {
isPresentingSelectAssetType = .buy
isPresentingSheet = .selectAsset(.buy)
}
}
38 changes: 20 additions & 18 deletions Gem/Navigation/Transactions/TransactionsNavigationStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
)
}
}
Comment on lines +55 to 76
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and maintainability, consider extracting the sheet's content view builder into a separate private @ViewBuilder function. This will make the body of your view cleaner and easier to read, especially since the switch statement contains non-trivial logic for each case.

For example, you could replace the closure with a method reference:

.sheet(item: $model.isPresentingSheet, content: sheetContent)

And then define the sheetContent method within your TransactionsNavigationStack struct:

@ViewBuilder
private func sheetContent(for type: TransactionsSheetType) -> some View {
    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
            )
        )
    }
}

}
}
Expand Down
Loading