diff --git a/dydx/dydxFormatter/dydxFormatter/dydxFormatter.swift b/dydx/dydxFormatter/dydxFormatter/dydxFormatter.swift index 30173c045..fa4365151 100644 --- a/dydx/dydxFormatter/dydxFormatter/dydxFormatter.swift +++ b/dydx/dydxFormatter/dydxFormatter/dydxFormatter.swift @@ -242,6 +242,18 @@ public final class dydxFormatter: NSObject, SingletonProtocol { return nil } + public func condensedDollar(number: Double?, digits: Int = 2) -> String? { + if let number = number { + let text = condensed(number: NSNumber(value: number), digits: digits) + if text?.first == "-" { + return "-$\(text?.dropFirst() ?? "")" + } else { + return "$\(text ?? "")" + } + } + return nil + } + /// formats the number as "$" or "-$" of "+$" prefixed /// - Parameters: /// - number: the number to format diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/Portfolio/Components/dydxPortfolioPositionsViewPresenter.swift b/dydx/dydxPresenters/dydxPresenters/_v4/Portfolio/Components/dydxPortfolioPositionsViewPresenter.swift index 339cf9c9d..3f0106d2f 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/Portfolio/Components/dydxPortfolioPositionsViewPresenter.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/Portfolio/Components/dydxPortfolioPositionsViewPresenter.swift @@ -64,7 +64,7 @@ class dydxPortfolioPositionsViewPresenter: HostedViewPresenter dydxVaultPositionViewModel? in guard let leverage = position.currentLeverageMultiple?.doubleValue, - let notionalValue = position.currentPosition?.usdc?.doubleValue, - let positionSize = position.currentPosition?.asset?.doubleValue, let marketId = position.marketId, // special case for fake USDC market to show unused margin let assetId = marketId == "USDC-USD" ? "USDC" : marketMap[marketId]?.assetId, let displayId = assetMap[assetId]?.id ?? marketMap[marketId]?.displayId else { return nil } + let equity = position.marginUsdc?.doubleValue ?? 0 + let notionalValue = position.currentPosition?.usdc?.doubleValue ?? 0 + let positionSize = position.currentPosition?.asset?.doubleValue ?? 0 let iconType: PlatformIconViewModel.IconType let tokenUnitPrecision: Int if marketId == "USDC-USD" { @@ -113,6 +114,7 @@ private class dydxVaultViewBuilderPresenter: HostedViewPresenter 0 ? .long : .short, leverage: leverage, + equity: equity, notionalValue: notionalValue, positionSize: positionSize.magnitude, tokenUnitPrecision: tokenUnitPrecision, @@ -121,7 +123,7 @@ private class dydxVaultViewBuilderPresenter: HostedViewPresenter $1.notionalValue }) + .sorted(by: { $0.equity > $1.equity }) } private func updateChartState(vault: Abacus.Vault?, valueType: dydxVaultChartViewModel.ValueTypeOption, timeType: dydxVaultChartViewModel.ValueTimeOption) { diff --git a/dydx/dydxViews/dydxViews/_v4/Vault/Landing/dydxVaultPositionView.swift b/dydx/dydxViews/dydxViews/_v4/Vault/Landing/dydxVaultPositionView.swift index 4ff7a447f..3ada512b6 100644 --- a/dydx/dydxViews/dydxViews/_v4/Vault/Landing/dydxVaultPositionView.swift +++ b/dydx/dydxViews/dydxViews/_v4/Vault/Landing/dydxVaultPositionView.swift @@ -18,6 +18,7 @@ public class dydxVaultPositionViewModel: PlatformViewModel { @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 equity: Double @Published public var notionalValue: Double @Published public var positionSize: Double @Published public var tokenUnitPrecision: Int @@ -36,11 +37,13 @@ public class dydxVaultPositionViewModel: PlatformViewModel { } fileprivate var notionalValueText: String { - dydxFormatter.shared.dollar(number: notionalValue) ?? "--" + let size = dydxFormatter.shared.condensedDollar(number: notionalValue) ?? "--" + let equity = dydxFormatter.shared.condensedDollar(number: equity) ?? "--" + return "\(size) / \(equity)" } fileprivate var positionSizeText: String { - dydxFormatter.shared.localFormatted(number: positionSize, digits: tokenUnitPrecision) ?? "--" + dydxFormatter.shared.condensed(number: positionSize, digits: tokenUnitPrecision) ?? "--" } fileprivate var pnlColor: ThemeColor.SemanticColor { @@ -52,7 +55,7 @@ public class dydxVaultPositionViewModel: PlatformViewModel { } fileprivate var pnlAmountText: String { - dydxFormatter.shared.dollar(number: pnlAmount) ?? "--" + dydxFormatter.shared.dollar(number: pnlAmount, digits: 0) ?? "--" } fileprivate var pnlPercentageText: String { @@ -64,6 +67,7 @@ public class dydxVaultPositionViewModel: PlatformViewModel { iconType: PlatformIconViewModel.IconType, side: SideTextViewModel.Side, leverage: Double, + equity: Double, notionalValue: Double, positionSize: Double, tokenUnitPrecision: Int, @@ -74,6 +78,7 @@ public class dydxVaultPositionViewModel: PlatformViewModel { self.iconType = iconType self.side = side self.leverage = leverage + self.equity = equity self.notionalValue = notionalValue self.positionSize = positionSize self.tokenUnitPrecision = tokenUnitPrecision diff --git a/dydx/dydxViews/dydxViews/_v4/Vault/Landing/dydxVaultViewModel.swift b/dydx/dydxViews/dydxViews/_v4/Vault/Landing/dydxVaultViewModel.swift index f2235ce7d..511171acf 100644 --- a/dydx/dydxViews/dydxViews/_v4/Vault/Landing/dydxVaultViewModel.swift +++ b/dydx/dydxViews/dydxViews/_v4/Vault/Landing/dydxVaultViewModel.swift @@ -234,7 +234,9 @@ private struct dydxVaultView: View { .leftAligned() .frame(width: VaultPositionView.marketSectionWidth) .lineLimit(1) - Text(DataLocalizer.shared?.localize(path: "APP.GENERAL.SIZE", params: nil) ?? "") + let sizeText = DataLocalizer.shared?.localize(path: "APP.GENERAL.SIZE", params: nil) ?? "" + let equityText = DataLocalizer.shared?.localize(path: "APP.GENERAL.EQUITY", params: nil) ?? "" + Text(sizeText + " / " + equityText) .themeColor(foreground: .textTertiary) .themeFont(fontType: .base, fontSize: .small) .lineLimit(1)