Skip to content

Commit

Permalink
add tp/sl button and screen stub (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Aug 20, 2024
1 parent 05dcec8 commit 96901d3
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 1 deletion.
12 changes: 12 additions & 0 deletions PlatformUI/PlatformUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
02F16FE228B53A200085DC58 /* SampleStyleLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F16FE128B53A200085DC58 /* SampleStyleLabel.swift */; };
02F38BF22A9AAE3700969E06 /* CircularProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F38BF12A9AAE3700969E06 /* CircularProgressView.swift */; };
1C811E336064517E256D1290 /* Pods_iOS_PlatformUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6793D8074DF2E7FE4592138 /* Pods_iOS_PlatformUITests.framework */; };
27044F882BBB2ADF004C750D /* Text+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27044F872BBB2ADF004C750D /* Text+Ext.swift */; };
27E6A7322AB8D5F600026CB5 /* SwipeActionsViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E6A7312AB8D5F600026CB5 /* SwipeActionsViewModifier.swift */; };
6488BBDC296F6AEA0096502F /* TabItemViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6488BBDB296F6AEA0096502F /* TabItemViewModel.swift */; };
64A4DC5F29677BCB008D8E20 /* PlatformOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A4DC5E29677BCB008D8E20 /* PlatformOutput.swift */; };
Expand Down Expand Up @@ -132,6 +133,7 @@
02F16FDE28B539850085DC58 /* SampleStyle.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = SampleStyle.json; sourceTree = "<group>"; };
02F16FE128B53A200085DC58 /* SampleStyleLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleStyleLabel.swift; sourceTree = "<group>"; };
02F38BF12A9AAE3700969E06 /* CircularProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircularProgressView.swift; sourceTree = "<group>"; };
27044F872BBB2ADF004C750D /* Text+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Text+Ext.swift"; sourceTree = "<group>"; };
27E6A7312AB8D5F600026CB5 /* SwipeActionsViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeActionsViewModifier.swift; sourceTree = "<group>"; };
366BD14FE1ED4F2AF21D924E /* Pods-iOS-PlatformUI.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iOS-PlatformUI.release.xcconfig"; path = "Target Support Files/Pods-iOS-PlatformUI/Pods-iOS-PlatformUI.release.xcconfig"; sourceTree = "<group>"; };
418D5C02425B3C680BF32DA4 /* Pods_iOS_PlatformUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_iOS_PlatformUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -218,6 +220,7 @@
025B844028AACBDE0037FF7C /* Components */ = {
isa = PBXGroup;
children = (
27044F862BBB2ACB004C750D /* Extensions */,
27E6A72C2AB8D5B500026CB5 /* Utility */,
02F38BEC2A9AAE0800969E06 /* CircularProgressView */,
02714C8629E0C39D00CC1C44 /* ComboBox */,
Expand Down Expand Up @@ -365,6 +368,14 @@
path = CircularProgressView;
sourceTree = "<group>";
};
27044F862BBB2ACB004C750D /* Extensions */ = {
isa = PBXGroup;
children = (
27044F872BBB2ADF004C750D /* Text+Ext.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
27E6A72C2AB8D5B500026CB5 /* Utility */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -626,6 +637,7 @@
02714C8C29E0C3AD00CC1C44 /* ComboBox.swift in Sources */,
02F16FE228B53A200085DC58 /* SampleStyleLabel.swift in Sources */,
6488BBDC296F6AEA0096502F /* TabItemViewModel.swift in Sources */,
27044F882BBB2ADF004C750D /* Text+Ext.swift in Sources */,
0258B9EE2991C9FF0098E1BE /* PlatformWebView.swift in Sources */,
02F38BF22A9AAE3700969E06 /* CircularProgressView.swift in Sources */,
02E2C93028A1C8A400F7C3BE /* PlatformUI.docc in Sources */,
Expand Down
16 changes: 16 additions & 0 deletions PlatformUI/PlatformUI/Components/Extensions/Text+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Text+Ext.swift
// PlatformUI
//
// Created by Michael Maguire on 4/1/24.
//

import SwiftUI
import Utilities

public extension Text {
init(localizerPathKey: String, params: [String: String]? = nil) {
self = Text(DataLocalizer.shared?.localize(path: localizerPathKey, params: params) ?? "")
}
}

12 changes: 12 additions & 0 deletions dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
02FA5B7E2A12FB280045F2F5 /* dydxTransferWithdrawalViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02FA5B7D2A12FB280045F2F5 /* dydxTransferWithdrawalViewPresenter.swift */; };
02FAFA5C29D4E08E001A0903 /* dydxDebugViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02FAFA5B29D4E08E001A0903 /* dydxDebugViewBuilder.swift */; };
02FF0BD229AE92FE00781EDA /* dydxWalletListViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02FF0BD129AE92FE00781EDA /* dydxWalletListViewBuilder.swift */; };
27044F702BBB1CDF004C750D /* dydxTakeProfitStopLossViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27044F6F2BBB1CDF004C750D /* dydxTakeProfitStopLossViewPresenter.swift */; };
270BA8F32A6F278F009212EA /* dydxDebugThemeViewerBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 270BA8F22A6F278F009212EA /* dydxDebugThemeViewerBuilder.swift */; };
270E7E242A5F6B1B00136793 /* dydxTradeInputSideViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 270E7E232A5F6B1B00136793 /* dydxTradeInputSideViewPresenter.swift */; };
27351D452AC4A67900E4A563 /* dydxRestrictionsWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27351D442AC4A67900E4A563 /* dydxRestrictionsWorker.swift */; };
Expand Down Expand Up @@ -478,6 +479,7 @@
02FA5B7D2A12FB280045F2F5 /* dydxTransferWithdrawalViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTransferWithdrawalViewPresenter.swift; sourceTree = "<group>"; };
02FAFA5B29D4E08E001A0903 /* dydxDebugViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxDebugViewBuilder.swift; sourceTree = "<group>"; };
02FF0BD129AE92FE00781EDA /* dydxWalletListViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxWalletListViewBuilder.swift; sourceTree = "<group>"; };
27044F6F2BBB1CDF004C750D /* dydxTakeProfitStopLossViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTakeProfitStopLossViewPresenter.swift; sourceTree = "<group>"; };
270BA8F22A6F278F009212EA /* dydxDebugThemeViewerBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxDebugThemeViewerBuilder.swift; sourceTree = "<group>"; };
270E7E232A5F6B1B00136793 /* dydxTradeInputSideViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradeInputSideViewPresenter.swift; sourceTree = "<group>"; };
27351D442AC4A67900E4A563 /* dydxRestrictionsWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxRestrictionsWorker.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -627,6 +629,7 @@
0252A39528C10A5500C8E2C9 /* RootTab */,
02F99F2A29E4BFF90009B3E8 /* Search */,
02D1342328EB56B900B46941 /* Shared */,
27044F6D2BBB1CB0004C750D /* TakeProfitStopLoss */,
02A5C859297FBCCB00FFE1F9 /* Transfer */,
6496DC3C295E121000174CE7 /* Trade */,
0262EFA729D79EF3009889E2 /* Wallet */,
Expand Down Expand Up @@ -1315,6 +1318,14 @@
path = WalletList;
sourceTree = "<group>";
};
27044F6D2BBB1CB0004C750D /* TakeProfitStopLoss */ = {
isa = PBXGroup;
children = (
27044F6F2BBB1CDF004C750D /* dydxTakeProfitStopLossViewPresenter.swift */,
);
path = TakeProfitStopLoss;
sourceTree = "<group>";
};
2741E3712A689702000FA190 /* DirectionColorPreference */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1923,6 +1934,7 @@
02F6E71F2A8293270018F00C /* dydxProfileFeesViewPresenter.swift in Sources */,
647D0F152A9FB1C600DA7815 /* dydxFrontendAlertsProvider.swift in Sources */,
02D1345828ECF30000B46941 /* dydxMarketsSearchViewBuilder.swift in Sources */,
27044F702BBB1CDF004C750D /* dydxTakeProfitStopLossViewPresenter.swift in Sources */,
64529A4C2AE8705E000810E6 /* dydxUpdateWorker.swift in Sources */,
278A4DA42B8FDD9D003898EB /* dydxRatingsWorker.swift in Sources */,
02DDAD55292587C600CC7531 /* QRCodeDisplayBuilder.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@
"destination":"dydxPresenters.dydxClosePositionInputViewBuilder",
"presentation":"half"
},
"/trade/take_proft_stop_loss":{
"destination":"dydxPresenters.dydxTakeProfitStopLossViewBuilder",
"presentation":"half"
},
"/transfer":{
"destination":"dydxPresenters.dydxTransferViewBuilder",
"presentation":"prompt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ class dydxMarketPositionViewPresenter: HostedViewPresenter<dydxMarketPositionVie

self.viewModel = viewModel

viewModel?.shareAction = {}
// hide for now until feature work complete
#if DEBUG
viewModel?.takeProfitStopLossAction = {[weak self] in
if let assetId = self?.position?.assetId {
Router.shared?.navigate(to: RoutingRequest(path: "/trade/take_proft_stop_loss", params: ["marketId": "\(assetId)-USD"]), animated: true, completion: nil)
}
}
#endif
viewModel?.closeAction = {[weak self] in
if let assetId = self?.position?.assetId {
Router.shared?.navigate(to: RoutingRequest(path: "/trade/close", params: ["marketId": "\(assetId)-USD"]), animated: true, completion: nil)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// dydxTakeProfitStopLossViewPresenter.swift
// dydxPresenters
//
// Created by Michael Maguire on 4/1/24.
//

import dydxStateManager
import dydxViews
import ParticlesKit
import PlatformParticles
import PlatformUI
import RoutingKit
import Utilities
import PlatformRouting
import PanModal

public class dydxTakeProfitStopLossViewBuilder: NSObject, ObjectBuilderProtocol {
public func build<T>() -> T? {
let presenter = dydxTakeProfitStopLossViewPresenter()
let view = presenter.viewModel?.createView() ?? PlatformViewModel().createView()
return dydxTakeProfitStopLossViewController(presenter: presenter, view: view, configuration: .default) as? T
}
}

private class dydxTakeProfitStopLossViewController: HostingViewController<PlatformView, dydxTakeProfitStopLossViewModel> {
override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool {
if request?.path == "/trade/take_proft_stop_loss", let marketId = parser.asString(request?.params?["marketId"]) {
AbacusStateManager.shared.setMarket(market: marketId)
return true
}
return false
}
}

private protocol dydxTakeProfitStopLossViewPresenterProtocol: HostedViewPresenterProtocol {
var viewModel: dydxTakeProfitStopLossViewModel? { get }
}

private class dydxTakeProfitStopLossViewPresenter: HostedViewPresenter<dydxTakeProfitStopLossViewModel>, dydxTakeProfitStopLossViewPresenterProtocol {

override init() {
let viewModel = dydxTakeProfitStopLossViewModel()

super.init()

self.viewModel = viewModel
}
}
12 changes: 12 additions & 0 deletions dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
02FD2B8B292307A200A5609E /* LeverageRiskChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02FD2B8A292307A200A5609E /* LeverageRiskChange.swift */; };
02FF0BCE29AE928700781EDA /* dydxWalletListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02FF0BCD29AE928700781EDA /* dydxWalletListView.swift */; };
02FF0BD529AEB91900781EDA /* dydxWalletView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02FF0BD429AEB91900781EDA /* dydxWalletView.swift */; };
27044F7F2BBB1D5A004C750D /* dydxTakeProfitStopLossViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27044F7E2BBB1D5A004C750D /* dydxTakeProfitStopLossViewModel.swift */; };
270BA8CF2A6F1470009212EA /* dydxDebugThemeViewerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 270BA8CE2A6F1470009212EA /* dydxDebugThemeViewerView.swift */; };
270E7E342A5F700B00136793 /* dydxOrderbookManagerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 270E7E332A5F700B00136793 /* dydxOrderbookManagerView.swift */; };
272030182A7812B900D233B9 /* UINavigationController+SwipeBackNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272030172A7812B900D233B9 /* UINavigationController+SwipeBackNavigation.swift */; };
Expand Down Expand Up @@ -499,6 +500,7 @@
02FD2B8A292307A200A5609E /* LeverageRiskChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeverageRiskChange.swift; sourceTree = "<group>"; };
02FF0BCD29AE928700781EDA /* dydxWalletListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxWalletListView.swift; sourceTree = "<group>"; };
02FF0BD429AEB91900781EDA /* dydxWalletView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxWalletView.swift; sourceTree = "<group>"; };
27044F7E2BBB1D5A004C750D /* dydxTakeProfitStopLossViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTakeProfitStopLossViewModel.swift; sourceTree = "<group>"; };
270BA8CE2A6F1470009212EA /* dydxDebugThemeViewerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxDebugThemeViewerView.swift; sourceTree = "<group>"; };
270E7E332A5F700B00136793 /* dydxOrderbookManagerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxOrderbookManagerView.swift; sourceTree = "<group>"; };
272030172A7812B900D233B9 /* UINavigationController+SwipeBackNavigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationController+SwipeBackNavigation.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -650,6 +652,7 @@
0230375D28C11AFA00412B72 /* _v4 */ = {
isa = PBXGroup;
children = (
27044F712BBB1D44004C750D /* TakeProfitStopLoss */,
278A4D942B8FA5F5003898EB /* Rating */,
27ED364E2AD7358C00C159F5 /* Auth */,
27AAA9782ACE34B600AF3C56 /* Banner */,
Expand Down Expand Up @@ -1357,6 +1360,14 @@
path = Components;
sourceTree = "<group>";
};
27044F712BBB1D44004C750D /* TakeProfitStopLoss */ = {
isa = PBXGroup;
children = (
27044F7E2BBB1D5A004C750D /* dydxTakeProfitStopLossViewModel.swift */,
);
path = TakeProfitStopLoss;
sourceTree = "<group>";
};
270BA8C12A6F145B009212EA /* Settings */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1989,6 +2000,7 @@
02DDAD3C2925859D00CC7531 /* QRCodeDisplay.swift in Sources */,
0276FA7C2A0DB515000BDF0B /* OrderStatus.swift in Sources */,
024B7B4F28B7F85100F7C386 /* SideText.swift in Sources */,
27044F7F2BBB1D5A004C750D /* dydxTakeProfitStopLossViewModel.swift in Sources */,
64A4DB5D296620DE008D8E20 /* dydxTradeInputExecutionView.swift in Sources */,
024F47AB2964AAE200E40247 /* dydxMarketConfigsView.swift in Sources */,
64A4DB7429662629008D8E20 /* dydxTradeInputLeverageView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Utilities

public class dydxMarketPositionViewModel: PlatformViewModel {
@Published public var shareAction: (() -> Void)?
@Published public var takeProfitStopLossAction: (() -> Void)?
@Published public var closeAction: (() -> Void)?
@Published public var unrealizedPNLAmount: SignedAmountViewModel?
@Published public var unrealizedPNLPercent: String?
Expand Down Expand Up @@ -213,6 +214,22 @@ public class dydxMarketPositionViewModel: PlatformViewModel {
.createView(parentStyle: parentStyle)
}

if let takeProfitStopLossAction = self.takeProfitStopLossAction {
let content = AnyView(
HStack {
Spacer()
Text(DataLocalizer.localize(path: "APP.TRADE.ADD_TP_SL"))
.themeFont(fontSize: .medium)
Spacer()
}
)

PlatformButtonViewModel(content: content.wrappedViewModel, state: .secondary) {
takeProfitStopLossAction()
}
.createView(parentStyle: parentStyle)
}

if let closeAction = self.closeAction {
let content = AnyView(
HStack {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// dydxTakeProfitStopLossViewModel.swift
// dydxViews
//
// Created by Michael Maguire on 4/1/24.
//

import PlatformUI
import SwiftUI
import Utilities
import Introspect

public class dydxTakeProfitStopLossViewModel: PlatformViewModel {

public init() {}

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

override public func createView(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> PlatformUI.PlatformView {
PlatformView(viewModel: self, parentStyle: parentStyle, styleKey: styleKey) { [weak self] _ in
guard let self = self else { return AnyView(PlatformView.nilView) }

let view = VStack {
VStack(alignment: .leading, spacing: 6) {
Text(localizerPathKey: "APP.TRIGGERS_MODAL.PRICE_TRIGGERS")
.themeFont(fontType: .plus, fontSize: .larger)
.themeColor(foreground: .textPrimary)
.frame(maxWidth: .infinity, alignment: .leading)
Text(localizerPathKey: "APP.TRIGGERS_MODAL.PRICE_TRIGGERS_DESCRIPTION")
.themeFont(fontType: .base, fontSize: .small)
.themeColor(foreground: .textTertiary)
.frame(maxWidth: .infinity, alignment: .leading)
}
.frame(maxWidth: .infinity)
HStack(alignment: .center, spacing: 8) {
Text(localizerPathKey: "APP.GENERAL.ADVANCED")
Rectangle()
.frame(height: 1)
.themeFont(fontType: .base, fontSize: .smallest)
.themeColor(background: .textTertiary)
}
}
.padding(.top, 32)
.padding([.leading, .trailing])
.padding(.bottom, max((self.safeAreaInsets?.bottom ?? 0), 16))
.themeColor(background: .layer3)
.makeSheet(sheetStyle: .fitSize)

// make it visible under the tabbar
return AnyView(view.ignoresSafeArea(edges: [.bottom]))
}
}
}

#Preview {
dydxTakeProfitStopLossViewModel.previewValue
.createView()
.previewLayout(.fixed(width: 375, height: 667))
.previewDisplayName("dydxTakeProfitStopLossViewModel")
}

0 comments on commit 96901d3

Please sign in to comment.