-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOB-359 Target Leverage Selection Screen
- Loading branch information
Showing
7 changed files
with
245 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...dydxPresenters/_v4/Trade/Margin/Components/dydxTargetLeverageCtaButtonViewPresenter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// dydxTargetLeverageCtaButtonViewPresenter.swift | ||
// dydxPresenters | ||
// | ||
// Created by Rui Huang on 08/05/2024. | ||
// | ||
|
||
import Utilities | ||
import dydxViews | ||
import PlatformParticles | ||
import RoutingKit | ||
import ParticlesKit | ||
import PlatformUI | ||
|
||
protocol dydxTargetLeverageCtaButtonViewPresenterProtocol: HostedViewPresenterProtocol { | ||
var viewModel: dydxTargetLeverageCtaButtonViewModel? { get } | ||
} | ||
|
||
class dydxTargetLeverageCtaButtonViewPresenter: HostedViewPresenter<dydxTargetLeverageCtaButtonViewModel>, dydxTargetLeverageCtaButtonViewPresenterProtocol { | ||
override init() { | ||
super.init() | ||
|
||
viewModel = dydxTargetLeverageCtaButtonViewModel() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
dydx/dydxViews/dydxViews/_v4/Trade/Margin/Components/dydxTargetLeverageCtaButtonView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// dydxTargetLeverageCtaButtonView.swift | ||
// dydxUI | ||
// | ||
// Created by Rui Huang on 08/05/2024. | ||
// Copyright © 2024 dYdX Trading Inc. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import PlatformUI | ||
import Utilities | ||
|
||
public class dydxTargetLeverageCtaButtonViewModel: PlatformViewModel { | ||
public enum State { | ||
case enabled(String? = nil) | ||
case disabled(String? = nil) | ||
case thinking | ||
} | ||
|
||
@Published public var ctaAction: (() -> Void)? | ||
@Published public var ctaButtonState: State = .disabled() | ||
|
||
public init() { } | ||
|
||
public static var previewValue: dydxTargetLeverageCtaButtonViewModel { | ||
let vm = dydxTargetLeverageCtaButtonViewModel() | ||
vm.ctaButtonState = .enabled("OK") | ||
return vm | ||
} | ||
|
||
public override func createView(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> PlatformView { | ||
PlatformView(viewModel: self, parentStyle: parentStyle, styleKey: styleKey) { [weak self] style in | ||
guard let self = self else { return AnyView(PlatformView.nilView) } | ||
|
||
return AnyView( | ||
self.createCtaButton(parentStyle: style) | ||
) | ||
} | ||
} | ||
|
||
private func createCtaButton(parentStyle style: ThemeStyle) -> some View { | ||
let buttonTitle: String | ||
let state: PlatformButtonState | ||
switch ctaButtonState { | ||
case .enabled(let title): | ||
buttonTitle = title ?? DataLocalizer.localize(path: "APP.TRADE.CONFIRM_LEVERAGE") | ||
state = .primary | ||
case .disabled(let title): | ||
buttonTitle = title ?? DataLocalizer.localize(path: "APP.TRADE.ADJUST_LEVERAGE") | ||
state = .disabled | ||
case .thinking: | ||
buttonTitle = DataLocalizer.localize(path: "APP.V4.CALCULATING") | ||
state = .disabled | ||
} | ||
|
||
let buttonContent = | ||
Text(buttonTitle) | ||
.wrappedViewModel | ||
|
||
return PlatformButtonViewModel(content: buttonContent, | ||
state: state) { [weak self] in | ||
PlatformView.hideKeyboard() | ||
self?.ctaAction?() | ||
} | ||
.createView(parentStyle: style) | ||
.animation(.easeInOut(duration: 0.1)) | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct dydxTargetLeverageCtaButtonView_Previews_Dark: PreviewProvider { | ||
@StateObject static var themeSettings = ThemeSettings.shared | ||
|
||
static var previews: some View { | ||
ThemeSettings.applyDarkTheme() | ||
ThemeSettings.applyStyles() | ||
return dydxTargetLeverageCtaButtonViewModel.previewValue | ||
.createView() | ||
.themeColor(background: .layer0) | ||
.environmentObject(themeSettings) | ||
// .edgesIgnoringSafeArea(.bottom) | ||
.previewLayout(.sizeThatFits) | ||
} | ||
} | ||
|
||
struct dydxTargetLeverageCtaButtonView_Previews_Light: PreviewProvider { | ||
@StateObject static var themeSettings = ThemeSettings.shared | ||
|
||
static var previews: some View { | ||
ThemeSettings.applyLightTheme() | ||
ThemeSettings.applyStyles() | ||
return dydxTargetLeverageCtaButtonViewModel.previewValue | ||
.createView() | ||
.themeColor(background: .layer0) | ||
.environmentObject(themeSettings) | ||
// .edgesIgnoringSafeArea(.bottom) | ||
.previewLayout(.sizeThatFits) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters