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

MOB-426 : add top receipt area to price triggers panel screen #127

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 @@ -303,7 +303,7 @@
"destination":"dydxPresenters.dydxClosePositionInputViewBuilder",
"presentation":"half"
},
"/trade/take_proft_stop_loss":{
"/trade/take_profit_stop_loss":{
"destination":"dydxPresenters.dydxTakeProfitStopLossViewBuilder",
"presentation":"half"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class dydxMarketPositionViewPresenter: HostedViewPresenter<dydxMarketPositionVie
#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)
Router.shared?.navigate(to: RoutingRequest(path: "/trade/take_profit_stop_loss", params: ["marketId": "\(assetId)-USD"]), animated: true, completion: nil)
}
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import RoutingKit
import Utilities
import PlatformRouting
import PanModal
import Combine

public class dydxTakeProfitStopLossViewBuilder: NSObject, ObjectBuilderProtocol {
public func build<T>() -> T? {
Expand All @@ -25,8 +26,9 @@ public class dydxTakeProfitStopLossViewBuilder: NSObject, ObjectBuilderProtocol

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"]) {
if request?.path == "/trade/take_profit_stop_loss", let marketId = parser.asString(request?.params?["marketId"]), let presenter = presenter as? dydxTakeProfitStopLossViewPresenter {
AbacusStateManager.shared.setMarket(market: marketId)
presenter.marketId = marketId
return true
}
return false
Expand All @@ -38,6 +40,25 @@ private protocol dydxTakeProfitStopLossViewPresenterProtocol: HostedViewPresente
}

private class dydxTakeProfitStopLossViewPresenter: HostedViewPresenter<dydxTakeProfitStopLossViewModel>, dydxTakeProfitStopLossViewPresenterProtocol {
fileprivate var marketId: String?

override func start() {
super.start()

guard let marketId = marketId else { return }

Publishers
.CombineLatest(AbacusStateManager.shared.state.selectedSubaccountPositions,
AbacusStateManager.shared.state.market(of: marketId))
.sink { [weak self] subaccountPositions, market in
let position = subaccountPositions.first { subaccountPosition in
subaccountPosition.id == self?.marketId
}
self?.viewModel?.entryPrice = position?.entryPrice?.current?.doubleValue
self?.viewModel?.oraclePrice = market?.oraclePrice?.doubleValue
}
.store(in: &subscriptions)
}

override init() {
let viewModel = dydxTakeProfitStopLossViewModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,63 @@ import PlatformUI
import SwiftUI
import Utilities
import Introspect
import dydxFormatter

public class dydxTakeProfitStopLossViewModel: PlatformViewModel {

@Published public var entryPrice: Double?
@Published public var oraclePrice: Double?

public init() {}

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

private func createHeader() -> some View {
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)
}

private func createReceipt() -> some View {
VStack(spacing: 12) {
createReceiptLine(titleLocalizerPathKey: "APP.TRIGGERS_MODAL.AVG_ENTRY_PRICE", dollarValue: entryPrice)
createReceiptLine(titleLocalizerPathKey: "APP.TRADE.ORACLE_PRICE", dollarValue: oraclePrice)
}
.padding(.all, 12)
.themeColor(background: .layer2)
.clipShape(.rect(cornerRadius: 8))
}

private func createReceiptLine(titleLocalizerPathKey: String, dollarValue: Double?) -> some View {
HStack(alignment: .center, spacing: 0) {
Text(localizerPathKey: titleLocalizerPathKey)
.themeFont(fontType: .base, fontSize: .small)
.themeColor(foreground: .textTertiary)
Spacer()
Text(dydxFormatter.shared.dollar(number: dollarValue, digits: 2) ?? "")
.themeFont(fontType: .number, fontSize: .small)
.themeColor(foreground: .textPrimary)
}
}

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)
let view = VStack(spacing: 18) {
self.createHeader()
self.createReceipt()
HStack(alignment: .center, spacing: 8) {
Text(localizerPathKey: "APP.GENERAL.ADVANCED")
Rectangle()
Expand Down
Loading