Skip to content

Commit

Permalink
display USDC "market"
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Oct 17, 2024
1 parent c6f62e1 commit 9955348
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ private extension dydxTransferSearchItemViewModel {
let placeholderText = option.localizedString?.prefix(1).uppercased()
// SwiftUI does not process svgs well
if url.absoluteString.ends(with: ".svg") {
self.icon = PlatformIconViewModel(url: nil, placeholderText: placeholderText)
self.icon = PlatformIconViewModel(type: .init(url: nil, placeholderText: placeholderText))
} else {
self.icon = PlatformIconViewModel(url: url, placeholderText: placeholderText)
self.icon = PlatformIconViewModel(type: .init(url: url, placeholderText: placeholderText))
}
}
self.onTapAction = onTapAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,28 @@ private class dydxVaultViewBuilderPresenter: HostedViewPresenter<dydxVaultViewMo
let notionalValue = position.currentPosition?.usdc?.doubleValue,
let positionSize = position.currentPosition?.asset?.doubleValue,
let marketId = position.marketId,
let assetId = marketMap[marketId]?.assetId,
let asset = assetMap[assetId]
// special case for fake USDC market to show unused margin
let assetId = marketId == "USDC-USD" ? "USDC" : marketMap[marketId]?.assetId
else { return nil }
let iconType: PlatformIconViewModel.IconType
if marketId == "USDC-USD" {
iconType = .asset(name: "symbol_USDC", bundle: .dydxView)
} else {
iconType = .init(url: URL(string: assetMap[assetId]?.resources?.imageUrl ?? ""), placeholderText: assetId.first?.uppercased())
}
return dydxVaultPositionViewModel(assetId: assetId,
iconUrl: URL(string: asset.resources?.imageUrl ?? ""),
side: positionSize > 0 ? .long : .short,
leverage: leverage,
notionalValue: notionalValue,
iconType: iconType,
side: positionSize > 0 ? .long : .short,
leverage: leverage,
notionalValue: notionalValue,
positionSize: positionSize.magnitude,
tokenUnitPrecision: 2,
pnlAmount: position.thirtyDayPnl?.absolute?.doubleValue,
pnlPercentage: position.thirtyDayPnl?.percent?.doubleValue,
sparklineValues: position.thirtyDayPnl?.sparklinePoints?.map({ $0.doubleValue }))
tokenUnitPrecision: 2,
pnlAmount: position.thirtyDayPnl?.absolute?.doubleValue,
pnlPercentage: position.thirtyDayPnl?.percent?.doubleValue,
sparklineValues: position.thirtyDayPnl?.sparklinePoints?.map({ $0.doubleValue }))
}
.compactMap { $0 }
.sorted(by: { $0.notionalValue > $1.notionalValue })
}

private func updateChartState(vault: Abacus.Vault?, valueType: dydxVaultChartViewModel.ValueTypeOption, timeType: dydxVaultChartViewModel.ValueTimeOption) {
Expand Down
25 changes: 10 additions & 15 deletions dydx/dydxViews/dydxViews/Shared/PlatformUI+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@
import PlatformUI
import SwiftUI

extension PlatformIconViewModel {
/// creates a PlatformIconViewModel with a URL and placeholder Text element if the URL is unavailable
public convenience init(url: URL?, placeholderText: String?) {
if let placeholderText {
let placeholderContent = { Text(placeholderText)
.frame(width: 32, height: 32)
.themeColor(foreground: .textTertiary)
.themeColor(background: .layer5)
.borderAndClip(style: .circle, borderColor: .layer7, lineWidth: 1)
.wrappedInAnyView()
}
self.init(type: .url(url: url, placeholderContent: placeholderContent))
} else {
self.init(type: .url(url: url, placeholderContent: nil))
}
public extension PlatformIconViewModel.IconType {

init(url: URL?, placeholderText: String?) {
self = .url(url: url, placeholderContent: { Text(placeholderText ?? "")
.frame(width: 32, height: 32)
.themeColor(foreground: .textTertiary)
.themeColor(background: .layer5)
.borderAndClip(style: .circle, borderColor: .layer7, lineWidth: 1)
.wrappedInAnyView()
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class dydxAdjustMarginInputViewModel: PlatformViewModel {
HStack(spacing: 12) {
if let marketIconUrlString = self.sharedMarketViewModel?.logoUrl {
let placeholderText = self.sharedMarketViewModel?.assetName?.prefix(1).uppercased()
PlatformIconViewModel(url: marketIconUrlString, placeholderText: placeholderText)
PlatformIconViewModel(type: .init(url: marketIconUrlString, placeholderText: placeholderText))
.createView()
}
Text(DataLocalizer.localize(path: "APP.TRADE.ADJUST_ISOLATED_MARGIN"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import dydxFormatter
public class dydxVaultPositionViewModel: PlatformViewModel {

@Published public var assetId: String
@Published public var iconUrl: URL?
@Published public var iconType: PlatformIconViewModel.IconType = .init(url: nil, placeholderText: nil)
@Published public var side: SideTextViewModel.Side
@Published public var leverage: Double
@Published public var notionalValue: Double
Expand Down Expand Up @@ -61,7 +61,7 @@ public class dydxVaultPositionViewModel: PlatformViewModel {

public init(
assetId: String,
iconUrl: URL?,
iconType: PlatformIconViewModel.IconType,
side: SideTextViewModel.Side,
leverage: Double,
notionalValue: Double,
Expand All @@ -71,7 +71,7 @@ public class dydxVaultPositionViewModel: PlatformViewModel {
pnlPercentage: Double?,
sparklineValues: [Double]?) {
self.assetId = assetId
self.iconUrl = iconUrl
self.iconType = iconType
self.side = side
self.leverage = leverage
self.notionalValue = notionalValue
Expand Down Expand Up @@ -102,7 +102,7 @@ struct VaultPositionView: View {

var marketSection: some View {
HStack(spacing: 8) {
PlatformIconViewModel(url: viewModel.iconUrl, placeholderText: viewModel.assetId.prefix(1).uppercased())
PlatformIconViewModel(type: viewModel.iconType)
.createView()
VStack(alignment: .leading, spacing: 2) {
Text(viewModel.assetId)
Expand Down

0 comments on commit 9955348

Please sign in to comment.