From 355180879f88473d7080a328c6fd33e2906299f7 Mon Sep 17 00:00:00 2001 From: mike-dydx <149746839+mike-dydx@users.noreply.github.com> Date: Wed, 19 Jun 2024 18:42:35 -0400 Subject: [PATCH] unopened isolated positions pt2 follow up - empty state (#197) * remove unused files * dismiss on success, update button state on submission * multi-line receipt line item title * stubbed unopened isolated positions UI * wire up abacus data for unopened positions * put back fixed size, clean up * update button state after validation * clean up * ui tweaks * Update Package.resolved * stubbed unopened isolated positions UI * wire up abacus data for unopened positions * update button state after validation * change routing to orders tab, populate unopened isolated position * show unopened isolated position in market info view * stub UI for cancel orders * cancel orders * remove isolated checks * remove "USD" from market names * always show positions/orders/fills in market view --- .../dydxMarketPositionViewPresenter.swift | 14 ++++++++ .../dydxMarketInfoViewBuilder.swift | 14 ++------ .../dydxPortfolioOrdersViewPresenter.swift | 2 -- .../dydxPortfolioPositionsViewPresenter.swift | 2 -- .../Position/dydxMarketPositionView.swift | 33 ++++++++++++++----- .../_v4/MarketInfo/dydxMarketInfoView.swift | 8 ++--- .../Components/dydxMarketAssetItemView.swift | 4 --- .../Sections/dydxPortfolioOrdersView.swift | 1 - ...rtfolioPendingPositionsItemViewModel.swift | 21 ++++++------ .../Sections/dydxPortfolioPositionsView.swift | 25 +++++++------- 10 files changed, 66 insertions(+), 58 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/dydxPresenters/dydxPresenters/_v4/Portfolio/Components/dydxPortfolioOrdersViewPresenter.swift b/dydx/dydxPresenters/dydxPresenters/_v4/Portfolio/Components/dydxPortfolioOrdersViewPresenter.swift index c77c0ce95..f331ee241 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/Portfolio/Components/dydxPortfolioOrdersViewPresenter.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/Portfolio/Components/dydxPortfolioOrdersViewPresenter.swift @@ -36,8 +36,6 @@ class dydxPortfolioOrdersViewPresenter: HostedViewPresenter 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/Markets/Components/dydxMarketAssetItemView.swift b/dydx/dydxViews/dydxViews/_v4/Markets/Components/dydxMarketAssetItemView.swift index 35e565a53..bfa0353d7 100644 --- a/dydx/dydxViews/dydxViews/_v4/Markets/Components/dydxMarketAssetItemView.swift +++ b/dydx/dydxViews/dydxViews/_v4/Markets/Components/dydxMarketAssetItemView.swift @@ -91,10 +91,6 @@ open class dydxMarketAssetItemViewModel: PlatformViewModel { .themeColor(foreground: .textPrimary) .themeFont(fontType: .plus, fontSize: .medium) .layoutPriority(1) - Text("USD") - .themeColor(foreground: .textSecondary) - .themeFont(fontType: .plus, fontSize: .medium) - .minimumScaleFactor(0.5) } Text(sharedMarketViewModel?.volume24H ?? "") .themeFont(fontType: .base, fontSize: .small) diff --git a/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioOrdersView.swift b/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioOrdersView.swift index ea26fc5d0..5776c1f2c 100644 --- a/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioOrdersView.swift +++ b/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioOrdersView.swift @@ -182,7 +182,6 @@ public class dydxPortfolioOrderItemViewModel: PlatformViewModel { } public class dydxPortfolioOrdersViewModel: PlatformListViewModel { - @Published public var shouldDisplayIsolatedOrdersWarning: Bool = false @Published public var placeholderText: String? public override var placeholder: PlatformViewModel? { 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 28b478a52..914a170a7 100644 --- a/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioPositionsView.swift +++ b/dydx/dydxViews/dydxViews/_v4/Portfolio/Components/Sections/dydxPortfolioPositionsView.swift @@ -243,8 +243,6 @@ public class dydxPortfolioPositionItemViewModel: PlatformViewModel { } public class dydxPortfolioPositionsViewModel: PlatformViewModel { - // TODO: remove once isolated markets is supported and force released - @Published public var shouldDisplayIsolatedPositionsWarning: Bool = false @Published public var emptyText: String? @Published public var positionItems: [dydxPortfolioPositionItemViewModel] { didSet { @@ -296,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 @@ -303,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] + } } } } @@ -323,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) {