Skip to content

Commit

Permalink
MOB-573 & MOB-586 : ISO Bug - iOS: On Position Cards, show dollar amo…
Browse files Browse the repository at this point in the history
…unt PnL first (match web) (#201)

* fix liquidation price coloring

* replace app configs with forAppWithIsolatedMargins configs

* update build number for local builds

* update pnl state order MOB-573

* polish estimated liquidation price
  • Loading branch information
mike-dydx authored Jun 26, 2024
1 parent d8b9833 commit 89d02fa
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class dydxMarketPositionViewPresenter: HostedViewPresenter<dydxMarketPositionVie
}

viewModel?.unrealizedPNLAmount = sharedOrderViewModel.unrealizedPnl
viewModel?.unrealizedPNLPercent = sharedOrderViewModel.unrealizedPnlPercent
viewModel?.unrealizedPNLPercent = dydxFormatter.shared.percent(number: position.unrealizedPnlPercent.current?.doubleValue, digits: 2) ?? ""
viewModel?.realizedPNLAmount = SignedAmountViewModel(amount: position.realizedPnl.current?.doubleValue, displayType: .dollar, coloringOption: .allText)

if let margin = position.equity.current?.doubleValue, let marginMode = position.marginMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ class dydxPortfolioPositionsViewPresenter: HostedViewPresenter<dydxPortfolioPosi
item.indexPrice = dydxFormatter.shared.dollar(number: market.oraclePrice, digits: configs.displayTickSizeDecimals?.intValue ?? 0)
item.entryPrice = dydxFormatter.shared.dollar(number: position.entryPrice.current, digits: configs.displayTickSizeDecimals?.intValue ?? 0)

item.unrealizedPnl = SignedAmountViewModel(amount: position.unrealizedPnl.current?.doubleValue ?? 0, displayType: .dollar, coloringOption: .signOnly)
item.unrealizedPnlPercent = SignedAmountViewModel(amount: position.unrealizedPnlPercent.current?.doubleValue, displayType: .percent, coloringOption: .allText)
item.unrealizedPnl = SignedAmountViewModel(amount: position.unrealizedPnl.current?.doubleValue ?? 0, displayType: .dollar, coloringOption: .allText)
item.unrealizedPnlPercent = dydxFormatter.shared.percent(number: position.unrealizedPnlPercent.current?.doubleValue, digits: 2) ?? ""

