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

unopened isolated positions pt2 follow up - empty state #197

Merged
merged 20 commits into from
Jun 19, 2024
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 @@ -55,6 +55,20 @@ class dydxMarketPositionViewPresenter: HostedViewPresenter<dydxMarketPositionVie
}
.store(in: &subscriptions)

Publishers
.CombineLatest(AbacusStateManager.shared.state.onboarded,
$position.removeDuplicates())
.sink { [weak self] (onboarded, position) in
if !onboarded {
self?.viewModel?.emptyText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_POSITIONS_LOG_IN")
} else if position == nil {
self?.viewModel?.emptyText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_POSITIONS")
} else {
self?.viewModel?.emptyText = nil
}
}
.store(in: &subscriptions)

Publishers
.CombineLatest4($position.compactMap { $0 }.removeDuplicates(),
AbacusStateManager.shared.state.selectedSubaccountTriggerOrders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,28 +171,20 @@ private class dydxMarketInfoViewPresenter: HostedViewPresenter<dydxMarketInfoVie
}

private func updatePositionSection(position: SubaccountPosition?, pendingPosition: SubaccountPendingPosition?) {
if let position, position.side.current != PositionSide.none, let viewModel = viewModel {
viewModel.showPositionSection = true
if let position, position.side.current != PositionSide.none {
fillsPresenter.filterByMarketId = position.id
fundingPresenter.filterByMarketId = position.id
ordersPresenter.filterByMarketId = position.id
positionPresenter.position = position
positionPresenter.pendingPosition = nil
resetPresentersForVisibilityChange()
} else if let pendingPosition, pendingPosition.orderCount > 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class dydxPortfolioOrdersViewPresenter: HostedViewPresenter<dydxPortfolioOrdersV

AbacusStateManager.shared.state.onboarded
.sink { [weak self] onboarded in
// TODO: remove once isolated markets is supported and force released
self?.viewModel?.shouldDisplayIsolatedOrdersWarning = onboarded
Comment on lines -39 to -40
Copy link
Contributor Author

@mike-dydx mike-dydx Jun 19, 2024

Choose a reason for hiding this comment

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

newly unused, removed

if onboarded {
self?.viewModel?.placeholderText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_ORDERS")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class dydxPortfolioPositionsViewPresenter: HostedViewPresenter<dydxPortfolioPosi

AbacusStateManager.shared.state.onboarded
.sink { [weak self] onboarded in
// TODO: remove once isolated markets is supported and force released
self?.viewModel?.shouldDisplayIsolatedPositionsWarning = onboarded
if onboarded {
self?.viewModel?.emptyText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_POSITIONS")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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)
)
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -296,16 +294,24 @@ public class dydxPortfolioPositionsViewModel: PlatformViewModel {
Spacer()
}
.padding(.horizontal, 16)
.frame(width: UIScreen.main.bounds.width - 32)
.themeFont(fontSize: .small)
.themeColor(foreground: .textTertiary)
.wrappedViewModel
}

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]
}
}
}
}
Expand All @@ -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) {
Expand Down
Loading