From 7dcc2c4494ee0ee5126449aba807bc1393d71432 Mon Sep 17 00:00:00 2001 From: mike-dydx Date: Wed, 19 Jun 2024 18:18:38 -0400 Subject: [PATCH] always show positions/orders/fills in market view --- .../dydxMarketPositionViewPresenter.swift | 14 ++++++++ .../dydxMarketInfoViewBuilder.swift | 14 ++------ .../Position/dydxMarketPositionView.swift | 33 ++++++++++++++----- .../_v4/MarketInfo/dydxMarketInfoView.swift | 8 ++--- ...rtfolioPendingPositionsItemViewModel.swift | 21 ++++++------ .../Sections/dydxPortfolioPositionsView.swift | 23 ++++++------- 6 files changed, 66 insertions(+), 47 deletions(-) diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/MarketInfo/Components/dydxMarketPositionViewPresenter.swift b/dydx/dydxPresenters/dydxPresenters/_v4/MarketInfo/Components/dydxMarketPositionViewPresenter.swift index c3348de9a..3c80b6559 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/MarketInfo/Components/dydxMarketPositionViewPresenter.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/MarketInfo/Components/dydxMarketPositionViewPresenter.swift @@ -55,6 +55,20 @@ class dydxMarketPositionViewPresenter: HostedViewPresenter 0, let viewModel = viewModel { - viewModel.showPositionSection = true + } else if let pendingPosition, pendingPosition.orderCount > 0 { fillsPresenter.filterByMarketId = pendingPosition.marketId fundingPresenter.filterByMarketId = pendingPosition.marketId ordersPresenter.filterByMarketId = pendingPosition.marketId positionPresenter.position = nil positionPresenter.pendingPosition = pendingPosition - resetPresentersForVisibilityChange() - } else { - viewModel?.showPositionSection = false - for (_, presenter) in selectionPresenters { - presenter.stop() - } } + resetPresentersForVisibilityChange() } private func resetPresentersForVisibilityChange() { diff --git a/dydx/dydxViews/dydxViews/_v4/MarketInfo/Components/Position/dydxMarketPositionView.swift b/dydx/dydxViews/dydxViews/_v4/MarketInfo/Components/Position/dydxMarketPositionView.swift index 4b652d0ff..5a867de8a 100644 --- a/dydx/dydxViews/dydxViews/_v4/MarketInfo/Components/Position/dydxMarketPositionView.swift +++ b/dydx/dydxViews/dydxViews/_v4/MarketInfo/Components/Position/dydxMarketPositionView.swift @@ -11,6 +11,8 @@ import PlatformUI import Utilities public class dydxMarketPositionViewModel: PlatformViewModel { + @Published public var emptyText: String? + @Published public var takeProfitStopLossAction: (() -> Void)? @Published public var closeAction: (() -> Void)? @Published public var unrealizedPNLAmount: SignedAmountViewModel? @@ -69,20 +71,28 @@ public class dydxMarketPositionViewModel: PlatformViewModel { guard let self = self else { return AnyView(PlatformView.nilView) } return AnyView( - Group { - if let pendingPosition = self.pendingPosition { - pendingPosition.createView(parentStyle: style) - } else { - VStack { + VStack(spacing: 24) { + // check size to determine if there is current position data to display + VStack { + if let emptyText = self.emptyText { + PlaceholderViewModel(text: emptyText) + .createView() + } else { self.createCollection(parentStyle: style) - self.createButtons(parentStyle: style) - self.createList(parentStyle: style) } - .themeColor(background: .layer2) + } + + if let pendingPosition = self.pendingPosition { + VStack(spacing: 16) { + self.createPendingPositionsHeader(parentStyle: style) + pendingPosition.createView(parentStyle: style) + } + .frame(width: UIScreen.main.bounds.width - 32) } } + .themeColor(background: .layer2) .frame(width: UIScreen.main.bounds.width - 16) ) } @@ -310,6 +320,13 @@ public class dydxMarketPositionViewModel: PlatformViewModel { } .padding(.horizontal, 8) } + + private func createPendingPositionsHeader(parentStyle: ThemeStyle) -> some View { + Text(localizerPathKey: "APP.TRADE.UNOPENED_ISOLATED_POSITIONS") + .themeFont(fontSize: .larger) + .themeColor(foreground: .textSecondary) + .leftAligned() + } } #if DEBUG diff --git a/dydx/dydxViews/dydxViews/_v4/MarketInfo/dydxMarketInfoView.swift b/dydx/dydxViews/dydxViews/_v4/MarketInfo/dydxMarketInfoView.swift index ee2e5752e..5c38ce247 100644 --- a/dydx/dydxViews/dydxViews/_v4/MarketInfo/dydxMarketInfoView.swift +++ b/dydx/dydxViews/dydxViews/_v4/MarketInfo/dydxMarketInfoView.swift @@ -17,7 +17,6 @@ public class dydxMarketInfoViewModel: PlatformViewModel { @Published public var resources = dydxMarketResourcesViewModel() @Published public var configs: dydxMarketConfigsViewModel? = dydxMarketConfigsViewModel() - @Published public var showPositionSection: Bool = false @Published public var sections = dydxPortfolioSectionsViewModel() @Published public var fills = dydxPortfolioFillsViewModel() @Published public var position = dydxMarketPositionViewModel() @@ -48,7 +47,6 @@ public class dydxMarketInfoViewModel: PlatformViewModel { vm.stats = .previewValue vm.resources = .previewValue vm.configs = .previewValue - vm.showPositionSection = true vm.sections = .previewValue vm.position = .previewValue vm.orders = .previewValue @@ -70,10 +68,8 @@ public class dydxMarketInfoViewModel: PlatformViewModel { LazyVStack(pinnedViews: [.sectionHeaders]) { self.createChartPagesSection(parentStyle: style) - if self.showPositionSection { - self.createPositionSection(parentStyle: style) - Spacer(minLength: 24) - } + self.createPositionSection(parentStyle: style) + Spacer(minLength: 24) self.createStatsSection(parentStyle: style) diff --git a/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioPendingPositionsItemViewModel.swift b/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioPendingPositionsItemViewModel.swift index 97422b084..845a9ec4c 100644 --- a/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioPendingPositionsItemViewModel.swift +++ b/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioPendingPositionsItemViewModel.swift @@ -43,28 +43,27 @@ public class dydxPortfolioPendingPositionsItemViewModel: PlatformViewModel { }() private var topContent: some View { - VStack(spacing: 8) { + VStack(spacing: 12) { HStack(spacing: 8) { PlatformIconViewModel(type: .url(url: marketLogoUrl), clip: .defaultCircle, size: CGSize(width: 20, height: 20)) .createView() Text(marketName) - .themeFont(fontSize: .small) + .themeFont(fontSize: .large) .themeColor(foreground: .textSecondary) Spacer() } HStack(spacing: 0) { Text(localizerPathKey: "APP.GENERAL.MARGIN") - .themeFont(fontSize: .smaller) + .themeFont(fontSize: .medium) .themeColor(foreground: .textTertiary) Spacer() Text(margin) - .themeFont(fontSize: .smaller) + .themeFont(fontSize: .medium) .themeColor(foreground: .textSecondary) } } - .padding(.vertical, 10) } private var divider: some View { @@ -85,13 +84,11 @@ public class dydxPortfolioPendingPositionsItemViewModel: PlatformViewModel { } let viewOrders = Text(localizerPathKey: viewOrdersStringKey, params: viewOrdersStringParams) - .themeFont(fontSize: .smaller) + .themeFont(fontSize: .medium) .themeColor(foreground: .colorPurple) - .padding(.vertical, 8) let cancel = Text(localizerPathKey: "APP.GENERAL.CANCEL") - .themeFont(fontSize: .smaller) + .themeFont(fontSize: .medium) .themeColor(foreground: .colorRed) - .padding(.vertical, 8) return HStack(spacing: 0) { Button(action: viewOrdersAction, label: { viewOrders }) Spacer() @@ -103,14 +100,16 @@ public class dydxPortfolioPendingPositionsItemViewModel: PlatformViewModel { PlatformView(viewModel: self, parentStyle: parentStyle, styleKey: styleKey) { [weak self] _ in guard let self = self else { return AnyView(PlatformView.nilView) } - let horizontalPadding: CGFloat = 12 - return VStack(spacing: 0) { + let verticalPadding: CGFloat = 16 + let horizontalPadding: CGFloat = 20 + return VStack(spacing: 12) { self.topContent self.divider .padding(.horizontal, -horizontalPadding) self.bottomContent } .padding(.horizontal, horizontalPadding) + .padding(.vertical, verticalPadding) .themeColor(background: .layer3) .clipShape(.rect(cornerRadius: 10)) .wrappedInAnyView() diff --git a/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioPositionsView.swift b/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioPositionsView.swift index 629e4b4df..914a170a7 100644 --- a/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioPositionsView.swift +++ b/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioPositionsView.swift @@ -294,6 +294,7 @@ public class dydxPortfolioPositionsViewModel: PlatformViewModel { Spacer() } .padding(.horizontal, 16) + .frame(width: UIScreen.main.bounds.width - 32) .themeFont(fontSize: .small) .themeColor(foreground: .textTertiary) .wrappedViewModel @@ -301,9 +302,16 @@ public class dydxPortfolioPositionsViewModel: PlatformViewModel { private var openPositionsView: some View { LazyVStack { - let items = self.positionItems.map { $0.createView() } - ForEach(items.indices, id: \.self) { index in - items[index] + if let emptyText = self.emptyText, positionItems.isEmpty { + AnyView( + PlaceholderViewModel(text: emptyText) + .createView() + ) + } else { + let items = self.positionItems.map { $0.createView() } + ForEach(items.indices, id: \.self) { index in + items[index] + } } } } @@ -321,16 +329,9 @@ public class dydxPortfolioPositionsViewModel: PlatformViewModel { } public override func createView(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> PlatformView { - PlatformView(viewModel: self, parentStyle: parentStyle, styleKey: styleKey) { [weak self] style in + PlatformView(viewModel: self, parentStyle: parentStyle, styleKey: styleKey) { [weak self] _ in guard let self = self else { return AnyView(PlatformView.nilView) } - if let emptyText = self.emptyText, positionItems.isEmpty, pendingPositionItems.isEmpty { - return AnyView( - PlaceholderViewModel(text: emptyText) - .createView(parentStyle: style) - ) - } - return AnyView( ScrollView { VStack(spacing: 24) {