Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SL/TP clean up #155

Merged
merged 5 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum dydxSettingsStoreKey: String, CaseIterable {
public var defaultValue: Any? {
switch self {
case .language: return DataLocalizer.shared?.language
case .v4Theme: return dydxThemeType.dark.rawValue
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i checked this change with Achal

case .v4Theme: return dydxThemeType.classicDark.rawValue
case .directionColorPreference: return "green_is_up"
case .shouldDisplayInAppNotifications: return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,6 @@ private class dydxTakeProfitStopLossViewPresenter: HostedViewPresenter<dydxTakeP
)
.compactMap { $0 }
.sink { [weak self] subaccountPositions, triggerOrdersInput, errors, configsMap in
#if DEBUG
if let triggerOrdersInput {
Console.shared.log("\nmmm marketId: \(triggerOrdersInput.marketId)")
Console.shared.log("mmm size: \(triggerOrdersInput.size)")
Console.shared.log("mmm stopLossOrder?.orderId: \(triggerOrdersInput.stopLossOrder?.orderId)")
Console.shared.log("mmm stopLossOrder?.size: \(triggerOrdersInput.stopLossOrder?.size?.doubleValue)")
Console.shared.log("mmm stopLossOrder?.side: \(triggerOrdersInput.stopLossOrder?.side?.rawValue)")
Console.shared.log("mmm stopLossOrder?.type: \(triggerOrdersInput.stopLossOrder?.type?.rawValue)\n")
Console.shared.log("mmm stopLossOrder?.price?.triggerPrice: \(triggerOrdersInput.stopLossOrder?.price?.triggerPrice)")
Console.shared.log("mmm stopLossOrder?.price?.limitPrice: \(triggerOrdersInput.stopLossOrder?.price?.limitPrice)")
Console.shared.log("mmm stopLossOrder?.price?.percentDiff: \(triggerOrdersInput.stopLossOrder?.price?.percentDiff)")
Console.shared.log("mmm stopLossOrder?.price?.usdcDiff: \(triggerOrdersInput.stopLossOrder?.price?.usdcDiff)")
Console.shared.log("mmm takeProfitOrder?.orderId: \(triggerOrdersInput.takeProfitOrder?.orderId)")
Console.shared.log("mmm takeProfitOrder?.size: \(triggerOrdersInput.takeProfitOrder?.size?.doubleValue)")
Console.shared.log("mmm takeProfitOrder?.side: \(triggerOrdersInput.takeProfitOrder?.side?.rawValue)\n")
Console.shared.log("mmm takeProfitOrder?.type: \(triggerOrdersInput.takeProfitOrder?.type?.rawValue)\n")
Console.shared.log("mmm takeProfitOrder?.price?.triggerPrice: \(triggerOrdersInput.takeProfitOrder?.price?.triggerPrice)")
Console.shared.log("mmm takeProfitOrder?.price?.limitPrice: \(triggerOrdersInput.takeProfitOrder?.price?.limitPrice)\n")
Console.shared.log("mmm takeProfitOrder?.price?.percentDiff: \(triggerOrdersInput.takeProfitOrder?.price?.percentDiff)")
Console.shared.log("mmm takeProfitOrder?.price?.usdcDiff: \(triggerOrdersInput.takeProfitOrder?.price?.usdcDiff)\n")
}
#endif
self?.update(subaccountPositions: subaccountPositions, triggerOrdersInput: triggerOrdersInput, errors: errors, configsMap: configsMap)
}
.store(in: &subscriptions)
Expand Down Expand Up @@ -134,7 +112,7 @@ private class dydxTakeProfitStopLossViewPresenter: HostedViewPresenter<dydxTakeP
}

private func update(market: PerpetualMarket?) {
viewModel?.oraclePrice = dydxFormatter.shared.raw(number: market?.oraclePrice?.doubleValue, digits: market?.configs?.displayTickSizeDecimals?.intValue ?? 2)
viewModel?.oraclePrice = dydxFormatter.shared.dollar(number: market?.oraclePrice?.doubleValue, digits: market?.configs?.displayTickSizeDecimals?.intValue ?? 2)
viewModel?.customAmountViewModel?.assetId = market?.assetId
viewModel?.customAmountViewModel?.stepSize = market?.configs?.stepSize?.stringValue
viewModel?.customAmountViewModel?.minimumValue = market?.configs?.minOrderSize?.floatValue
Expand Down Expand Up @@ -240,7 +218,7 @@ private class dydxTakeProfitStopLossViewPresenter: HostedViewPresenter<dydxTakeP
&& order.side.opposite == position?.side.current
}

viewModel?.entryPrice = dydxFormatter.shared.raw(number: position?.entryPrice?.current?.doubleValue,
viewModel?.entryPrice = dydxFormatter.shared.dollar(number: position?.entryPrice?.current?.doubleValue,
digits: marketConfig.displayTickSizeDecimals?.intValue ?? 2)

viewModel?.takeProfitStopLossInputAreaViewModel?.numOpenTakeProfitOrders = takeProfitOrders.count
Expand Down Expand Up @@ -397,12 +375,15 @@ private class dydxTakeProfitStopLossViewPresenter: HostedViewPresenter<dydxTakeP
if let pendingOrders = self?.pendingOrders, pendingOrders <= 0 {
Router.shared?.navigate(to: .init(path: "/action/dismiss"), animated: true, completion: nil)
}
case .failed(let error):
case .failed:
self?.pendingOrders = nil
// TODO: how to handle errors?
self?.viewModel?.submissionReadiness = .fixErrors(cta: DataLocalizer.shared?.localize(path: "APP.GENERAL.UNKNOWN_ERROR", params: nil))
}
}
// dismiss immediately if no changes
if (self?.pendingOrders ?? 0) == 0 {
Router.shared?.navigate(to: .init(path: "/action/dismiss"), animated: true, completion: nil)
}
}

self.viewModel = viewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ struct dydxGainLossInputView: View {
}

private func displayTextOnChange(newValue: String) {
guard isFocused else { return }
viewModel.onEdited?(newValue, viewModel.curUnit)
}

Expand Down
Loading