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

TRCL-3714 Wallet/Settings/Mode switcher #330

Merged
merged 26 commits into from
Jan 8, 2025
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
4 changes: 4 additions & 0 deletions dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
02031F1C2AC3A7130069E00D /* dydxTradeSheetTipDraftViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031F1B2AC3A7130069E00D /* dydxTradeSheetTipDraftViewPresenter.swift */; };
0207FC9D2D269C00004C2C9F /* dydxSimpleUITradeInputValidationViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0207FC8F2D269BFF004C2C9F /* dydxSimpleUITradeInputValidationViewPresenter.swift */; };
0207FC9F2D27BA6B004C2C9F /* dydxSimpleUITradeInputCtaButtonViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0207FC9E2D27BA62004C2C9F /* dydxSimpleUITradeInputCtaButtonViewPresenter.swift */; };
0207FCA32D2A181D004C2C9F /* dydxSimpleUIMarketsHeaderViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0207FCA22D2A181C004C2C9F /* dydxSimpleUIMarketsHeaderViewPresenter.swift */; };
0208627C28F4DAC000C9D3A0 /* dydxMarketInfoPagingViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0208627B28F4DAC000C9D3A0 /* dydxMarketInfoPagingViewPresenter.swift */; };
0208631028F5186E00C9D3A0 /* OrderbookLineDataPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0208630F28F5186E00C9D3A0 /* OrderbookLineDataPoint.swift */; };
0208632528F51EC400C9D3A0 /* dydxMarketDepthChartViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0208632428F51EC400C9D3A0 /* dydxMarketDepthChartViewPresenter.swift */; };
Expand Down Expand Up @@ -422,6 +423,7 @@
02031F1B2AC3A7130069E00D /* dydxTradeSheetTipDraftViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradeSheetTipDraftViewPresenter.swift; sourceTree = "<group>"; };
0207FC8F2D269BFF004C2C9F /* dydxSimpleUITradeInputValidationViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSimpleUITradeInputValidationViewPresenter.swift; sourceTree = "<group>"; };
0207FC9E2D27BA62004C2C9F /* dydxSimpleUITradeInputCtaButtonViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSimpleUITradeInputCtaButtonViewPresenter.swift; sourceTree = "<group>"; };
0207FCA22D2A181C004C2C9F /* dydxSimpleUIMarketsHeaderViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSimpleUIMarketsHeaderViewPresenter.swift; sourceTree = "<group>"; };
0208627B28F4DAC000C9D3A0 /* dydxMarketInfoPagingViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxMarketInfoPagingViewPresenter.swift; sourceTree = "<group>"; };
0208630F28F5186E00C9D3A0 /* OrderbookLineDataPoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderbookLineDataPoint.swift; sourceTree = "<group>"; };
0208632428F51EC400C9D3A0 /* dydxMarketDepthChartViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxMarketDepthChartViewPresenter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1374,6 +1376,7 @@
02D6DBB72D134BE0008AAEA1 /* components */ = {
isa = PBXGroup;
children = (
0207FCA22D2A181C004C2C9F /* dydxSimpleUIMarketsHeaderViewPresenter.swift */,
027885DA2D1A34EA00366321 /* dydxSimpleUIPortfolioViewPresenter.swift */,
028CF1412D1489E800476930 /* dydxSimpleUIMarketSearchViewPresenter.swift */,
02D6DBB82D134BE8008AAEA1 /* dydxSimpleUIMarketListViewPresenter.swift */,
Expand Down Expand Up @@ -2167,6 +2170,7 @@
27C027532AFD761300E92CCB /* dydxProfileSecondaryButtonsViewPresenter.swift in Sources */,
02EF485629F732C600C97746 /* dydxFavoriteStore.swift in Sources */,
0208627C28F4DAC000C9D3A0 /* dydxMarketInfoPagingViewPresenter.swift in Sources */,
0207FCA32D2A181D004C2C9F /* dydxSimpleUIMarketsHeaderViewPresenter.swift in Sources */,
0238FECB2970D681002E1C1A /* SharedAccountPresenter.swift in Sources */,
27592DF92C9A54D6002FBD4B /* dydxSystemAlertsProvider.swift in Sources */,
027885F02D1DE14600366321 /* dydxSimpleUIMarketInfoHeaderViewPresenter.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@
},
"/settings":{
"destination":"dydxPresenters.dydxSettingsLandingViewBuilder",
"dependencies":[
"/my-profile"
]
},
"/settings/notifications":{
"destination":"dydxPresenters.dydxNotificationsSettingsViewBuilder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,11 @@ class dydxSimpleUIMarketPositionViewPresenter: HostedViewPresenter<dydxSimpleUIM
viewModel?.logoUrl = sharedOrderViewModel.logoUrl
viewModel?.amount = dydxFormatter.shared.dollar(number: position.notionalTotal.current?.doubleValue, digits: 2)
viewModel?.funding = SignedAmountViewModel(amount: position.netFunding?.doubleValue, displayType: .dollar, coloringOption: .allText)

viewModel?.closeAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/trade/close",
params: ["marketId": position.id]),
animated: true, completion: nil)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// dydxSimpleUIMarketsHeaderViewPresenter.swift
// dydxPresenters
//
// Created by Rui Huang on 05/01/2025.
//

import Utilities
import dydxViews
import PlatformParticles
import RoutingKit
import ParticlesKit
import PlatformUI
import dydxStateManager
import Abacus
import Combine
import dydxFormatter

protocol dydxSimpleUIMarketsHeaderViewPresenterProtocol: HostedViewPresenterProtocol {
var viewModel: dydxSimpleUIMarketsHeaderViewModel? { get }
}

class dydxSimpleUIMarketsHeaderViewPresenter: HostedViewPresenter<dydxSimpleUIMarketsHeaderViewModel>, dydxSimpleUIMarketsHeaderViewPresenterProtocol {
override init() {
super.init()

viewModel = dydxSimpleUIMarketsHeaderViewModel()
}

override func start() {
super.start()

Publishers.CombineLatest(
AbacusStateManager.shared.state.onboarded,
AbacusStateManager.shared.state.walletState
)
.sink { [weak self] onboarded, walletState in
guard let self = self else { return }
self.update(onboarded: onboarded, currentWallet: walletState.currentWallet)
}
.store(in: &subscriptions)
}

private func update(onboarded: Bool, currentWallet: dydxWalletInstance?) {
viewModel?.onboarded = onboarded

let ethereumAddress = currentWallet?.ethereumAddress ?? ""
if onboarded {
viewModel?.items = [.transfers, .history, .settings, .help, .signOut(ethereumAddress: ethereumAddress)]
} else {
viewModel?.items = [.signIn, .settings, .help]
}
}
}

private extension dydxSimpleUIMarketsHeaderViewModel.MenuItem {

static let signIn = dydxSimpleUIMarketsHeaderViewModel.MenuItem(
icon: "icon_wallet_connect",
title: DataLocalizer.localize(path: "APP.GENERAL.CONNECT_WALLET")) {
Router.shared?.navigate(to: RoutingRequest(path: "/onboard/wallets"), animated: true, completion: nil)
}

static func signOut(ethereumAddress: String) -> Self {
dydxSimpleUIMarketsHeaderViewModel.MenuItem(
icon: "settings_signout",
title: DataLocalizer.localize(path: "APP.GENERAL.SIGN_OUT")) {
Router.shared?.navigate(to: RoutingRequest(path: "/action/wallet/disconnect", params: ["ethereumAddress": ethereumAddress]), animated: true, completion: nil)
}
}

static let settings = dydxSimpleUIMarketsHeaderViewModel.MenuItem(
icon: "icon_settings",
title: DataLocalizer.localize(path: "APP.EMAIL_NOTIFICATIONS.SETTINGS")) {
Router.shared?.navigate(to: RoutingRequest(url: "/settings"), animated: true, completion: nil)
}

static let history = dydxSimpleUIMarketsHeaderViewModel.MenuItem(
icon: "icon_clock",
title: DataLocalizer.localize(path: "APP.GENERAL.HISTORY")) {
Router.shared?.navigate(to: RoutingRequest(path: "/portfolio/history"), animated: true, completion: nil)
}

static let transfers = dydxSimpleUIMarketsHeaderViewModel.MenuItem(
icon: "icon_transfer",
title: DataLocalizer.localize(path: "APP.GENERAL.TRANSFER")) {
Router.shared?.navigate(to: RoutingRequest(path: "/transfer"), animated: true, completion: nil)
}

static let help = dydxSimpleUIMarketsHeaderViewModel.MenuItem(
icon: "icon_help",
title: DataLocalizer.localize(path: "APP.HEADER.HELP")) {
Router.shared?.navigate(to: RoutingRequest(path: "/help"), animated: true, completion: nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ public class dydxSimpleUIMarketsViewPresenter: HostedViewPresenter<dydxSimpleUIM
private let marketListPresenter = dydxSimpleUIMarketListViewPresenter()
private let marketSearchPresenter = dydxSimpleUIMarketSearchViewPresenter()
private let portfolioPresenter = dydxSimpleUIPortfolioViewPresenter()
private let headerPresenter = dydxSimpleUIMarketsHeaderViewPresenter()

private lazy var childPresenters: [HostedViewPresenterProtocol] = [
marketListPresenter,
marketSearchPresenter,
portfolioPresenter
portfolioPresenter,
headerPresenter
]

override init() {
Expand All @@ -55,10 +57,7 @@ public class dydxSimpleUIMarketsViewPresenter: HostedViewPresenter<dydxSimpleUIM
portfolioPresenter.$viewModel.assign(to: &viewModel.$portfolio)
marketSearchPresenter.viewModel?.$searchText.assign(to: &marketListPresenter.$searchText)
marketSearchPresenter.viewModel?.$focused.assign(to: &viewModel.$keyboardUp)

viewModel.onSettingTapped = {
Router.shared?.navigate(to: RoutingRequest(path: "/settings/app_mode"), animated: true, completion: nil)
}
headerPresenter.$viewModel.assign(to: &viewModel.$header)

super.init()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ protocol dydxSimpleUITradeInputCtaButtonViewPresenterProtocol: HostedViewPresent
var viewModel: dydxTradeInputCtaButtonViewModel? { get }
}

protocol dydxSimpleUITradeInputCtaButtonViewPresenterDelegate: AnyObject {
func tradeButtonTapped()
}

class dydxSimpleUITradeInputCtaButtonViewPresenter: HostedViewPresenter<dydxTradeInputCtaButtonViewModel>, dydxSimpleUITradeInputCtaButtonViewPresenterProtocol {

weak var delegate: dydxSimpleUITradeInputCtaButtonViewPresenterDelegate?

private enum OnboardingState {
case newUser
case needDeposit
Expand Down Expand Up @@ -128,6 +134,7 @@ class dydxSimpleUITradeInputCtaButtonViewPresenter: HostedViewPresenter<dydxTrad
case .needDeposit:
Router.shared?.navigate(to: RoutingRequest(path: "/transfer"), animated: true, completion: nil)
case .readyToTrade:
delegate?.tradeButtonTapped()
Router.shared?.navigate(to: RoutingRequest(path: "/trade/status"), animated: true, completion: nil)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,24 @@ class dydxSimpleUITradeInputViewController: HostingViewController<PlatformView,
func buySellButtonTapped() {
move(to: .half)
}

func tradeButtonTapped() {
move(to: .tip)
}
}

private protocol dydxSimpeUITradeInputViewPresenterDelegate: AnyObject {
func buySellButtonTapped()
func tradeButtonTapped()
}

private protocol dydxSimpleUITradeInputViewPresenterProtocol: HostedViewPresenterProtocol {
var viewModel: dydxSimpleUITradeInputViewModel? { get }
func updateViewControllerPosition(position: FloatingPanelState)
}

private class dydxSimpleUITradeInputViewPresenter: HostedViewPresenter<dydxSimpleUITradeInputViewModel>, dydxSimpleUITradeInputViewPresenterProtocol, dydxTradeSheetTipBuySellViewPresenterDelegate {
private class dydxSimpleUITradeInputViewPresenter: HostedViewPresenter<dydxSimpleUITradeInputViewModel>, dydxSimpleUITradeInputViewPresenterProtocol, dydxTradeSheetTipBuySellViewPresenterDelegate, dydxSimpleUITradeInputCtaButtonViewPresenterDelegate {

weak var delegate: dydxSimpeUITradeInputViewPresenterDelegate?

// MARK: dydxTradeInputViewPresenterProtocol
Expand All @@ -132,6 +138,12 @@ private class dydxSimpleUITradeInputViewPresenter: HostedViewPresenter<dydxSimpl
delegate?.buySellButtonTapped()
}

// MARK: dydxSimpleUITradeInputCtaButtonViewPresenterDelegate

func tradeButtonTapped() {
delegate?.tradeButtonTapped()
}

private let tipBuySellPresenter = dydxTradeSheetTipBuySellViewPresenter()
private let tipDraftPresenter = dydxTradeSheetTipDraftViewPresenter()
private let sideViewPresenter = dydxTradeInputSideViewPresenter()
Expand Down Expand Up @@ -166,6 +178,7 @@ private class dydxSimpleUITradeInputViewPresenter: HostedViewPresenter<dydxSimpl

self.viewModel = viewModel
tipBuySellPresenter.delegate = self
ctaButtonPresenter.delegate = self

attachChildren(workers: childPresenters)
}
Expand Down
4 changes: 4 additions & 0 deletions dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
02031F032AC36CE60069E00D /* BuySellButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031F022AC36CE60069E00D /* BuySellButton.swift */; };
02031F052AC373B50069E00D /* dydxTradeSheetTipBuySellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031F042AC373B50069E00D /* dydxTradeSheetTipBuySellView.swift */; };
02031F1A2AC3A6FE0069E00D /* dydxTradeSheetTipDraftView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031F192AC3A6FE0069E00D /* dydxTradeSheetTipDraftView.swift */; };
0207FCA12D2A17DF004C2C9F /* dydxSimpleUIMarketsHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0207FCA02D2A17DF004C2C9F /* dydxSimpleUIMarketsHeaderView.swift */; };
02084B2D297FC2CD00CF9522 /* dydxTransferFaucetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02084B2C297FC2CD00CF9522 /* dydxTransferFaucetView.swift */; };
02084C682981253200CF9522 /* dydxValidationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02084C672981253200CF9522 /* dydxValidationView.swift */; };
0208627828F4C5EE00C9D3A0 /* dydxMarketTilesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0208627728F4C5EE00C9D3A0 /* dydxMarketTilesView.swift */; };
Expand Down Expand Up @@ -420,6 +421,7 @@
02031F022AC36CE60069E00D /* BuySellButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuySellButton.swift; sourceTree = "<group>"; };
02031F042AC373B50069E00D /* dydxTradeSheetTipBuySellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradeSheetTipBuySellView.swift; sourceTree = "<group>"; };
02031F192AC3A6FE0069E00D /* dydxTradeSheetTipDraftView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradeSheetTipDraftView.swift; sourceTree = "<group>"; };
0207FCA02D2A17DF004C2C9F /* dydxSimpleUIMarketsHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSimpleUIMarketsHeaderView.swift; sourceTree = "<group>"; };
02084B2C297FC2CD00CF9522 /* dydxTransferFaucetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTransferFaucetView.swift; sourceTree = "<group>"; };
02084C672981253200CF9522 /* dydxValidationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxValidationView.swift; sourceTree = "<group>"; };
0208627728F4C5EE00C9D3A0 /* dydxMarketTilesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxMarketTilesView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1524,6 +1526,7 @@
isa = PBXGroup;
children = (
02D6DBB32D134723008AAEA1 /* dydxSimpleUIMarketView.swift */,
0207FCA02D2A17DF004C2C9F /* dydxSimpleUIMarketsHeaderView.swift */,
02D6DBB52D134BCF008AAEA1 /* dydxSimpleUIMarketListView.swift */,
028CF1332D1489DD00476930 /* dydxSimpleUIMarketSearchView.swift */,
027885DC2D1A3EDA00366321 /* dydxSimpleUIPortfolioView.swift */,
Expand Down Expand Up @@ -2358,6 +2361,7 @@
02D9518A2C926B8E007BB2B4 /* dydxNotificationPrimerView.swift in Sources */,
0279DE6B2BEC471700F9ECF8 /* dydxAdjustMarginInputView.swift in Sources */,
02DDE09F28F37D4200945990 /* dydxMarketPriceCandlesHighlightView.swift in Sources */,
0207FCA12D2A17DF004C2C9F /* dydxSimpleUIMarketsHeaderView.swift in Sources */,
02A9B6102900605400AE1516 /* SizeText.swift in Sources */,
64A4DB6F2966218B008D8E20 /* dydxTradeInputOrderTypeView.swift in Sources */,
277E90132B1EA0D3005CCBCB /* dydxTradingRewardsView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "mark.pdf",
"filename" : "dYdX Logo (3) 1.svg",
"idiom" : "universal"
}
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Loading