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

MOB-316 : Display markets list when market title is tapped on trade page #112

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 @@ -95,6 +95,13 @@ private class dydxMarketInfoViewPresenter: HostedViewPresenter<dydxMarketInfoVie
Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss"), animated: true, completion: nil)
}

viewModel.header.onMarketSelectorTap = {
Router.shared?.navigate(to: RoutingRequest(path: "/markets/search",
params: ["shouldShowResultsForEmptySearch": true]),
animated: true,
completion: nil)
}

viewModel.sections.itemTitles = Section.allSections.map(\.text)
viewModel.sections.onSelectionChanged = { [weak self] index in
if index < Section.allSections.count {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,27 @@ public class dydxMarketsSearchViewBuilder: NSObject, ObjectBuilderProtocol {

private class dydxMarketsSearchViewController: HostingViewController<PlatformView, dydxSearchViewModel> {
override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool {
request?.path == "/markets/search"
guard request?.path == "/markets/search" else { return false }
if let presenter = presenter as? dydxMarketsSearchViewPresenter {
presenter.shouldShowResultsForEmptySearch = parser.asBoolean(request?.params?["shouldShowResultsForEmptySearch"])?.boolValue ?? false
}
return true
}
}

private class dydxMarketsSearchViewPresenter: dydxSearchViewPresenter {
private var chartPresenterMap = [String: dydxAssetItemChartViewPresenter]()

fileprivate var shouldShowResultsForEmptySearch: Bool = false

override init() {
super.init()
}

override func start() {
super.start()

guard let searchTextPublisher = viewModel?.$searchText else {
guard let searchTextPublisher = viewModel?.$searchText.map({ $0.lowercased() }) else {
return
}

Expand All @@ -49,16 +55,20 @@ private class dydxMarketsSearchViewPresenter: dydxSearchViewPresenter {
AbacusStateManager.shared.state.candlesMap,
AbacusStateManager.shared.state.assetMap,
searchTextPublisher.removeDuplicates())
.sink { [weak self] (markets: [PerpetualMarket], candlesMap: [String: MarketCandles], assetMap: [String: Asset], searchText: String?) in
let filterMarkets = markets.filter { market in
.sink { [weak self] (markets: [PerpetualMarket], candlesMap: [String: MarketCandles], assetMap: [String: Asset], searchText: String) in
var filterMarkets = markets.filter { market in
guard market.status?.canTrade == true,
let searchText = searchText?.lowercased(), searchText.length > 0,
let asset = assetMap[market.assetId] else {
searchText.isNotEmpty || self?.shouldShowResultsForEmptySearch == true,
let asset = assetMap[market.assetId] else {
return false
}
return asset.id.lowercased().starts(with: searchText) ||
asset.name?.lowercased().starts(with: searchText) ?? false
}
// sort by volume if showing empty search string results and search text is empty
if searchText.isEmpty && self?.shouldShowResultsForEmptySearch == true {
filterMarkets.sort { ($0.perpetual?.volume24H?.doubleValue ?? 0) > $1.perpetual?.volume24H?.doubleValue ?? 0 }
}
self?.updateAssetList(markets: filterMarkets, candlesMap: candlesMap, assetMap: assetMap)
}
.store(in: &subscriptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private class dydxTradeInputViewController: HostingViewController<PlatformView,
var positions: [FloatingPanel.FloatingPanelState: FloatingPanel.FloatingPanelLayoutAnchoring] = [
.tip: FloatingPanelLayoutAnchor(absoluteInset: 90, edge: .bottom, referenceGuide: .safeArea),
// Use .half instead of .full, so that the back button from the parent view is enabled.
.half: FloatingPanelLayoutAnchor(absoluteInset: 56, edge: .top, referenceGuide: .safeArea)
.half: FloatingPanelLayoutAnchor(absoluteInset: 76, edge: .top, referenceGuide: .safeArea)
]
if position == nil {
positions[.hidden] = FloatingPanelLayoutAnchor(absoluteInset: 0, edge: .bottom, referenceGuide: .superview)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "Vector.pdf",
"filename" : "gray_star.pdf",
"idiom" : "universal"
}
],
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import Utilities

public class dydxMarketInfoHeaderViewModel: PlatformViewModel {
@Published public var sharedMarketViewModel: SharedMarketViewModel? = SharedMarketViewModel()
@Published public var favoriteViewModel: dydxUserFavoriteViewModel? = dydxUserFavoriteViewModel()
@Published public var favoriteViewModel: dydxUserFavoriteViewModel? = dydxUserFavoriteViewModel(size: .init(width: 20, height: 20))
@Published public var onBackButtonTap: (() -> Void)?
@Published public var onMarketSelectorTap: (() -> Void)?

public init() { }
public init() {}

public static var previewValue: dydxMarketInfoHeaderViewModel = {
let vm = dydxMarketInfoHeaderViewModel()
Expand All @@ -24,63 +25,56 @@ public class dydxMarketInfoHeaderViewModel: PlatformViewModel {
return vm
}()

private func createMarketSelectorView(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> some View {
HStack(spacing: 15) {
HStack(spacing: 12) {
PlatformIconViewModel(type: .url(url: self.sharedMarketViewModel?.logoUrl),
clip: .defaultCircle,
size: CGSize(width: 40, height: 40))
.createView(parentStyle: parentStyle, styleKey: styleKey)
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 4) {
Text(sharedMarketViewModel?.tokenFullName ?? "")
.themeColor(foreground: .textSecondary)
.themeFont(fontType: .base, fontSize: .large)
TokenTextViewModel(symbol: sharedMarketViewModel?.tokenSymbol ?? "")
.createView(parentStyle: parentStyle.themeFont(fontSize: .smallest), styleKey: styleKey)
}
HStack(alignment: .center, spacing: 4) {
Text(sharedMarketViewModel?.indexPrice ?? "")
.themeColor(foreground: .textPrimary)
.themeFont(fontType: .number, fontSize: .large)
sharedMarketViewModel?.priceChangePercent24H?.createView(parentStyle: parentStyle.themeFont(fontSize: .medium), styleKey: styleKey)
}
}
}
PlatformIconViewModel(type: .asset(name: "icon_dropdown", bundle: .dydxView),
clip: .noClip,
size: .init(width: 14, height: 8))
.createView(parentStyle: parentStyle, styleKey: styleKey)
}
.padding(.horizontal, 12)
.padding(.vertical, 8)
.themeColor(background: .layer3)
.borderAndClip(style: .cornerRadius(12), borderColor: .borderDefault, lineWidth: 1)
.onTapGesture(perform: self.onMarketSelectorTap ?? {})
}

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

return AnyView(
HStack(spacing: 0) {
ChevronBackButtonModel(onBackButtonTap: self.onBackButtonTap ?? {})
.createView(parentStyle: style)
return HStack(spacing: 28) {
ChevronBackButtonModel(onBackButtonTap: self.onBackButtonTap ?? {})
.createView(parentStyle: style)

let icon = PlatformIconViewModel(type: .url(url: sharedMarketViewModel.logoUrl),
clip: .defaultCircle,
size: CGSize(width: 40, height: 40))
self.createMarketSelectorView(parentStyle: parentStyle, styleKey: styleKey)

let main =
HStack {
VStack(alignment: .leading) {
HStack(spacing: 4) {
Text(sharedMarketViewModel.tokenFullName ?? "")
.themeColor(foreground: .textPrimary)
.themeFont(fontType: .plus, fontSize: .medium)
Text("USD")
.themeFont(fontType: .plus, fontSize: .medium)

}
Text(sharedMarketViewModel.tokenSymbol ?? "")
.themeFont(fontType: .base, fontSize: .small)
}

self.favoriteViewModel?.createView(parentStyle: style)
.padding(.leading, 4)
.padding(.top, -18)

Spacer()
}

let trailing =
VStack(alignment: .trailing, spacing: 2) {
Text(sharedMarketViewModel.indexPrice ?? "")
.themeColor(foreground: .textPrimary)
.themeFont(fontType: .plus, fontSize: .medium)
.lineLimit(1)
.minimumScaleFactor(0.5)
if let priceChangePercent24H = sharedMarketViewModel.priceChangePercent24H {
priceChangePercent24H
.createView(parentStyle: style, styleKey: "asset_list_item_24h_volume")
}
}
PlatformTableViewCellViewModel(logo: icon,
main: main.wrappedViewModel,
trailing: trailing.wrappedViewModel)
.createView(parentStyle: style)
}
.frame(height: 72)
.padding([.leading])
)
self.favoriteViewModel?.createView(parentStyle: style)
.viewModel.createView(parentStyle: parentStyle, styleKey: styleKey)
}.wrappedInAnyView()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import Utilities

public class dydxUserFavoriteViewModel: PlatformViewModel {
@Published public var isFavorited: Bool = false
@Published public var size = CGSize(width: 16, height: 16)
@Published public var size: CGSize
@Published public var onTapped: (() -> Void)?
@Published public var handleTap: Bool = true

public init() { }
public init(size: CGSize = .init(width: 16, height: 16)) {
self.size = size
}

public static var previewValue: dydxUserFavoriteViewModel {
let vm = dydxUserFavoriteViewModel()
Expand Down
Loading