Skip to content

Commit

Permalink
cleaned up disabled behavior for margin mode selection
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Jun 6, 2024
1 parent 026174f commit 9c93ebe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ private class dydxMarginModeViewPresenter: HostedViewPresenter<dydxMarginModeVie
case .cross:
crossItemViewModel.isSelected = true
isolatedItemViewModel.isSelected = false
isolatedItemViewModel.isDisabled = tradeInput.options?.marginModeOptions == nil
case .isolated:
crossItemViewModel.isSelected = false
crossItemViewModel.isDisabled = tradeInput.options?.marginModeOptions == nil
isolatedItemViewModel.isSelected = true
default:
assertionFailure("should have margin mode")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ private class dydxTargetLeverageViewPresenter: HostedViewPresenter<dydxTargetLev
override func start() {
super.start()

// TODO: Fix...? tradeInput?.targetLeverage is nil for now

Publishers.CombineLatest(AbacusStateManager.shared.state.configsAndAssetMap,
AbacusStateManager.shared.state.tradeInput)
.compactMap { $0 }
Expand Down
22 changes: 12 additions & 10 deletions dydx/dydxViews/dydxViews/_v4/Trade/Margin/dydxMarginModeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Utilities
public class dydxMarginModeItemViewModel: PlatformViewModel {
@Published public var title: String?
@Published public var detail: String?
@Published public var isDisabled: Bool = false
@Published public var isSelected: Bool = false
@Published public var selectedAction: (() -> Void)?

Expand All @@ -33,14 +34,16 @@ public class dydxMarginModeItemViewModel: PlatformViewModel {
HStack {
Text(self.title ?? "")
.themeFont(fontSize: .medium)
.themeColor(foreground: .textPrimary)
.themeColor(foreground: self.isDisabled ? .textTertiary : .textPrimary)

Spacer()

if self.isSelected {
self.createSelectedCheckmark(parentStyle: style)
} else {
self.createUnselectedCheckmark(parentStyle: style)
if !self.isDisabled {
if self.isSelected {
self.createSelectedCheckmark(parentStyle: style)
} else {
self.createUnselectedCheckmark(parentStyle: style)
}
}
}

Expand All @@ -52,18 +55,17 @@ public class dydxMarginModeItemViewModel: PlatformViewModel {
.padding(16)
.leftAligned()
.themeColor(background: self.isSelected ? ThemeColor.SemanticColor.layer1 : ThemeColor.SemanticColor.layer3)
.overlay(
RoundedRectangle(cornerRadius: cornerRadius)
.strokeBorder(self.isSelected ? ThemeColor.SemanticColor.colorPurple.color : ThemeColor.SemanticColor.textTertiary.color, lineWidth: 1)
)
.contentShape(RoundedRectangle(cornerRadius: cornerRadius))
.borderAndClip(style: .cornerRadius(8),
borderColor: isSelected ? .colorPurple : isDisabled ? .textTertiary : .layer7,
lineWidth: isSelected ? 2 : 1)
.wrappedViewModel

return AnyView(
PlatformButtonViewModel(content: buttonContent,
type: PlatformButtonType.iconType,
action: self.selectedAction ?? {})
.createView(parentStyle: style)
.disabled(isDisabled)
)
}
}
Expand Down

0 comments on commit 9c93ebe

Please sign in to comment.