Skip to content

Commit

Permalink
add multiple orders view when more than one tp/sl exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Apr 4, 2024
1 parent 25cd4d1 commit bce391b
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public extension View {
modifier(BorderModifier(cornerRadius: cornerRadius, borderWidth: borderWidth, borderColor: borderColor))
}

func borderAndClip(style: BorderAndClipStyle, borderColor: ThemeColor.SemanticColor, lineWidth: CGFloat) -> some View {
func borderAndClip(style: BorderAndClipStyle, borderColor: ThemeColor.SemanticColor, lineWidth: CGFloat = 1) -> some View {
modifier(BorderAndClipModifier(style: style, borderColor: borderColor, lineWidth: lineWidth))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ private class dydxTakeProfitStopLossViewPresenter: HostedViewPresenter<dydxTakeP
let viewModel = dydxTakeProfitStopLossViewModel()

viewModel.takeProfitStopLossInputAreaViewModel = dydxTakeProfitStopLossInputAreaModel()
viewModel.takeProfitStopLossInputAreaViewModel?.multipleOrdersExistViewModel = .init()
viewModel.takeProfitStopLossInputAreaViewModel?.takeProfitPriceInputViewModel = .init(triggerType: .takeProfit)
viewModel.takeProfitStopLossInputAreaViewModel?.gainInputViewModel = .init(triggerType: .takeProfit)
viewModel.takeProfitStopLossInputAreaViewModel?.stopLossPriceInputViewModel = .init(triggerType: .stopLoss)
viewModel.takeProfitStopLossInputAreaViewModel?.lossInputViewModel = .init(triggerType: .stopLoss)

super.init()

// set up edit actions
viewModel.takeProfitStopLossInputAreaViewModel?.takeProfitPriceInputViewModel?.onEdited = {
AbacusStateManager.shared.triggerOrders(input: $0, type: .takeprofitprice)
}
Expand All @@ -143,6 +145,11 @@ private class dydxTakeProfitStopLossViewPresenter: HostedViewPresenter<dydxTakeP
AbacusStateManager.shared.triggerOrders(input: $0, type: .stoplossusdcdiff)
}

// set up button interactions
viewModel.takeProfitStopLossInputAreaViewModel?.multipleOrdersExistViewModel?.viewAllAction = {
Router.shared?.navigate(to: .init(path: "/portfolio/orders"), animated: true, completion: nil)
}

self.viewModel = viewModel
}
}
Expand Down
4 changes: 4 additions & 0 deletions dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
27A799B92A66EC2D007C3D04 /* ThemeClassicDark.json in Resources */ = {isa = PBXBuildFile; fileRef = 27A799B82A66EC2D007C3D04 /* ThemeClassicDark.json */; };
27AAA9862ACE34C800AF3C56 /* SwiftMessages+Banner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27AAA9852ACE34C800AF3C56 /* SwiftMessages+Banner.swift */; };
27C027452AFD734800E92CCB /* dydxSettingsHelpRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27C027442AFD734800E92CCB /* dydxSettingsHelpRowView.swift */; };
27CDA3D42BBF1AD700FEAFFE /* dydxMultipleOrdersExistViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27CDA3D32BBF1AD700FEAFFE /* dydxMultipleOrdersExistViewModel.swift */; };
27ED340C2AD47CB100C159F5 /* dydxBannerErrorAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27ED340B2AD47CB100C159F5 /* dydxBannerErrorAlert.swift */; };
27ED365C2AD735A800C159F5 /* dydxSecurityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27ED365B2AD735A800C159F5 /* dydxSecurityView.swift */; };
27F624112BBD9FEB00AB6D1A /* dydxTriggerPriceInputViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27F624042BBD9FEB00AB6D1A /* dydxTriggerPriceInputViewModel.swift */; };
Expand Down Expand Up @@ -529,6 +530,7 @@
27A799B82A66EC2D007C3D04 /* ThemeClassicDark.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ThemeClassicDark.json; sourceTree = "<group>"; };
27AAA9852ACE34C800AF3C56 /* SwiftMessages+Banner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftMessages+Banner.swift"; sourceTree = "<group>"; };
27C027442AFD734800E92CCB /* dydxSettingsHelpRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSettingsHelpRowView.swift; sourceTree = "<group>"; };
27CDA3D32BBF1AD700FEAFFE /* dydxMultipleOrdersExistViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxMultipleOrdersExistViewModel.swift; sourceTree = "<group>"; };
27ED340B2AD47CB100C159F5 /* dydxBannerErrorAlert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxBannerErrorAlert.swift; sourceTree = "<group>"; };
27ED365B2AD735A800C159F5 /* dydxSecurityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSecurityView.swift; sourceTree = "<group>"; };
27F624042BBD9FEB00AB6D1A /* dydxTriggerPriceInputViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxTriggerPriceInputViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1381,6 +1383,7 @@
27F624042BBD9FEB00AB6D1A /* dydxTriggerPriceInputViewModel.swift */,
2728CE1A2BBCD2AB004C9323 /* dydxGainLossInputViewModel.swift */,
27F624122BBDB4D400AB6D1A /* dydxTakeProfitStopLossInputAreaViewModel.swift */,
27CDA3D32BBF1AD700FEAFFE /* dydxMultipleOrdersExistViewModel.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -1895,6 +1898,7 @@
0246DE5E28B984C700A7FF1F /* Wallets2View.swift in Sources */,
27C027452AFD734800E92CCB /* dydxSettingsHelpRowView.swift in Sources */,
0253155129BFA62700D6CC9B /* dydxOnboardScanInstructionsView.swift in Sources */,
27CDA3D42BBF1AD700FEAFFE /* dydxMultipleOrdersExistViewModel.swift in Sources */,
024B7B5C28B7F90100F7C386 /* dydxViewBundleClass.swift in Sources */,
02A9B60C29005A3F00AE1516 /* AmountChange.swift in Sources */,
64A4DB5329662070008D8E20 /* dydxTradeInputSizeView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// dydxMultipleOrdersExistViewModel.swift
// dydxUI
//
// Created by Michael Maguire on 4/4/24.
// Copyright © 2024 dYdX Trading Inc. All rights reserved.
//

import SwiftUI
import PlatformUI

public class dydxMultipleOrdersExistViewModel: PlatformViewModel {
@Published public var viewAllAction: (() -> Void)?

public static var previewValue: dydxMultipleOrdersExistViewModel = {
let vm = dydxMultipleOrdersExistViewModel()
return vm
}()

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) }

return HStack(spacing: 0) {
Text(localizerPathKey: "APP.TRIGGERS_MODAL.MULTIPLE_ORDERS_FOUND")
.themeColor(foreground: .textPrimary)
.themeFont(fontType: .base, fontSize: .medium)
Spacer()
Text(localizerPathKey: "APP.GENERAL.VIEW_ALL")
.themeColor(foreground: .colorPurple)
.themeFont(fontType: .plus, fontSize: .medium)
.onTapGesture { [weak self] in
self?.viewAllAction?()
}
}
.padding(.horizontal, 14)
.padding(.vertical, 16)
.borderAndClip(style: .cornerRadius(8), borderColor: .layer7)
.wrappedInAnyView()
}
}
}

#if DEBUG
struct dydxMultipleOrdersExistViewModel_Previews: PreviewProvider {
@StateObject static var themeSettings = ThemeSettings.shared

static var previews: some View {
Group {
dydxMultipleOrdersExistViewModel.previewValue
.createView()
.environmentObject(themeSettings)
.previewLayout(.sizeThatFits)
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ import Utilities

public class dydxTakeProfitStopLossInputAreaModel: PlatformViewModel {

@Published public var openTakeProfitOrders: Int?
@Published public var numOpenTakeProfitOrders: Int?
@Published public var takeProfitPriceInputViewModel: dydxTriggerPriceInputViewModel?
@Published public var gainInputViewModel: dydxGainLossInputViewModel?

@Published public var openStopLossOrders: Int?
@Published public var numOpenStopLossOrders: Int?
@Published public var stopLossPriceInputViewModel: dydxTriggerPriceInputViewModel?
@Published public var lossInputViewModel: dydxGainLossInputViewModel?

@Published public var multipleOrdersExistViewModel: dydxMultipleOrdersExistViewModel?
private var hasMultipleTakeProfitOrders: Bool { (numOpenTakeProfitOrders ?? 0) > 1 }
private var hasMultipleStopLossOrders: Bool { (numOpenStopLossOrders ?? 0) > 1 }

@Published private var isTakeProfitTooltipPresented: Bool = false
private lazy var isTakeProfitTooltipPresentedBinding = Binding(
get: { [weak self] in self?.isTakeProfitTooltipPresented == true },
Expand Down Expand Up @@ -131,16 +133,24 @@ public class dydxTakeProfitStopLossInputAreaModel: PlatformViewModel {
return VStack(alignment: .leading, spacing: 16) {
VStack(alignment: .leading, spacing: 16) {
self.createSectionHeader(triggerType: .takeProfit)
HStack(spacing: 12) {
self.takeProfitPriceInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey)
self.gainInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey)
if self.hasMultipleTakeProfitOrders {
self.multipleOrdersExistViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey)
} else {
HStack(spacing: 12) {
self.takeProfitPriceInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey)
self.gainInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey)
}
}
}
VStack(alignment: .leading, spacing: 16) {
self.createSectionHeader(triggerType: .stopLoss)
HStack(spacing: 12) {
self.stopLossPriceInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey)
self.lossInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey)
if self.hasMultipleStopLossOrders {
self.multipleOrdersExistViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey)
} else {
HStack(spacing: 12) {
self.stopLossPriceInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey)
self.lossInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey)
}
}
}
}
Expand Down

0 comments on commit bce391b

Please sign in to comment.