Skip to content

Commit

Permalink
stub UI for cancel orders
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Jun 19, 2024
1 parent d212bba commit 340627f
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 4 deletions.
2 changes: 1 addition & 1 deletion PlatformUI/PlatformUI/DesignSystem/Theme/SampleStyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"_textColor": "text_tertiary"
},
"button-destructive": {
"_layerColor": "layer_4",
"_layerColor": "layer_3",
"_textColor": "color_red"
}
}
12 changes: 12 additions & 0 deletions dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
27B957ED2B97C07400EF9304 /* dydxShareActionBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27B957EC2B97C07400EF9304 /* dydxShareActionBuilder.swift */; };
27C027532AFD761300E92CCB /* dydxSettingsHelpRowViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27C027522AFD761300E92CCB /* dydxSettingsHelpRowViewPresenter.swift */; };
27DB2EA32AC1E7B20047BC39 /* dydxTradeRestrictedViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27DB2EA22AC1E7B20047BC39 /* dydxTradeRestrictedViewPresenter.swift */; };
27E0735C2C20D2470034B963 /* dydxCancelPendingIsolatedOrdersViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E0735B2C20D2470034B963 /* dydxCancelPendingIsolatedOrdersViewBuilder.swift */; };
314BBDE9F332ECA910BC414E /* Pods_iOS_dydxPresenters.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F1551C00FFF41C29CFC5BD94 /* Pods_iOS_dydxPresenters.framework */; };
6448800B2AA248340068DD87 /* dydxAlertsWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64487FFE2AA248340068DD87 /* dydxAlertsWorker.swift */; };
645299EF2AE86FB1000810E6 /* dydxUpdateViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 645299E22AE86FB1000810E6 /* dydxUpdateViewPresenter.swift */; };
Expand Down Expand Up @@ -542,6 +543,7 @@
27B957EC2B97C07400EF9304 /* dydxShareActionBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxShareActionBuilder.swift; sourceTree = "<group>"; };
27C027522AFD761300E92CCB /* dydxSettingsHelpRowViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSettingsHelpRowViewPresenter.swift; sourceTree = "<group>"; };
27DB2EA22AC1E7B20047BC39 /* dydxTradeRestrictedViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradeRestrictedViewPresenter.swift; sourceTree = "<group>"; };
27E0735B2C20D2470034B963 /* dydxCancelPendingIsolatedOrdersViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxCancelPendingIsolatedOrdersViewBuilder.swift; sourceTree = "<group>"; };
64487FFE2AA248340068DD87 /* dydxAlertsWorker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxAlertsWorker.swift; sourceTree = "<group>"; };
645299E22AE86FB1000810E6 /* dydxUpdateViewPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxUpdateViewPresenter.swift; sourceTree = "<group>"; };
64529A4B2AE8705E000810E6 /* dydxUpdateWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxUpdateWorker.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -653,6 +655,7 @@
0230376A28C11B0300412B72 /* _v4 */ = {
isa = PBXGroup;
children = (
27E0735A2C20D1F80034B963 /* CancelOrders */,
278A4D912B8FA5C1003898EB /* Rating */,
021B68A32AD9B86600C5C3BF /* Auth */,
0243A75529BE568600A083FE /* Actions */,
Expand Down Expand Up @@ -1452,6 +1455,14 @@
path = Error;
sourceTree = "<group>";
};
27E0735A2C20D1F80034B963 /* CancelOrders */ = {
isa = PBXGroup;
children = (
27E0735B2C20D2470034B963 /* dydxCancelPendingIsolatedOrdersViewBuilder.swift */,
);
path = CancelOrders;
sourceTree = "<group>";
};
51E65BFD078A26FDF0980B06 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2027,6 +2038,7 @@
276908FF2AAFB22F0075B2D6 /* dydxPortfolioTransfersViewPresenter.swift in Sources */,
6496DBC9295CBBDD00174CE7 /* dydxV4TabBarBuilder.swift in Sources */,
02F7010029EA165F004DEB5E /* dydxTransferReceiptViewPresenter.swift in Sources */,
27E0735C2C20D2470034B963 /* dydxCancelPendingIsolatedOrdersViewBuilder.swift in Sources */,
277E90152B1EA0E3005CCBCB /* dydxTradingRewardsViewPresenter.swift in Sources */,
0216441128F36FBE00C7093E /* CandleDataPoint.swift in Sources */,
6453A7D2299C563F0041A0C4 /* dydxClosePositionInputViewBuilder.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,14 @@
"destination":"dydxPresenters.dydxOrderDetailsViewBuilder",
"presentation":"half"
},

"/orders/:id":{
"destination":"dydxPresenters.dydxOrderDetailsViewBuilder",
"presentation":"half"
},
"/portfolio/cancel_pending_position/:market":{
"destination":"dydxPresenters.dydxCancelPendingIsolatedOrdersViewBuilder",
"presentation":"half"
},
"/profile/user":{
"destination":"ProfileInput.storyboard",
"presentation":"half"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// dydxCancelPendingIsolatedOrdersViewBuilder.swift
// dydxUI
//
// Created by Michael Maguire on 6/17/24.
// Copyright © 2024 dYdX Trading Inc. All rights reserved.
//
import Utilities
import dydxViews
import PlatformParticles
import RoutingKit
import ParticlesKit
import PlatformUI

public class dydxCancelPendingIsolatedOrdersViewBuilder: NSObject, ObjectBuilderProtocol {
public func build<T>() -> T? {
let presenter = dydxCancelPendingIsolatedOrdersViewBuilderPresenter()
let view = presenter.viewModel?.createView() ?? PlatformViewModel().createView()
return dydxCancelPendingIsolatedOrdersViewBuilderController(presenter: presenter, view: view, configuration: .default) as? T
}
}

private class dydxCancelPendingIsolatedOrdersViewBuilderController: HostingViewController<PlatformView, dydxCancelPendingIsolatedOrdersViewModel> {
override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool {
if request?.path == "/portfolio/cancel_pending_position" {
return true
}
return false
}
}

private protocol dydxCancelPendingIsolatedOrdersViewBuilderPresenterProtocol: HostedViewPresenterProtocol {
var viewModel: dydxCancelPendingIsolatedOrdersViewModel? { get }
}

private class dydxCancelPendingIsolatedOrdersViewBuilderPresenter: HostedViewPresenter<dydxCancelPendingIsolatedOrdersViewModel>, dydxCancelPendingIsolatedOrdersViewBuilderPresenterProtocol {
override init() {
super.init()

self.viewModel = .previewValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class dydxPortfolioPositionsViewPresenter: HostedViewPresenter<dydxPortfolioPosi
}

let cancelOrdersAction: () -> Void = {
Router.shared?.navigate(to: RoutingRequest(path: "/trade/markets", params: ["market": market.id]), animated: true, completion: nil)
Router.shared?.navigate(to: RoutingRequest(path: "/portfolio/cancel_pending_position/\(market.id)"), animated: true, completion: nil)
}

return dydxPortfolioPendingPositionsItemViewModel(marketLogoUrl: URL(string: asset.resources?.imageUrl ?? ""),
Expand Down
12 changes: 12 additions & 0 deletions dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
27C6E4C92BC8C30E00ED892A /* dydxCustomLimitPriceViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E4BC2BC8C30E00ED892A /* dydxCustomLimitPriceViewModel.swift */; };
27CDA3D42BBF1AD700FEAFFE /* dydxMultipleOrdersExistViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27CDA3D32BBF1AD700FEAFFE /* dydxMultipleOrdersExistViewModel.swift */; };
27E072D22C1A095C0034B963 /* dydxPortfolioPendingPositionsItemViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E072D12C1A095C0034B963 /* dydxPortfolioPendingPositionsItemViewModel.swift */; };
27E0736B2C20D27F0034B963 /* dydxCancelPendingIsolatedOrdersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E0736A2C20D27F0034B963 /* dydxCancelPendingIsolatedOrdersView.swift */; };
27ED340C2AD47CB100C159F5 /* dydxBannerErrorAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27ED340B2AD47CB100C159F5 /* dydxBannerErrorAlert.swift */; };
27ED365C2AD735A800C159F5 /* dydxSecurityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27ED365B2AD735A800C159F5 /* dydxSecurityView.swift */; };
27F624112BBD9FEB00AB6D1A /* dydxPriceInputViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27F624042BBD9FEB00AB6D1A /* dydxPriceInputViewModel.swift */; };
Expand Down Expand Up @@ -565,6 +566,7 @@
27C6E4BC2BC8C30E00ED892A /* dydxCustomLimitPriceViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxCustomLimitPriceViewModel.swift; sourceTree = "<group>"; };
27CDA3D32BBF1AD700FEAFFE /* dydxMultipleOrdersExistViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxMultipleOrdersExistViewModel.swift; sourceTree = "<group>"; };
27E072D12C1A095C0034B963 /* dydxPortfolioPendingPositionsItemViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxPortfolioPendingPositionsItemViewModel.swift; sourceTree = "<group>"; };
27E0736A2C20D27F0034B963 /* dydxCancelPendingIsolatedOrdersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxCancelPendingIsolatedOrdersView.swift; sourceTree = "<group>"; };
27ED340B2AD47CB100C159F5 /* dydxBannerErrorAlert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxBannerErrorAlert.swift; sourceTree = "<group>"; };
27ED365B2AD735A800C159F5 /* dydxSecurityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSecurityView.swift; sourceTree = "<group>"; };
27F624042BBD9FEB00AB6D1A /* dydxPriceInputViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxPriceInputViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -696,6 +698,7 @@
0230375D28C11AFA00412B72 /* _v4 */ = {
isa = PBXGroup;
children = (
27E0735D2C20D2680034B963 /* CancelOrders */,
278A4D942B8FA5F5003898EB /* Rating */,
27ED364E2AD7358C00C159F5 /* Auth */,
27AAA9782ACE34B600AF3C56 /* Banner */,
Expand Down Expand Up @@ -1502,6 +1505,14 @@
path = Banner;
sourceTree = "<group>";
};
27E0735D2C20D2680034B963 /* CancelOrders */ = {
isa = PBXGroup;
children = (
27E0736A2C20D27F0034B963 /* dydxCancelPendingIsolatedOrdersView.swift */,
);
path = CancelOrders;
sourceTree = "<group>";
};
27ED364E2AD7358C00C159F5 /* Auth */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1958,6 +1969,7 @@
277E901B2B1EA4F9005CCBCB /* dydxRewardsSummaryView.swift in Sources */,
02084B2D297FC2CD00CF9522 /* dydxTransferFaucetView.swift in Sources */,
022EDC8E29A048B3003D59A7 /* dydxClosePositionHeaderView.swift in Sources */,
27E0736B2C20D27F0034B963 /* dydxCancelPendingIsolatedOrdersView.swift in Sources */,
02F1D3882BEAA6CA00A9376C /* dydxTradeInputMarginView.swift in Sources */,
0256F53629AFFC9800A083C0 /* dydxOnboardConnectView.swift in Sources */,
024F48902965CE9200E40247 /* dydxPortfolioDetailsView.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion dydx/dydxViews/dydxViews/Themes/dydxStyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"_textColor": "text_tertiary"
},
"button-destructive": {
"_layerColor": "layer_4",
"_layerColor": "layer_3",
"_textColor": "color_red"
},
"asset_list_item_24h_volume": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//
// dydxCancelPendingIsolatedOrdersView.swift
// dydxViews
//
// Created by Michael Maguire on 6/17/24.
//

import SwiftUI
import PlatformUI
import Utilities
import SDWebImageSwiftUI

public class dydxCancelPendingIsolatedOrdersViewModel: PlatformViewModel {
@Published public var marketLogoUrl: URL?
@Published public var marketName: String
@Published public var marketId: String
@Published public var orderCount: Int
@Published public var cancelAction: (() -> Void)

public init(marketLogoUrl: URL?,
marketName: String,
marketId: String,
orderCount: Int,
cancelAction: @escaping (() -> Void)
) {
self.marketLogoUrl = marketLogoUrl
self.marketName = marketName
self.marketId = marketId
self.orderCount = orderCount
self.cancelAction = cancelAction
}

public static var previewValue: dydxCancelPendingIsolatedOrdersViewModel {
.init(marketLogoUrl: URL(string: "https://v4.testnet.dydx.exchange/currencies/eth.png"),
marketName: "Ethereum",
marketId: "ETH-USDC",
orderCount: 1,
cancelAction: {}
)
}

public override func createView(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> PlatformUI.PlatformView {
PlatformView(viewModel: self, parentStyle: parentStyle, styleKey: styleKey) { [weak self] _ in
guard let self = self else { return AnyView(PlatformView.nilView) }
return AnyView(CancelView(viewModel: self))
}
}
}

private struct CancelView: View {
@StateObject var viewModel = dydxCancelPendingIsolatedOrdersViewModel.previewValue

var logo: some View {
return WebImage(url: viewModel.marketLogoUrl)
.resizable()
.scaledToFit()
.frame(width: 85, height: 85)
.clipShape(.circle)
}

var title: some View {
return Text(localizerPathKey: "APP.TRADE.CANCEL_ORDERS")
.themeFont(fontType: .base, fontSize: .large)
.themeColor(foreground: .textPrimary)
}

var subtitle: some View {
let openOrdersText = (viewModel.orderCount == 1 ?
DataLocalizer.shared?.localize(path: "APP.CANCEL_ORDERS_MODAL.ONE_OPEN_ORDER", params: nil)
: DataLocalizer.shared?.localize(path: "APP.CANCEL_ORDERS_MODAL.N_OPEN_ORDERS", params: ["COUNT": "\(viewModel.orderCount)"])) ?? ""

let localizedString = DataLocalizer.shared?.localize(path: "APP.CANCEL_ORDERS_MODAL.CANCEL_ORDERS_CONFIRMATION", params: ["OPEN_ORDERS_TEXT": openOrdersText,
"ASSET": viewModel.marketName,
"MARKET": viewModel.marketId]) ?? ""
var attributedString = AttributedString(localizedString)
.themeFont(fontType: .base, fontSize: .small)
.themeColor(foreground: .textTertiary, to: nil)

let replacementTexts = [
openOrdersText,
viewModel.marketName,
viewModel.marketId
]
for replacementText in replacementTexts {
if let range = attributedString.range(of: replacementText) {
attributedString = attributedString.themeColor(foreground: .textSecondary, to: range)
}
}

return Text(attributedString)
.multilineTextAlignment(.center)

}

var button: some View {
let key = viewModel.orderCount == 1 ? "APP.TRADE.CANCEL_ORDER" : "APP.TRADE.CANCEL_ORDERS_COUNT"
let params = ["COUNT": "\(viewModel.orderCount)"]
let content = Text(localizerPathKey: key, params: params)
.themeFont(fontType: .base, fontSize: .medium)
.themeColor(foreground: .textPrimary)
return PlatformButtonViewModel(content: content.wrappedViewModel,
type: .defaultType(),
state: .destructive,
action: viewModel.cancelAction)
.createView()
}

var body: some View {
VStack(spacing: 24) {
logo
VStack(spacing: 8) {
title
subtitle
}
button
}
.padding(.horizontal, 24)
.padding(.top, 60)
.padding(.bottom, max((viewModel.safeAreaInsets?.bottom ?? 0), 24))
.themeColor(background: .layer4)
.makeSheet(sheetStyle: .fitSize)
.ignoresSafeArea(edges: [.bottom])
}
}

#Preview {
CancelView()
}

0 comments on commit 340627f

Please sign in to comment.