From d4f0561dce36e3ee5f9f2674a82024ad60f17a9e Mon Sep 17 00:00:00 2001 From: mike-dydx <149746839+mike-dydx@users.noreply.github.com> Date: Tue, 5 Dec 2023 13:33:40 -0500 Subject: [PATCH] TRCL-3317 : Trading Rewards Detail Screen Rewards Summary Card (#37) * add routing to trading rewards and trading rewards summary card * adjust for long value wrapping * remove unnecessary imports * clean up * add enable_trading_rewards feature flag --- .../_Utils/dydxFeatureFlag.swift | 1 + .../dydxPresenters.xcodeproj/project.pbxproj | 24 +++++ .../dydxPresenters/_Features/features.json | 20 ++++ .../_Features/routing_swiftui.json | 4 + .../dydxProfileRewardsViewPresenter.swift | 4 + .../dydxTradingRewardsViewBuilder.swift | 24 +++++ .../dydxTradingRewardsViewPresenter.swift | 45 +++++++++ .../dydxViews.xcodeproj/project.pbxproj | 24 +++++ .../dydxProfileRewardsViewModel.swift | 2 + .../Components/dydxTitledCardView.swift | 10 +- .../Components/dydxRewardsSummaryView.swift | 91 +++++++++++++++++++ .../dydxTradingRewardsView.swift | 73 +++++++++++++++ .../_v4/Profile/dydxProfileView.swift | 10 +- 13 files changed, 324 insertions(+), 8 deletions(-) create mode 100644 dydx/dydxPresenters/dydxPresenters/_v4/Profile/TradingRewards/Components/dydxTradingRewardsViewBuilder.swift create mode 100644 dydx/dydxPresenters/dydxPresenters/_v4/Profile/TradingRewards/dydxTradingRewardsViewPresenter.swift create mode 100644 dydx/dydxViews/dydxViews/_v4/Profile/TradingRewards/Components/dydxRewardsSummaryView.swift create mode 100644 dydx/dydxViews/dydxViews/_v4/Profile/TradingRewards/dydxTradingRewardsView.swift diff --git a/dydx/dydxFormatter/dydxFormatter/_Utils/dydxFeatureFlag.swift b/dydx/dydxFormatter/dydxFormatter/_Utils/dydxFeatureFlag.swift index 901dc9457..54778f4e9 100644 --- a/dydx/dydxFormatter/dydxFormatter/_Utils/dydxFeatureFlag.swift +++ b/dydx/dydxFormatter/dydxFormatter/_Utils/dydxFeatureFlag.swift @@ -14,6 +14,7 @@ public enum dydxBoolFeatureFlag: String, CaseIterable { case full_story case force_mainnet case enable_cctp + case enable_trading_rewards private static let obj = NSObject() diff --git a/dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj b/dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj index 3f4919709..484329b01 100644 --- a/dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj +++ b/dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj @@ -131,6 +131,8 @@ 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 */; }; + 277E90152B1EA0E3005CCBCB /* dydxTradingRewardsViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277E90142B1EA0E3005CCBCB /* dydxTradingRewardsViewPresenter.swift */; }; + 277E90192B1EA3C3005CCBCB /* dydxTradingRewardsViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277E90182B1EA3C3005CCBCB /* dydxTradingRewardsViewBuilder.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 */; }; @@ -470,6 +472,8 @@ 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 = ""; }; + 277E90142B1EA0E3005CCBCB /* dydxTradingRewardsViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradingRewardsViewPresenter.swift; sourceTree = ""; }; + 277E90182B1EA3C3005CCBCB /* dydxTradingRewardsViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradingRewardsViewBuilder.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 = ""; }; @@ -848,6 +852,7 @@ 0258BA1E299294A90098E1BE /* Profile */ = { isa = PBXGroup; children = ( + 277E90052B1EA093005CCBCB /* TradingRewards */, 02B27A3B2AE8BC6B00A995EC /* Help */, 0273A1392ACCC4A9001B89F5 /* History */, 024FEB552ACB75A40087A55E /* FeesStructure */, @@ -1277,6 +1282,23 @@ path = DirectionColorPreference; sourceTree = ""; }; + 277E90052B1EA093005CCBCB /* TradingRewards */ = { + isa = PBXGroup; + children = ( + 277E90172B1EA376005CCBCB /* Components */, + 277E90142B1EA0E3005CCBCB /* dydxTradingRewardsViewPresenter.swift */, + ); + path = TradingRewards; + sourceTree = ""; + }; + 277E90172B1EA376005CCBCB /* Components */ = { + isa = PBXGroup; + children = ( + 277E90182B1EA3C3005CCBCB /* dydxTradingRewardsViewBuilder.swift */, + ); + path = Components; + sourceTree = ""; + }; 27DB2E932AC1E7040047BC39 /* Error */ = { isa = PBXGroup; children = ( @@ -1775,6 +1797,7 @@ 0208631028F5186E00C9D3A0 /* OrderbookLineDataPoint.swift in Sources */, 0276FA992A0DB8FD000BDF0B /* Model+Ext.swift in Sources */, 6488BBC7296F2CD50096502F /* AbacusUtils.swift in Sources */, + 277E90192B1EA3C3005CCBCB /* dydxTradingRewardsViewBuilder.swift in Sources */, 026FC3E42AFACA3300C52F20 /* dydxPresentersBundleClass.swift in Sources */, 025841F228EE9D7C007338D3 /* dydxMarketAssetListViewPresenter.swift in Sources */, 02F95A8E2A1D6AAD00828F9A /* dydxProfileHistoryViewPresenter.swift in Sources */, @@ -1820,6 +1843,7 @@ 276908FF2AAFB22F0075B2D6 /* dydxPortfolioTransfersViewPresenter.swift in Sources */, 6496DBC9295CBBDD00174CE7 /* dydxV4TabBarBuilder.swift in Sources */, 02F7010029EA165F004DEB5E /* dydxTransferReceiptViewPresenter.swift in Sources */, + 277E90152B1EA0E3005CCBCB /* dydxTradingRewardsViewPresenter.swift in Sources */, 0216441128F36FBE00C7093E /* CandleDataPoint.swift in Sources */, 6453A7D2299C563F0041A0C4 /* dydxClosePositionInputViewBuilder.swift in Sources */, 02031F142AC374150069E00D /* dydxTradeSheetTipBuySellViewPresenter.swift in Sources */, diff --git a/dydx/dydxPresenters/dydxPresenters/_Features/features.json b/dydx/dydxPresenters/dydxPresenters/_Features/features.json index dd6d00fc7..0e4131f80 100644 --- a/dydx/dydxPresenters/dydxPresenters/_Features/features.json +++ b/dydx/dydxPresenters/dydxPresenters/_Features/features.json @@ -53,6 +53,26 @@ ] } }, + { + "title":{ + "text":"Enable Trading Rewards" + }, + "field":{ + "field":"enable_trading_rewards", + "optional":true, + "type" : "text", + "options" : [ + { + "text": "yes", + "value" : "1" + }, + { + "text": "no", + "value" : "0" + } + ] + } + }, { "title":{ "text":"Push Notification" diff --git a/dydx/dydxPresenters/dydxPresenters/_Features/routing_swiftui.json b/dydx/dydxPresenters/dydxPresenters/_Features/routing_swiftui.json index e8053c750..e2fc9185a 100644 --- a/dydx/dydxPresenters/dydxPresenters/_Features/routing_swiftui.json +++ b/dydx/dydxPresenters/dydxPresenters/_Features/routing_swiftui.json @@ -209,6 +209,10 @@ "destination":"dydxPresenters.dydxFeesStuctureViewBuilder", "presentation":"push" }, + "/profile/trading-rewards":{ + "destination":"dydxPresenters.dydxTradingRewardsViewBuilder", + "presentation":"push" + }, "/portfolio":{ "destination":"dydxPresenters.dydxPortfolioViewBuilder" }, diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Components/dydxProfileRewardsViewPresenter.swift b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Components/dydxProfileRewardsViewPresenter.swift index 6a810f316..320b70e6e 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Components/dydxProfileRewardsViewPresenter.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Components/dydxProfileRewardsViewPresenter.swift @@ -27,5 +27,9 @@ public class dydxProfileRewardsViewPresenter: HostedViewPresenter, dydxProfileRewardsViewPresenterProtocol { + override init() { + super.init() + + viewModel = dydxProfileRewardsViewModel() + viewModel?.last7DaysRewardsAmount = "PLACEHOLDER" + viewModel?.allTimeRewardsAmount = "PLACEHOLDER" + } +} diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/TradingRewards/dydxTradingRewardsViewPresenter.swift b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/TradingRewards/dydxTradingRewardsViewPresenter.swift new file mode 100644 index 000000000..9c7dfd134 --- /dev/null +++ b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/TradingRewards/dydxTradingRewardsViewPresenter.swift @@ -0,0 +1,45 @@ +// +// dydxTradingRewardsViewPresenter.swift +// dydxPresenters +// +// Created by Michael Maguire on 12/4/23. +// + +import Utilities +import dydxViews +import RoutingKit +import PlatformUI + +public class dydxTradingRewardsViewBuilder: NSObject, ObjectBuilderProtocol { + public func build() -> T? { + let presenter = dydxTradingRewardsViewPresenter() + let view = presenter.viewModel?.createView() ?? PlatformViewModel().createView() + return dydxTradingRewardsViewController(presenter: presenter, view: view, configuration: .tabbarItemView) as? T + } +} + +private class dydxTradingRewardsViewController: HostingViewController { + override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool { + if request?.path == "/trading-rewards" { + return true + } + return false + } +} + +private protocol dydxTradingRewardsViewPresenterProtocol: HostedViewPresenterProtocol { + var viewModel: dydxTradingRewardsViewModel? { get } +} + +private class dydxTradingRewardsViewPresenter: HostedViewPresenter, dydxTradingRewardsViewPresenterProtocol { + override init() { + super.init() + + viewModel = dydxTradingRewardsViewModel() + + viewModel?.headerViewModel.title = DataLocalizer.localize(path: "APP.GENERAL.TRADING_REWARDS") + viewModel?.headerViewModel.backButtonAction = { + Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss"), animated: true, completion: nil) + } + } +} diff --git a/dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj b/dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj index 8ca7fb428..2060aa431 100644 --- a/dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj +++ b/dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj @@ -160,6 +160,8 @@ 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 */; }; + 277E90132B1EA0D3005CCBCB /* dydxTradingRewardsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277E90122B1EA0D3005CCBCB /* dydxTradingRewardsView.swift */; }; + 277E901B2B1EA4F9005CCBCB /* dydxRewardsSummaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277E901A2B1EA4F9005CCBCB /* dydxRewardsSummaryView.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 */; }; @@ -496,6 +498,8 @@ 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 = ""; }; + 277E90122B1EA0D3005CCBCB /* dydxTradingRewardsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradingRewardsView.swift; sourceTree = ""; }; + 277E901A2B1EA4F9005CCBCB /* dydxRewardsSummaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxRewardsSummaryView.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 = ""; }; @@ -1001,6 +1005,7 @@ 0258BA0F2992947E0098E1BE /* Profile */ = { isa = PBXGroup; children = ( + 277E8FF82B1EA083005CCBCB /* TradingRewards */, 02B27A382AE8BC4500A995EC /* Help */, 0273A12A2ACCC48D001B89F5 /* History */, 024FEB622ACB75C00087A55E /* FeesStructure */, @@ -1338,6 +1343,23 @@ path = Settings; sourceTree = ""; }; + 277E8FF82B1EA083005CCBCB /* TradingRewards */ = { + isa = PBXGroup; + children = ( + 277E90162B1EA36E005CCBCB /* Components */, + 277E90122B1EA0D3005CCBCB /* dydxTradingRewardsView.swift */, + ); + path = TradingRewards; + sourceTree = ""; + }; + 277E90162B1EA36E005CCBCB /* Components */ = { + isa = PBXGroup; + children = ( + 277E901A2B1EA4F9005CCBCB /* dydxRewardsSummaryView.swift */, + ); + path = Components; + sourceTree = ""; + }; 27AAA9782ACE34B600AF3C56 /* Banner */ = { isa = PBXGroup; children = ( @@ -1798,6 +1820,7 @@ 02D1344128EBA86200B46941 /* dydxMarketAssetSortView.swift in Sources */, 02EC0D9E29FAD3EB0015C4B3 /* IntervalText.swift in Sources */, 270E7E342A5F700B00136793 /* dydxOrderbookManagerView.swift in Sources */, + 277E901B2B1EA4F9005CCBCB /* dydxRewardsSummaryView.swift in Sources */, 02084B2D297FC2CD00CF9522 /* dydxTransferFaucetView.swift in Sources */, 022EDC8E29A048B3003D59A7 /* dydxClosePositionHeaderView.swift in Sources */, 0256F53629AFFC9800A083C0 /* dydxOnboardConnectView.swift in Sources */, @@ -1887,6 +1910,7 @@ 02DDE09F28F37D4200945990 /* dydxMarketPriceCandlesHighlightView.swift in Sources */, 02A9B6102900605400AE1516 /* SizeText.swift in Sources */, 64A4DB6F2966218B008D8E20 /* dydxTradeInputOrderTypeView.swift in Sources */, + 277E90132B1EA0D3005CCBCB /* dydxTradingRewardsView.swift in Sources */, 02678F5B2965DEAD00EE346B /* dydxPortfolioSectionsView.swift in Sources */, 64A4DB762966276B008D8E20 /* dydxTradeInputTriggerPriceView.swift in Sources */, 0238FEBF2970CBEF002E1C1A /* dydxMarketAccountView.swift in Sources */, diff --git a/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileRewardsViewModel.swift b/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileRewardsViewModel.swift index 7e696b646..bb097d206 100644 --- a/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileRewardsViewModel.swift +++ b/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileRewardsViewModel.swift @@ -38,6 +38,8 @@ public class dydxProfileRewardsViewModel: dydxTitledCardViewModel { Text(value ?? "-") .themeColor(foreground: .textSecondary) .themeFont(fontType: .number, fontSize: .medium) + .lineLimit(1) + .minimumScaleFactor(0.5) PlatformIconViewModel(type: .asset(name: "icon_dydx", bundle: .dydxView), clip: .noClip, size: .init(width: 24, height: 24), templateColor: nil) .createView() } diff --git a/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxTitledCardView.swift b/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxTitledCardView.swift index 96b2430a7..e83b4ccff 100644 --- a/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxTitledCardView.swift +++ b/dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxTitledCardView.swift @@ -37,10 +37,12 @@ public class dydxTitledCardViewModel: PlatformViewModel { Text(self.title) .themeFont(fontSize: .small) Spacer() - PlatformIconViewModel(type: .system(name: "chevron.right"), - size: CGSize(width: 10, height: 10), - templateColor: .textSecondary) - .createView(parentStyle: style) + if self.tapAction != nil { + PlatformIconViewModel(type: .system(name: "chevron.right"), + size: CGSize(width: 10, height: 10), + templateColor: .textSecondary) + .createView(parentStyle: style) + } } .padding() diff --git a/dydx/dydxViews/dydxViews/_v4/Profile/TradingRewards/Components/dydxRewardsSummaryView.swift b/dydx/dydxViews/dydxViews/_v4/Profile/TradingRewards/Components/dydxRewardsSummaryView.swift new file mode 100644 index 000000000..66e48e7ad --- /dev/null +++ b/dydx/dydxViews/dydxViews/_v4/Profile/TradingRewards/Components/dydxRewardsSummaryView.swift @@ -0,0 +1,91 @@ +// +// dydxRewardsSummaryView.swift +// dydxViews +// +// Created by Michael Maguire on 12/4/23. +// + +import SwiftUI +import PlatformUI +import Utilities + +public class dydxRewardsSummaryViewModel: dydxTitledCardViewModel { + @Published public var last7DaysRewardsAmount: String? + @Published public var last7DaysRewardsPeriod: String? + @Published public var allTimeRewardsAmount: String? + @Published public var allTimeRewardsValue: String? + + public init() { + super.init(title: DataLocalizer.shared?.localize(path: "APP.GENERAL.TRADING_REWARDS_SUMMARY", params: nil) ?? "") + } + + override func createContent(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> AnyView? { + HStack(spacing: 18) { + HStack { + titleValueStack(title: DataLocalizer.shared?.localize(path: "APP.PROFILES_PAGE.REWARDS_LAST_7_DAYS", params: nil) ?? "", primaryValue: last7DaysRewardsAmount, secondaryValue: last7DaysRewardsPeriod) + titleValueStack(title: DataLocalizer.shared?.localize(path: "APP.PROFILES_PAGE.REWARDS_ALL_TIME", params: nil) ?? "", primaryValue: last7DaysRewardsAmount, secondaryValue: allTimeRewardsValue) + } + } + .wrappedInAnyView() + } + + private func titleValueStack(title: String, primaryValue: String?, secondaryValue: String?) -> some View { + VStack(alignment: .leading, spacing: 4) { + Text(title) + .themeColor(foreground: .textTertiary) + .themeFont(fontType: .text, fontSize: .smaller) + HStack(spacing: 6) { + Text(primaryValue ?? "-") + .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() + } + Text(secondaryValue ?? "-") + .themeColor(foreground: .textTertiary) + .themeFont(fontType: .text, fontSize: .small) + } + .leftAligned() + + } + + public static var previewValue: dydxRewardsSummaryViewModel { + let vm = dydxRewardsSummaryViewModel() + vm.last7DaysRewardsAmount = "20.00" + vm.allTimeRewardsAmount = "30.00" + return vm + } + +} + +#if DEBUG +struct dydxRewardsSummaryViewModel_Previews_Dark: PreviewProvider { + @StateObject static var themeSettings = ThemeSettings.shared + + static var previews: some View { + ThemeSettings.applyDarkTheme() + ThemeSettings.applyStyles() + return dydxRewardsSummaryViewModel.previewValue + .createView() + .themeColor(background: .layer0) + .environmentObject(themeSettings) + // .edgesIgnoringSafeArea(.bottom) + .previewLayout(.sizeThatFits) + } +} + +struct dydxRewardsSummaryViewModel_Previews_Light: PreviewProvider { + @StateObject static var themeSettings = ThemeSettings.shared + + static var previews: some View { + ThemeSettings.applyLightTheme() + ThemeSettings.applyStyles() + return dydxRewardsSummaryViewModel.previewValue + .createView() + .themeColor(background: .layer0) + .environmentObject(themeSettings) + // .edgesIgnoringSafeArea(.bottom) + .previewLayout(.sizeThatFits) + } +} +#endif diff --git a/dydx/dydxViews/dydxViews/_v4/Profile/TradingRewards/dydxTradingRewardsView.swift b/dydx/dydxViews/dydxViews/_v4/Profile/TradingRewards/dydxTradingRewardsView.swift new file mode 100644 index 000000000..67430c0ad --- /dev/null +++ b/dydx/dydxViews/dydxViews/_v4/Profile/TradingRewards/dydxTradingRewardsView.swift @@ -0,0 +1,73 @@ +// +// dydxTradingRewardsView.swift +// dydxViews +// +// Created by Michael Maguire on 12/4/23. +// + +import SwiftUI +import PlatformUI +import Utilities + +public class dydxTradingRewardsViewModel: PlatformViewModel { + + @Published public var headerViewModel: NavHeaderModel = NavHeaderModel() + @Published public var rewardsSummary: dydxRewardsSummaryViewModel = dydxRewardsSummaryViewModel() + + public init() { } + + public static var previewValue: dydxHelpViewModel { + let vm = dydxHelpViewModel() + return vm + } + + 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 else { return AnyView(PlatformView.nilView) } + return VStack(spacing: 24) { + ScrollView(showsIndicators: false) { + self.headerViewModel.createView(parentStyle: parentStyle) + self.rewardsSummary.createView(parentStyle: style) + Spacer(minLength: 68) + } + .padding() + } + .frame(maxWidth: .infinity) + .themeColor(background: .layer2) + .ignoresSafeArea(edges: [.bottom]) + .wrappedInAnyView() + } + } +} + +#if DEBUG +struct dydxTradingRewardsViewModel_Previews_Dark: PreviewProvider { + @StateObject static var themeSettings = ThemeSettings.shared + + static var previews: some View { + ThemeSettings.applyDarkTheme() + ThemeSettings.applyStyles() + return dydxHelpViewModel.previewValue + .createView() + .themeColor(background: .layer0) + .environmentObject(themeSettings) + // .edgesIgnoringSafeArea(.bottom) + .previewLayout(.sizeThatFits) + } +} + +struct dydxTradingRewardsViewModel_Previews_Light: PreviewProvider { + @StateObject static var themeSettings = ThemeSettings.shared + + static var previews: some View { + ThemeSettings.applyLightTheme() + ThemeSettings.applyStyles() + return dydxHelpViewModel.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 816be4672..e5307cbb3 100644 --- a/dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift +++ b/dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift @@ -9,6 +9,7 @@ import SwiftUI import PlatformUI import Utilities +import dydxFormatter public class dydxProfileViewModel: PlatformViewModel { @Published public var header = dydxProfileHeaderViewModel() @@ -48,11 +49,12 @@ public class dydxProfileViewModel: PlatformViewModel { HStack(spacing: 14) { self.fees? .createView(parentStyle: style) - //TODO, comment in when abacus is ready -// self.rewards? -// .createView(parentStyle: style) + if dydxBoolFeatureFlag.enable_trading_rewards.isEnabled { + self.rewards? + .createView(parentStyle: style) + } } - + self.history? .createView(parentStyle: style)