-
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-493 iOS - Adjust margin screen for isolated margin UI (#162)
* MOB-483 Add isolated / cross margin mode button, Add target leverage button * MOB-357 Margin Mode Selection Screen * WIP * MOB-359 Target Leverage Selection Screen * MOB-493 Adjust margin screen for isolated margin UI
- Loading branch information
Showing
20 changed files
with
1,016 additions
and
15 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
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
...s/dydxPresenters/_v4/Trade/Margin/Components/dydxAdjustMarginCtaButtonViewPresenter.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 @@ | ||
// | ||
// dydxAdjustMarginCtaButtonViewPresenter.swift | ||
// dydxPresenters | ||
// | ||
// Created by Rui Huang on 09/05/2024. | ||
// | ||
|
||
import Utilities | ||
import dydxViews | ||
import PlatformParticles | ||
import RoutingKit | ||
import ParticlesKit | ||
import PlatformUI | ||
|
||
protocol dydxAdjustMarginCtaButtonViewPresenterProtocol: HostedViewPresenterProtocol { | ||
var viewModel: dydxAdjustMarginCtaButtonViewModel? { get } | ||
} | ||
|
||
class dydxAdjustMarginCtaButtonViewPresenter: HostedViewPresenter<dydxAdjustMarginCtaButtonViewModel>, dydxAdjustMarginCtaButtonViewPresenterProtocol { | ||
override init() { | ||
super.init() | ||
|
||
viewModel = dydxAdjustMarginCtaButtonViewModel() | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
dydx/dydxPresenters/dydxPresenters/_v4/Trade/Margin/dydxAdjustMarginInputViewBuilder.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,95 @@ | ||
// | ||
// dydxAdjustMarginInputViewBuilder.swift | ||
// dydxPresenters | ||
// | ||
// Created by Rui Huang on 08/05/2024. | ||
// | ||
|
||
import Utilities | ||
import dydxViews | ||
import PlatformParticles | ||
import RoutingKit | ||
import ParticlesKit | ||
import PlatformUI | ||
import dydxStateManager | ||
import Abacus | ||
import Combine | ||
import dydxFormatter | ||
|
||
public class dydxAdjustMarginInputViewBuilder: NSObject, ObjectBuilderProtocol { | ||
public func build<T>() -> T? { | ||
let presenter = dydxAdjustMarginInputViewPresenter() | ||
let view = presenter.viewModel?.createView() ?? PlatformViewModel().createView() | ||
return dydxAdjustMarginInputViewController(presenter: presenter, view: view, configuration: .default) as? T | ||
} | ||
} | ||
|
||
private class dydxAdjustMarginInputViewController: HostingViewController<PlatformView, dydxAdjustMarginInputViewModel> { | ||
override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool { | ||
if request?.path == "/trade/adjust_margin", let marketId = parser.asString(request?.params?["marketId"]) { | ||
let presenter = presenter as? dydxAdjustMarginInputViewPresenterProtocol | ||
presenter?.marketId = marketId | ||
return true | ||
} | ||
return false | ||
} | ||
} | ||
|
||
private protocol dydxAdjustMarginInputViewPresenterProtocol: HostedViewPresenterProtocol { | ||
var viewModel: dydxAdjustMarginInputViewModel? { get } | ||
var marketId: String? { get set } | ||
} | ||
|
||
private class dydxAdjustMarginInputViewPresenter: HostedViewPresenter<dydxAdjustMarginInputViewModel>, dydxAdjustMarginInputViewPresenterProtocol { | ||
private let ctaButtonPresenter = dydxAdjustMarginCtaButtonViewPresenter() | ||
|
||
private lazy var childPresenters: [HostedViewPresenterProtocol] = [ | ||
ctaButtonPresenter | ||
] | ||
|
||
var marketId: String? | ||
|
||
override init() { | ||
let viewModel = dydxAdjustMarginInputViewModel() | ||
|
||
ctaButtonPresenter.$viewModel.assign(to: &viewModel.$ctaButton) | ||
|
||
super.init() | ||
|
||
viewModel.marginPercentage?.percentageOptions = [ | ||
dydxAdjustMarginPercentagViewModel.PercentageOption(text: "10%", percentage: 0.1), | ||
dydxAdjustMarginPercentagViewModel.PercentageOption(text: "25%", percentage: 0.25), | ||
dydxAdjustMarginPercentagViewModel.PercentageOption(text: "50%", percentage: 0.5), | ||
dydxAdjustMarginPercentagViewModel.PercentageOption(text: "75%", percentage: 0.75) | ||
] | ||
|
||
viewModel.amount?.label = DataLocalizer.localize(path: "APP.GENERAL.AMOUNT") | ||
viewModel.amount?.placeHolder = "0.00" | ||
|
||
viewModel.liquidationPrice?.before = dydxFormatter.shared.dollar(number: 1234.56, digits: 2) | ||
|
||
self.viewModel = viewModel | ||
|
||
attachChildren(workers: childPresenters) | ||
} | ||
|
||
override func start() { | ||
super.start() | ||
|
||
if let marketId = marketId { | ||
Publishers | ||
.CombineLatest( | ||
AbacusStateManager.shared.state.market(of: marketId).compactMap { $0 }, | ||
AbacusStateManager.shared.state.assetMap) | ||
.sink { [weak self] market, assetMap in | ||
self?.updateState(market: market, assetMap: assetMap) | ||
} | ||
.store(in: &subscriptions) | ||
} | ||
} | ||
|
||
private func updateState(market: PerpetualMarket, assetMap: [String: Asset]) { | ||
let asset = assetMap[market.assetId] | ||
viewModel?.sharedMarketViewModel = SharedMarketPresenter.createViewModel(market: market, asset: asset) | ||
} | ||
} |
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
Oops, something went wrong.