Skip to content
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 @@ -45,6 +45,11 @@ class dydxMarketPositionViewPresenter: HostedViewPresenter<dydxMarketPositionVie
}
}

viewModel?.onboardAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/onboard"), animated: true, completion: { /* [weak self] */ _, _ in
})
}

attachChildren(workers: childPresenters)
}

Expand Down Expand Up @@ -77,13 +82,8 @@ class dydxMarketPositionViewPresenter: HostedViewPresenter<dydxMarketPositionVie
.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
}
self?.viewModel?.isSignedIn = onboarded
self?.viewModel?.hasOpenPosition = position != nil
}
.store(in: &subscriptions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ class dydxPortfolioFillsViewPresenter: HostedViewPresenter<dydxPortfolioFillsVie
super.init()

self.viewModel = viewModel

viewModel?.onboardAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/onboard"), animated: true, completion: { /* [weak self] */ _, _ in
})
}
}

override func start() {
super.start()

AbacusStateManager.shared.state.onboarded
.sink { [weak self] onboarded in
if onboarded {
self?.viewModel?.placeholderText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_TRADES")
} else {
self?.viewModel?.placeholderText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_TRADES_LOG_IN")
}
self?.viewModel?.isSignedIn = onboarded
}
.store(in: &subscriptions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ class dydxPortfolioFundingViewPresenter: HostedViewPresenter<dydxPortfolioFundin
super.init()

self.viewModel = viewModel

viewModel?.onboardAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/onboard"), animated: true, completion: { /* [weak self] */ _, _ in
})
}
}

override func start() {
super.start()

AbacusStateManager.shared.state.onboarded
.sink { [weak self] onboarded in
if onboarded {
self?.viewModel?.placeholderText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_FUNDING")
} else {
self?.viewModel?.placeholderText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_FUNDING_LOG_IN")
}
self?.viewModel?.isSignedIn = onboarded
}
.store(in: &subscriptions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ class dydxPortfolioOrdersViewPresenter: HostedViewPresenter<dydxPortfolioOrdersV
super.init()

self.viewModel = viewModel

viewModel?.onboardAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/onboard"), animated: true, completion: { /* [weak self] */ _, _ in
})
}
}

override func start() {
super.start()

AbacusStateManager.shared.state.onboarded
.sink { [weak self] onboarded in
if onboarded {
self?.viewModel?.placeholderText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_ORDERS")
} else {
self?.viewModel?.placeholderText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_ORDERS_LOG_IN")
}
self?.viewModel?.isSignedIn = onboarded
}
.store(in: &subscriptions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class dydxPortfolioPositionsViewPresenter: HostedViewPresenter<dydxPortfolioPosi
viewModel?.vaultTapAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/vault"), animated: true, completion: nil)
}
viewModel?.onboardAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/onboard"), animated: true, completion: { /* [weak self] */ _, _ in
})
}
}

override func start() {
super.start()

AbacusStateManager.shared.state.onboarded
.sink { [weak self] onboarded in
if onboarded {
self?.viewModel?.emptyText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_POSITIONS")
} else {
self?.viewModel?.emptyText = DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_POSITIONS_LOG_IN")
}
self?.viewModel?.isSignedIn = onboarded
}
.store(in: &subscriptions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import PlatformUI
import Utilities

public class dydxMarketPositionViewModel: PlatformViewModel {
@Published public var emptyText: String?

@Published public var closeAction: (() -> Void)?
@Published public var editMarginAction: (() -> Void)?
@Published public var onboardAction: (() -> Void)?

@Published public var isSignedIn: Bool = false
@Published public var hasOpenPosition: Bool = false

@Published public var unrealizedPNLAmount: SignedAmountViewModel?
@Published public var unrealizedPNLPercent: String = ""
@Published public var realizedPNLAmount: SignedAmountViewModel?
Expand Down Expand Up @@ -72,18 +75,27 @@ public class dydxMarketPositionViewModel: PlatformViewModel {
public override func createView(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> PlatformView {
PlatformView(viewModel: self, parentStyle: parentStyle, styleKey: styleKey) { [weak self] style in
guard let self = self else { return AnyView(PlatformView.nilView) }
guard self.isSignedIn else {
return PlatformButtonViewModel(
content: Text(DataLocalizer.localize(path: "APP.GENERAL.SIGN_IN_TO_VIEW")).wrappedViewModel,
action: { self.onboardAction?() }
)
.createView(parentStyle: parentStyle)
.frame(width: UIScreen.main.bounds.width - 16)
.wrappedInAnyView()
}

return AnyView(
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 {
if self.hasOpenPosition {
self.createCollection(parentStyle: style)
self.createButtons(parentStyle: style)
self.createList(parentStyle: style)
} else {
PlaceholderViewModel(text: DataLocalizer.localize(path: "APP.GENERAL.PLACEHOLDER_NO_POSITIONS"))
.createView()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ import PlatformUI
import Utilities

public class dydxPortfolioFillsViewModel: PlatformListViewModel {
@Published public var placeholderText: String?
@Published public var isSignedIn: Bool = false
@Published public var onboardAction: (() -> Void)?

public override var placeholder: PlatformViewModel? {
let vm = PlaceholderViewModel()
vm.text = placeholderText
return vm
guard self.isSignedIn else {
return PlatformButtonViewModel(
content: Text(DataLocalizer.localize(path: "APP.GENERAL.SIGN_IN_TO_VIEW")).wrappedViewModel,
action: { self.onboardAction?() }
)
.createView()
.frame(width: UIScreen.main.bounds.width - 16)
.wrappedViewModel
}
return PlaceholderViewModel(
text: DataLocalizer.localize(path: "APP.TRADE.TRADES_EMPTY_STATE")
)
}

public init(items: [PlatformViewModel] = [], contentChanged: (() -> Void)? = nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,22 @@ public class dydxPortfolioFundingItemViewModel: PlatformViewModel {
}

public class dydxPortfolioFundingViewModel: PlatformListViewModel {
@Published public var placeholderText: String?
@Published public var isSignedIn: Bool = false
@Published public var onboardAction: (() -> Void)?

public override var placeholder: PlatformViewModel? {
let vm = PlaceholderViewModel()
vm.text = placeholderText
return vm
guard self.isSignedIn else {
return PlatformButtonViewModel(
content: Text(DataLocalizer.localize(path: "APP.GENERAL.SIGN_IN_TO_VIEW")).wrappedViewModel,
action: { self.onboardAction?() }
)
.createView()
.frame(width: UIScreen.main.bounds.width - 16)
.wrappedViewModel
}
return PlaceholderViewModel(
text: DataLocalizer.localize(path: "APP.TRADE.FUNDING_EMPTY_STATE")
)
}

public init(items: [PlatformViewModel] = [], contentChanged: (() -> Void)? = nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,22 @@ public class dydxPortfolioOrderItemViewModel: PlatformViewModel {
}

public class dydxPortfolioOrdersViewModel: PlatformListViewModel {
@Published public var placeholderText: String?
@Published public var isSignedIn: Bool = false
@Published public var onboardAction: (() -> Void)?

public override var placeholder: PlatformViewModel? {
let vm = PlaceholderViewModel()
vm.text = placeholderText
return vm
guard self.isSignedIn else {
return PlatformButtonViewModel(
content: Text(DataLocalizer.localize(path: "APP.GENERAL.SIGN_IN_TO_VIEW")).wrappedViewModel,
action: { self.onboardAction?() }
)
.createView()
.frame(width: UIScreen.main.bounds.width - 16)
.wrappedViewModel
}
return PlaceholderViewModel(
text: DataLocalizer.localize(path: "APP.TRADE.ORDER_EMPTY_STATE")
)
}

public init(items: [PlatformViewModel] = [], contentChanged: (() -> Void)? = nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ public class dydxPortfolioPositionItemViewModel: PlatformViewModel {
}

public class dydxPortfolioPositionsViewModel: PlatformViewModel {
@Published public var emptyText: String?
@Published public var positionItems: [dydxPortfolioPositionItemViewModel] {
didSet {
contentChanged?()
Expand All @@ -259,19 +258,19 @@ public class dydxPortfolioPositionsViewModel: PlatformViewModel {
@Published public var vaultBalance: String?
@Published public var vaultApy: Double?
@Published public var vaultTapAction: (() -> Void)?
@Published public var isSignedIn: Bool = false
@Published public var onboardAction: (() -> Void)?

public var contentChanged: (() -> Void)?

init(
positionItems: [dydxPortfolioPositionItemViewModel] = [],
pendingPositionItems: [dydxPortfolioPendingPositionsItemViewModel] = [],
vaultBalance: String? = nil,
vaultApy: String? = nil,
emptyText: String? = nil
vaultApy: String? = nil
) {
self.positionItems = positionItems
self.pendingPositionItems = pendingPositionItems
self.emptyText = emptyText
}

public static var previewValue: dydxPortfolioPositionsViewModel {
Expand All @@ -283,8 +282,8 @@ public class dydxPortfolioPositionsViewModel: PlatformViewModel {
pendingPositionItems: [
.previewValue
],
vaultBalance: "324.320",
emptyText: "empty")
vaultBalance: "324.320"
)
}

public var pendingPositionsHeader: PlatformViewModel? {
Expand All @@ -309,9 +308,9 @@ public class dydxPortfolioPositionsViewModel: PlatformViewModel {

private var openPositionsView: some View {
LazyVStack {
if let emptyText = self.emptyText, positionItems.isEmpty {
if positionItems.isEmpty {
AnyView(
PlaceholderViewModel(text: emptyText)
PlaceholderViewModel(text: DataLocalizer.localize(path: "APP.TRADE.POSITIONS_EMPTY_STATE"))
.createView()
)
} else {
Expand Down Expand Up @@ -398,6 +397,15 @@ 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] _ in
guard let self = self else { return AnyView(PlatformView.nilView) }
guard self.isSignedIn else {
return PlatformButtonViewModel(
content: Text(DataLocalizer.localize(path: "APP.GENERAL.SIGN_IN_TO_VIEW")).wrappedViewModel,
action: { self.onboardAction?() }
)
.createView(parentStyle: parentStyle)
.frame(width: UIScreen.main.bounds.width - 16)
.wrappedInAnyView()
}

return AnyView(
ScrollView {
Expand Down