From 3d3861c88543eded42ec40ef42d0ea5b19337b09 Mon Sep 17 00:00:00 2001 From: mike-dydx Date: Mon, 4 Dec 2023 15:58:46 -0500 Subject: [PATCH] add rewards card to profile landing screen --- .../dydxPresenters.xcodeproj/project.pbxproj | 4 + .../dydxProfileRewardsViewPresenter.swift | 31 +++++++ .../dydxViews.xcodeproj/project.pbxproj | 4 + .../Components/dydxProfileFeesView.swift | 1 - .../Components/dydxProfileHistoryView.swift | 1 - .../dydxProfileRewardsViewModel.swift | 87 +++++++++++++++++++ .../_v4/Profile/dydxProfileView.swift | 3 + 7 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 dydx/dydxPresenters/dydxPresenters/_v4/Profile/Components/dydxProfileRewardsViewPresenter.swift create mode 100644 dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileRewardsViewModel.swift diff --git a/dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj b/dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj index 04ff2e10a..3f4919709 100644 --- a/dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj +++ b/dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj @@ -130,6 +130,7 @@ 2741E3702A68787A000FA190 /* settings_direction_color_preference.json in Resources */ = {isa = PBXBuildFile; fileRef = 2741E3632A68787A000FA190 /* settings_direction_color_preference.json */; }; 2741E3732A689740000FA190 /* dydxDirectionColorPreferenceViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2741E3722A689740000FA190 /* dydxDirectionColorPreferenceViewBuilder.swift */; }; 276908FF2AAFB22F0075B2D6 /* dydxPortfolioTransfersViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 276908FE2AAFB22F0075B2D6 /* dydxPortfolioTransfersViewPresenter.swift */; }; + 277E8FC92B1E576B005CCBCB /* dydxProfileRewardsViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277E8FC82B1E576B005CCBCB /* dydxProfileRewardsViewPresenter.swift */; }; 27C027532AFD761300E92CCB /* dydxSettingsHelpRowViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27C027522AFD761300E92CCB /* dydxSettingsHelpRowViewPresenter.swift */; }; 27DB2EA32AC1E7B20047BC39 /* dydxTradeRestrictedViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27DB2EA22AC1E7B20047BC39 /* dydxTradeRestrictedViewPresenter.swift */; }; 314BBDE9F332ECA910BC414E /* Pods_iOS_dydxPresenters.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F1551C00FFF41C29CFC5BD94 /* Pods_iOS_dydxPresenters.framework */; }; @@ -468,6 +469,7 @@ 2741E3632A68787A000FA190 /* settings_direction_color_preference.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = settings_direction_color_preference.json; sourceTree = ""; }; 2741E3722A689740000FA190 /* dydxDirectionColorPreferenceViewBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxDirectionColorPreferenceViewBuilder.swift; sourceTree = ""; }; 276908FE2AAFB22F0075B2D6 /* dydxPortfolioTransfersViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxPortfolioTransfersViewPresenter.swift; sourceTree = ""; }; + 277E8FC82B1E576B005CCBCB /* dydxProfileRewardsViewPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxProfileRewardsViewPresenter.swift; sourceTree = ""; }; 27C027522AFD761300E92CCB /* dydxSettingsHelpRowViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSettingsHelpRowViewPresenter.swift; sourceTree = ""; }; 27DB2EA22AC1E7B20047BC39 /* dydxTradeRestrictedViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradeRestrictedViewPresenter.swift; sourceTree = ""; }; 64487FFE2AA248340068DD87 /* dydxAlertsWorker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxAlertsWorker.swift; sourceTree = ""; }; @@ -867,6 +869,7 @@ 0258BA2729929E7D0098E1BE /* Components */ = { isa = PBXGroup; children = ( + 277E8FC82B1E576B005CCBCB /* dydxProfileRewardsViewPresenter.swift */, 027F3F052AB93B3700602E5B /* dydxProfileBalancesViewPresenter.swift */, 0258BA2829929E870098E1BE /* dydxProfileButtonsViewPresenter.swift */, 028DB33F2A05893D0090BE58 /* dydxProfileHeaderViewPresenter.swift */, @@ -1802,6 +1805,7 @@ 02669B7C2AD8661F00A756AA /* dydxCarteraConfigWorker.swift in Sources */, 02B841B228EF6C6400C4D25B /* dydxMarketInfoViewBuilder.swift in Sources */, 02031F1C2AC3A7130069E00D /* dydxTradeSheetTipDraftViewPresenter.swift in Sources */, + 277E8FC92B1E576B005CCBCB /* dydxProfileRewardsViewPresenter.swift in Sources */, 64A4DB9B2966490C008D8E20 /* dydxTradeInputOrderTypePresenter.swift in Sources */, 0236F118296ABEF500EB995F /* dydxPortfolioPositionsViewPresenter.swift in Sources */, 02282E752AC8860300BC9F01 /* dydxOrderbookGroupViewPresenter.swift in Sources */, diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Components/dydxProfileRewardsViewPresenter.swift b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Components/dydxProfileRewardsViewPresenter.swift new file mode 100644 index 000000000..6a810f316 --- /dev/null +++ b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Components/dydxProfileRewardsViewPresenter.swift @@ -0,0 +1,31 @@ +// +// dydxProfileRewardsViewPresenter.swift +// dydxPresenters +// +// Created by Rui Huang on 9/18/23. +// + +import Utilities +import dydxViews +import PlatformParticles +import RoutingKit +import ParticlesKit +import PlatformUI +import Abacus +import dydxStateManager +import dydxFormatter +import Combine + +public protocol dydxProfileRewardsViewPresenterProtocol: HostedViewPresenterProtocol { + var viewModel: dydxProfileRewardsViewModel? { get } +} + +public class dydxProfileRewardsViewPresenter: HostedViewPresenter, dydxProfileRewardsViewPresenterProtocol { + override init() { + super.init() + + viewModel = dydxProfileRewardsViewModel() + viewModel?.last7DaysRewardsAmount = "PLACEHOLDER" + viewModel?.allTimeRewardsAmount = "PLACEHOLDER" + } +} diff --git a/dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj b/dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj index f7c79e4ee..8ca7fb428 100644 --- a/dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj +++ b/dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj @@ -159,6 +159,7 @@ 277442972AD88C4900C91357 /* Satoshi-Bold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 277442952AD88C4900C91357 /* Satoshi-Bold.otf */; }; 277442982AD88C4900C91357 /* Satoshi-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 277442962AD88C4900C91357 /* Satoshi-Regular.otf */; }; 277E8F9F2B1A847D005CCBCB /* dydxTitledCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277E8F9E2B1A847D005CCBCB /* dydxTitledCardView.swift */; }; + 277E8FCB2B1E5798005CCBCB /* dydxProfileRewardsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277E8FCA2B1E5798005CCBCB /* dydxProfileRewardsViewModel.swift */; }; 27A799B92A66EC2D007C3D04 /* ThemeClassicDark.json in Resources */ = {isa = PBXBuildFile; fileRef = 27A799B82A66EC2D007C3D04 /* ThemeClassicDark.json */; }; 27AAA9862ACE34C800AF3C56 /* SwiftMessages+Banner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27AAA9852ACE34C800AF3C56 /* SwiftMessages+Banner.swift */; }; 27C027452AFD734800E92CCB /* dydxSettingsHelpRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27C027442AFD734800E92CCB /* dydxSettingsHelpRowView.swift */; }; @@ -494,6 +495,7 @@ 277442952AD88C4900C91357 /* Satoshi-Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Satoshi-Bold.otf"; sourceTree = ""; }; 277442962AD88C4900C91357 /* Satoshi-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Satoshi-Regular.otf"; sourceTree = ""; }; 277E8F9E2B1A847D005CCBCB /* dydxTitledCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTitledCardView.swift; sourceTree = ""; }; + 277E8FCA2B1E5798005CCBCB /* dydxProfileRewardsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxProfileRewardsViewModel.swift; sourceTree = ""; }; 27A799B82A66EC2D007C3D04 /* ThemeClassicDark.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ThemeClassicDark.json; sourceTree = ""; }; 27AAA9852ACE34C800AF3C56 /* SwiftMessages+Banner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftMessages+Banner.swift"; sourceTree = ""; }; 27C027442AFD734800E92CCB /* dydxSettingsHelpRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSettingsHelpRowView.swift; sourceTree = ""; }; @@ -1014,6 +1016,7 @@ 0258BA2429929D050098E1BE /* Components */ = { isa = PBXGroup; children = ( + 277E8FCA2B1E5798005CCBCB /* dydxProfileRewardsViewModel.swift */, 027F3EF62AB93ADC00602E5B /* dydxProfileBalancesViewModel.swift */, 0258BA2529929D1B0098E1BE /* dydxProfileButtonsView.swift */, 028DB33D2A0589270090BE58 /* dydxProfileHeaderView.swift */, @@ -1919,6 +1922,7 @@ 02A8975E28E6A941006F1658 /* dydxMarketAssetItemView.swift in Sources */, 02CA62852A7EBDBA006067DB /* dydxPortfolioFeesView.swift in Sources */, 024B7B5628B7F8AB00F7C386 /* dydxThemes.swift in Sources */, + 277E8FCB2B1E5798005CCBCB /* dydxProfileRewardsViewModel.swift in Sources */, 02DDAD3C2925859D00CC7531 /* QRCodeDisplay.swift in Sources */, 0276FA7C2A0DB515000BDF0B /* OrderStatus.swift in Sources */, 024B7B4F28B7F85100F7C386 /* SideText.swift in Sources */, diff --git a/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileFeesView.swift b/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileFeesView.swift index 77ec1a2eb..09ba20371 100644 --- a/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileFeesView.swift +++ b/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileFeesView.swift @@ -75,7 +75,6 @@ public class dydxProfileFeesViewModel: dydxTitledCardViewModel, Equatable { .leftAligned() } } - .padding(16) .wrappedInAnyView() } } diff --git a/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileHistoryView.swift b/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileHistoryView.swift index 6f23e19b3..3705044e5 100644 --- a/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileHistoryView.swift +++ b/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileHistoryView.swift @@ -122,7 +122,6 @@ public class dydxProfileHistoryViewModel: dydxTitledCardViewModel { } } .frame(maxWidth: .infinity) - .padding() .themeFont(fontSize: .smaller) .themeColor(foreground: .textTertiary) } diff --git a/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileRewardsViewModel.swift b/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileRewardsViewModel.swift new file mode 100644 index 000000000..7e696b646 --- /dev/null +++ b/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileRewardsViewModel.swift @@ -0,0 +1,87 @@ +// +// dydxProfileRewardsViewModel.swift +// dydxUI +// +// Created by Rui Huang on 9/18/23. +// Copyright © 2023 dYdX Trading Inc. All rights reserved. +// + +import SwiftUI +import PlatformUI +import Utilities + +public class dydxProfileRewardsViewModel: dydxTitledCardViewModel { + @Published public var last7DaysRewardsAmount: String? + @Published public var allTimeRewardsAmount: String? + + public init() { + super.init(title: DataLocalizer.shared?.localize(path: "APP.GENERAL.TRADING_REWARDS", params: nil) ?? "") + } + + override func createContent(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> AnyView? { + HStack(spacing: 0) { + VStack(alignment: .leading, spacing: 10) { + titleValueStack(title: DataLocalizer.shared?.localize(path: "APP.PROFILES_PAGE.REWARDS_LAST_7_DAYS", params: nil) ?? "", value: last7DaysRewardsAmount) + titleValueStack(title: DataLocalizer.shared?.localize(path: "APP.PROFILES_PAGE.REWARDS_ALL_TIME", params: nil) ?? "", value: allTimeRewardsAmount) + } + Spacer() + } + .wrappedInAnyView() + } + + private func titleValueStack(title: String, value: String?) -> some View { + VStack(alignment: .leading, spacing: 4) { + Text(title) + .themeColor(foreground: .textTertiary) + .themeFont(fontType: .text, fontSize: .smaller) + HStack(spacing: 6) { + Text(value ?? "-") + .themeColor(foreground: .textSecondary) + .themeFont(fontType: .number, fontSize: .medium) + PlatformIconViewModel(type: .asset(name: "icon_dydx", bundle: .dydxView), clip: .noClip, size: .init(width: 24, height: 24), templateColor: nil) + .createView() + } + } + + } + + public static var previewValue: dydxProfileRewardsViewModel { + let vm = dydxProfileRewardsViewModel() + vm.last7DaysRewardsAmount = "20.00" + vm.allTimeRewardsAmount = "30.00" + return vm + } + +} + +#if DEBUG +struct dydxProfileRewardsViewModel_Previews_Dark: PreviewProvider { + @StateObject static var themeSettings = ThemeSettings.shared + + static var previews: some View { + ThemeSettings.applyDarkTheme() + ThemeSettings.applyStyles() + return dydxProfileRewardsViewModel.previewValue + .createView() + .themeColor(background: .layer0) + .environmentObject(themeSettings) + // .edgesIgnoringSafeArea(.bottom) + .previewLayout(.sizeThatFits) + } +} + +struct dydxProfileRewardsViewModel_Previews_Light: PreviewProvider { + @StateObject static var themeSettings = ThemeSettings.shared + + static var previews: some View { + ThemeSettings.applyLightTheme() + ThemeSettings.applyStyles() + return dydxProfileRewardsViewModel.previewValue + .createView() + .themeColor(background: .layer0) + .environmentObject(themeSettings) + // .edgesIgnoringSafeArea(.bottom) + .previewLayout(.sizeThatFits) + } +} +#endif diff --git a/dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift b/dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift index a143a8b8a..52a2ed581 100644 --- a/dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift +++ b/dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift @@ -17,6 +17,7 @@ public class dydxProfileViewModel: PlatformViewModel { @Published public var history: dydxProfileHistoryViewModel? = dydxProfileHistoryViewModel() @Published public var fees: dydxProfileFeesViewModel? = dydxProfileFeesViewModel() @Published public var balances: dydxProfileBalancesViewModel? = dydxProfileBalancesViewModel() + @Published public var rewards: dydxProfileRewardsViewModel? = dydxProfileRewardsViewModel() public init() { } @@ -50,6 +51,8 @@ public class dydxProfileViewModel: PlatformViewModel { HStack(spacing: 14) { self.fees? .createView(parentStyle: style) +// self.rewards? +// .createView(parentStyle: style) } Spacer(minLength: 100)