-
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.
- Loading branch information
Showing
11 changed files
with
349 additions
and
9 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
70 changes: 70 additions & 0 deletions
70
...esenters/_v4/SimpleUI/MarketInfo/components/dydxSimpleUIMarketPositionViewPresenter.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,70 @@ | ||
// | ||
// dydxSimpleUIMarketPositionViewPresenter.swift | ||
// dydxPresenters | ||
// | ||
// Created by Rui Huang on 26/12/2024. | ||
// | ||
|
||
import Utilities | ||
import dydxViews | ||
import PlatformParticles | ||
import RoutingKit | ||
import ParticlesKit | ||
import PlatformUI | ||
import dydxStateManager | ||
import Abacus | ||
import Combine | ||
import dydxFormatter | ||
|
||
protocol dydxSimpleUIMarketPositionViewPresenterProtocol: HostedViewPresenterProtocol { | ||
var viewModel: dydxSimpleUIMarketPositionViewModel? { get } | ||
} | ||
|
||
class dydxSimpleUIMarketPositionViewPresenter: HostedViewPresenter<dydxSimpleUIMarketPositionViewModel>, dydxSimpleUIMarketPositionViewPresenterProtocol { | ||
@Published var marketId: String? | ||
|
||
override init() { | ||
super.init() | ||
|
||
viewModel = dydxSimpleUIMarketPositionViewModel() | ||
} | ||
|
||
override func start() { | ||
super.start() | ||
|
||
Publishers | ||
.CombineLatest4(AbacusStateManager.shared.state.selectedSubaccountPositions, | ||
$marketId, | ||
AbacusStateManager.shared.state.marketMap, | ||
AbacusStateManager.shared.state.assetMap) | ||
.sink { [weak self] position, marketId, marketMap, assetMap in | ||
let position = position.first { position in | ||
position.id == marketId && | ||
(position.side.current == Abacus.PositionSide.long_ || position.side.current == Abacus.PositionSide.short_) | ||
} | ||
self?.updatePositionSection(position: position, marketMap: marketMap, assetMap: assetMap) | ||
} | ||
.store(in: &subscriptions) | ||
} | ||
|
||
private func updatePositionSection(position: SubaccountPosition?, marketMap: [String: PerpetualMarket], assetMap: [String: Asset]) { | ||
guard let position, let sharedOrderViewModel = dydxPortfolioPositionsViewPresenter.createPositionViewModelItem(position: position, | ||
marketMap: marketMap, | ||
assetMap: assetMap) | ||
else { | ||
viewModel?.side = nil // hide the view | ||
return | ||
} | ||
|
||
viewModel?.symbol = sharedOrderViewModel.token?.symbol | ||
viewModel?.unrealizedPNLAmount = sharedOrderViewModel.unrealizedPnl | ||
viewModel?.size = sharedOrderViewModel.size | ||
viewModel?.side = SideTextViewModel(side: sharedOrderViewModel.sideText.side, coloringOption: .withBackground) | ||
viewModel?.liquidationPrice = sharedOrderViewModel.liquidationPrice | ||
viewModel?.entryPrice = sharedOrderViewModel.entryPrice | ||
|
||
viewModel?.logoUrl = sharedOrderViewModel.logoUrl | ||
viewModel?.amount = dydxFormatter.shared.dollar(number: position.notionalTotal.current?.doubleValue, digits: 2) | ||
viewModel?.funding = SignedAmountViewModel(amount: position.netFunding?.doubleValue, displayType: .dollar, coloringOption: .allText) | ||
} | ||
} |
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
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
Oops, something went wrong.