if let marginMode = position.marginMode {
item.marginMode = DataLocalizer.shared?.localize(path: "APP.GENERAL.\(marginMode.rawValue)", params: nil) ?? "--"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,24 @@ private class dydxAdjustMarginInputViewPresenter: HostedViewPresenter<dydxAdjust

private func updateLiquidationPrice(input: AdjustIsolatedMarginInput, market: PerpetualMarket) {
if let displayTickSizeDecimals = market.configs?.displayTickSizeDecimals?.intValue {
let before = input.summary?.liquidationPrice
// the non-zero check here is a band-aid for an abacus bug where there is a pre- and post- state even on empty input
let after = parser.asNumber(input.amount)?.doubleValue ?? 0 > 0 ? input.summary?.liquidationPriceUpdated : nil
let curLiquidationPrice = input.summary?.liquidationPrice
let postLiquidationPrice = input.summary?.liquidationPriceUpdated
viewModel?.liquidationPrice = dydxAdjustMarginLiquidationPriceViewModel()
viewModel?.liquidationPrice?.before = dydxFormatter.shared.dollar(number: before, digits: displayTickSizeDecimals)
viewModel?.liquidationPrice?.after = after != nil ? dydxFormatter.shared.dollar(number: after, digits: displayTickSizeDecimals) : nil
if let before, let after {
if before > after {
// lowering liquidation price is "safer" so increase is the "positive" direction
viewModel?.liquidationPrice?.direction = .increase
} else if before < after {
viewModel?.liquidationPrice?.direction = .decrease
} else {
viewModel?.liquidationPrice?.before = dydxFormatter.shared.dollar(number: curLiquidationPrice, digits: displayTickSizeDecimals)
viewModel?.liquidationPrice?.after = input.summary?.positionLeverageUpdated == nil ? nil : dydxFormatter.shared.dollar(number: postLiquidationPrice, digits: displayTickSizeDecimals)
if input.summary?.positionLeverageUpdated == nil {
viewModel?.liquidationPrice?.direction = .none
} else {
switch input.type {
case .add:
// liquidation price is moving further from oracle price with less leverage
viewModel?.liquidationPrice?.direction = .safer
case .remove:
// liquidation price is moving closer to oracle price with more leverage
viewModel?.liquidationPrice?.direction = .riskier
default:
viewModel?.liquidationPrice?.direction = .none
}
} else {
viewModel?.liquidationPrice?.direction = .none
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,23 @@ public final class AbacusStateManager: NSObject {
let appConfigsV2: AppConfigsV2
if dydxBoolFeatureFlag.force_mainnet.isEnabled {
deployment = "MAINNET"
appConfigsV2 = AppConfigsV2.companion.forApp
appConfigsV2 = AppConfigsV2.companion.forAppWithIsolatedMargins
} else {
// Expose more options for Testflight build
switch Installation.source {
case .appStore:
deployment = "MAINNET"
appConfigsV2 = AppConfigsV2.companion.forApp
appConfigsV2 = AppConfigsV2.companion.forAppWithIsolatedMargins
case .debug:
// For debugging only
deployment = "DEV"
appConfigsV2 = AppConfigsV2.companion.forAppWithIsolatedMargins
case .jailBroken:
deployment = "TESTNET"
appConfigsV2 = AppConfigsV2.companion.forApp
appConfigsV2 = AppConfigsV2.companion.forAppWithIsolatedMargins
case .testFlight:
deployment = "TESTFLIGHT"
appConfigsV2 = AppConfigsV2.companion.forApp
appConfigsV2 = AppConfigsV2.companion.forAppWithIsolatedMargins
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class dydxMarketPositionViewModel: PlatformViewModel {
@Published public var closeAction: (() -> Void)?
@Published public var editMarginAction: (() -> Void)?
@Published public var unrealizedPNLAmount: SignedAmountViewModel?
@Published public var unrealizedPNLPercent: SignedAmountViewModel?
@Published public var unrealizedPNLPercent: String = ""
@Published public var realizedPNLAmount: SignedAmountViewModel?
@Published public var marginMode: String?
@Published public var margin: String?
Expand Down Expand Up @@ -52,7 +52,7 @@ public class dydxMarketPositionViewModel: PlatformViewModel {
let vm = dydxMarketPositionViewModel()
vm.closeAction = {}
vm.unrealizedPNLAmount = .previewValue
vm.unrealizedPNLPercent = .previewValue
vm.unrealizedPNLPercent = "10%"
vm.realizedPNLAmount = .previewValue
vm.marginMode = "Cross"
vm.margin = "$10"
Expand Down Expand Up @@ -108,10 +108,13 @@ public class dydxMarketPositionViewModel: PlatformViewModel {
Text(DataLocalizer.localize(path: "APP.TRADE.UNREALIZED_PNL"))
.themeFont(fontType: .plus, fontSize: .small)
.themeColor(foreground: .textTertiary)
self.unrealizedPNLAmount?
.createView(parentStyle: .defaultStyle.themeFont(fontSize: .large))
self.unrealizedPNLPercent?
.createView(parentStyle: .defaultStyle.themeFont(fontSize: .smaller).themeColor(foreground: .textTertiary))
VStack(alignment: .leading, spacing: 2) {
self.unrealizedPNLAmount?
.createView(parentStyle: .defaultStyle.themeFont(fontSize: .large))
Text(self.unrealizedPNLPercent)
.themeFont(fontSize: .smaller)
.themeColor(foreground: .textSecondary)
}
}
.wrappedInAnyView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class dydxPortfolioPositionItemViewModel: PlatformViewModel {
self.leverageIcon = leverageIcon
self.indexPrice = indexPrice
self.entryPrice = entryPrice
self.unrealizedPnlPercent = unrealizedPnlPercent
self.unrealizedPnlPercent = "10%"
self.gradientType = gradientType
self.logoUrl = logoUrl
self.handler = Handler(onTapAction: onTapAction, onMarginEditAction: onMarginEditAction)
Expand All @@ -58,7 +58,7 @@ public class dydxPortfolioPositionItemViewModel: PlatformViewModel {
public var indexPrice: String?
public var entryPrice: String?
public var unrealizedPnl: SignedAmountViewModel?
public var unrealizedPnlPercent: SignedAmountViewModel?
public var unrealizedPnlPercent: String = ""
public var marginValue: String = "--"
public var marginMode: String = "--"
public var isMarginAdjustable: Bool = false
Expand Down Expand Up @@ -146,9 +146,10 @@ public class dydxPortfolioPositionItemViewModel: PlatformViewModel {
.themeFont(fontSize: .smaller)
.themeColor(foreground: .textTertiary)

self.unrealizedPnlPercent?.createView(parentStyle: parentStyle.themeFont(fontType: .number, fontSize: .small))

self.unrealizedPnl?.createView(parentStyle: parentStyle.themeFont(fontType: .number, fontSize: .smaller).themeColor(foreground: .textTertiary))
self.unrealizedPnl?.createView(parentStyle: parentStyle.themeFont(fontType: .number, fontSize: .small))
Text(self.unrealizedPnlPercent)
.themeFont(fontSize: .smaller)
.themeColor(foreground: .textTertiary)
}
.leftAligned()
.frame(width: geo.size.width / 3)
Expand Down Expand Up @@ -228,18 +229,6 @@ public class dydxPortfolioPositionItemViewModel: PlatformViewModel {
.leftAligned()
.minimumScaleFactor(0.5)
}

private func createTrailing(parentStyle: ThemeStyle) -> some View {
HStack {
Spacer()
VStack(alignment: .trailing) {
unrealizedPnl?.createView(parentStyle: parentStyle.themeFont(fontType: .number, fontSize: .small))

unrealizedPnlPercent?.createView(parentStyle: parentStyle.themeFont(fontType: .number, fontSize: .smaller))
}
}
.frame(maxWidth: 80)
}
}

public class dydxPortfolioPositionsViewModel: PlatformViewModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import Utilities

public class dydxAdjustMarginLiquidationPriceViewModel: PlatformViewModel {
public enum Direction {
case increase, decrease, none
case safer, riskier, none

var gradientType: GradientType {
switch self {
case .increase:
case .safer:
return .plus
case .decrease:
case .riskier:
return .minus
case .none:
return .none
Expand All @@ -34,7 +34,7 @@ public class dydxAdjustMarginLiquidationPriceViewModel: PlatformViewModel {

public static var previewValue: dydxAdjustMarginLiquidationPriceViewModel {
let vm = dydxAdjustMarginLiquidationPriceViewModel()
vm.direction = .increase
vm.direction = .riskier
vm.before = "$12,000.0"
vm.before = "$12,300.0"
return vm
Expand All @@ -46,7 +46,7 @@ public class dydxAdjustMarginLiquidationPriceViewModel: PlatformViewModel {

return AnyView(
HStack {
VStack(alignment: .leading, spacing: 8) {
VStack(alignment: .leading, spacing: 0) {
Text(DataLocalizer.localize(path: "APP.GENERAL.ESTIMATED"))
.themeColor(foreground: .textTertiary)
.themeFont(fontSize: .small)
Expand All @@ -58,19 +58,23 @@ public class dydxAdjustMarginLiquidationPriceViewModel: PlatformViewModel {

Spacer()

VStack(alignment: .trailing, spacing: 8) {
VStack(alignment: .trailing, spacing: 0) {
if self.after == nil {
Text(self.before ?? "")
.themeFont(fontSize: .large)
.themeColor(foreground: .textPrimary)
} else {
Text(self.before ?? "")
.themeFont(fontSize: .medium)
.themeColor(foreground: .textSecondary)

Text(self.after ?? "")
.themeFont(fontSize: .large)
.themeColor(foreground: .textPrimary)
.themeFont(fontSize: .small)
.themeColor(foreground: .textTertiary)
HStack(spacing: 4) {
Text("")
.themeFont(fontSize: .large)
.themeColor(foreground: self.direction == .riskier ? ThemeSettings.negativeColor : ThemeSettings.positiveColor)
Text(self.after ?? "")
.themeFont(fontSize: .large)
.themeColor(foreground: .textPrimary)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions dydxV4/dydxV4.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2716,7 +2716,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = dydxV4/dydx.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5251;
CURRENT_PROJECT_VERSION = 999999999;
DEVELOPMENT_TEAM = 75C6UARB5H;
INFOPLIST_FILE = dydxV4/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
Expand All @@ -2739,7 +2739,7 @@
CODE_SIGN_ENTITLEMENTS = dydxV4/dydx.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5251;
CURRENT_PROJECT_VERSION = 999999999;
DEVELOPMENT_TEAM = 75C6UARB5H;
INFOPLIST_FILE = dydxV4/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
Expand Down
2 changes: 1 addition & 1 deletion dydxV4/dydxV4/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>18540</string>
<string>999999999</string>
<key>FirebaseAutomaticScreenReportingEnabled</key>
<false/>
<key>ITSAppUsesNonExemptEncryption</key>
Expand Down

0 comments on commit 89d02fa

Please sign in to comment.