From 864e49a27c5585b77de3b4b498739f327c17998d Mon Sep 17 00:00:00 2001 From: mike-dydx <149746839+mike-dydx@users.noreply.github.com> Date: Tue, 23 Apr 2024 13:59:32 -0400 Subject: [PATCH] MOB-456 : integrate abacus validation error with button states (#145) * bump 1.6.36 -> 1.6.38 * some ui * add label accessory to platform input, split out input views into view models * clean up * add cta button * hook up button and button states * abacus? * clean up * pause * clean up * pause * fix keyboard, fix toggle clipping, fix trade input not scrollable * bump 1.6.36 -> 1.6.38 * some ui * add label accessory to platform input, split out input views into view models * clean up * add cta button * hook up button and button states * abacus? * clean up * pause * clean up * fix keyboard, fix toggle clipping, fix trade input not scrollable * clean up * clean up * bump 1.6.36 -> 1.6.38 * some ui * add label accessory to platform input, split out input views into view models * clean up * add cta button * hook up button and button states * abacus? * clean up * pause * clean up * pause * fix keyboard, fix toggle clipping, fix trade input not scrollable * clean up * clean up * add validation error handling * use localized string extension for validation error --- .../dydxTakeProfitStopLossViewPresenter.swift | 50 +++++++++++-------- .../dydxCustomAmountViewModel.swift | 7 ++- .../dydxCustomLimitPriceViewModel.swift | 15 ++++-- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/TakeProfitStopLoss/dydxTakeProfitStopLossViewPresenter.swift b/dydx/dydxPresenters/dydxPresenters/_v4/TakeProfitStopLoss/dydxTakeProfitStopLossViewPresenter.swift index 69d875fdf..4190c44ed 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/TakeProfitStopLoss/dydxTakeProfitStopLossViewPresenter.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/TakeProfitStopLoss/dydxTakeProfitStopLossViewPresenter.swift @@ -140,28 +140,21 @@ private class dydxTakeProfitStopLossViewPresenter: HostedViewPresenter Void)? + @Published public var assetId: String? { didSet { guard let assetId = assetId else { return } @@ -36,7 +40,6 @@ public class dydxCustomAmountViewModel: PlatformTextInputViewModel { slider.maximumValue = maximumValue ?? 0 } } - @Published private var isOn: Bool = false public init() { super.init( @@ -50,7 +53,7 @@ public class dydxCustomAmountViewModel: PlatformTextInputViewModel { PlatformBooleanInputViewModel(label: DataLocalizer.shared?.localize(path: "APP.GENERAL.CUSTOM_AMOUNT", params: nil), labelAccessory: nil, value: isOn.description, valueAccessoryView: nil) { [weak self] value in guard let self, let value, let isOn = Bool(value) else { return } self.isOn = isOn - self.onEdited?(isOn ? "\(minimumValue ?? 0)" : nil) + self.toggleAction?(isOn) } .createView() .padding(.trailing, 2) // swiftui bug where toggle view in a scrollview gets clipped without this diff --git a/dydx/dydxViews/dydxViews/_v4/TakeProfitStopLoss/Components/dydxCustomLimitPriceViewModel.swift b/dydx/dydxViews/dydxViews/_v4/TakeProfitStopLoss/Components/dydxCustomLimitPriceViewModel.swift index 11cdd3193..a92d0329e 100644 --- a/dydx/dydxViews/dydxViews/_v4/TakeProfitStopLoss/Components/dydxCustomLimitPriceViewModel.swift +++ b/dydx/dydxViews/dydxViews/_v4/TakeProfitStopLoss/Components/dydxCustomLimitPriceViewModel.swift @@ -13,9 +13,12 @@ import Utilities public class dydxCustomLimitPriceViewModel: PlatformViewModel { + @Published public var toggleAction: ((Bool) -> Void)? + @Published private var isOn: Bool = false @Published public var takeProfitPriceInputViewModel: dydxPriceInputViewModel? @Published public var stopLossPriceInputViewModel: dydxPriceInputViewModel? + @Published public var alert: InlineAlertViewModel? @Published private var isTooltipPresented: Bool = false private lazy var isTooltipPresentedBinding = Binding( @@ -27,6 +30,7 @@ public class dydxCustomLimitPriceViewModel: PlatformViewModel { PlatformBooleanInputViewModel(label: DataLocalizer.shared?.localize(path: "APP.TRADE.LIMIT_PRICE", params: nil), labelAccessory: nil, value: isOn.description, valueAccessoryView: nil) { [weak self] value in guard let self, let value, let isOn = Bool(value) else { return } self.isOn = isOn + self.toggleAction?(isOn) } .createView() .padding(.trailing, 2) // swiftui bug where toggle view in a scrollview gets clipped without this @@ -49,10 +53,13 @@ public class dydxCustomLimitPriceViewModel: PlatformViewModel { guard let self = self else { return PlatformView.emptyView.wrappedInAnyView() } return VStack(spacing: 15) { self.onOffSwitch - HStack(alignment: .center, spacing: 20) { - if self.isOn { - self.takeProfitPriceInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey) - self.stopLossPriceInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey) + if self.isOn { + VStack(spacing: 16) { + HStack(alignment: .center, spacing: 20) { + self.takeProfitPriceInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey) + self.stopLossPriceInputViewModel?.createView(parentStyle: parentStyle, styleKey: styleKey) + } + self.alert?.createView(parentStyle: parentStyle, styleKey: styleKey) } } }