Skip to content

Commit

Permalink
TRCL-3317 : Trading Rewards Detail Screen Rewards Summary Card (#37)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mike-dydx committed Aug 21, 2024
1 parent 7610e76 commit d4f0561
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
24 changes: 24 additions & 0 deletions dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -470,6 +472,8 @@
2741E3722A689740000FA190 /* dydxDirectionColorPreferenceViewBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxDirectionColorPreferenceViewBuilder.swift; sourceTree = "<group>"; };
276908FE2AAFB22F0075B2D6 /* dydxPortfolioTransfersViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxPortfolioTransfersViewPresenter.swift; sourceTree = "<group>"; };
277E8FC82B1E576B005CCBCB /* dydxProfileRewardsViewPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxProfileRewardsViewPresenter.swift; sourceTree = "<group>"; };
277E90142B1EA0E3005CCBCB /* dydxTradingRewardsViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradingRewardsViewPresenter.swift; sourceTree = "<group>"; };
277E90182B1EA3C3005CCBCB /* dydxTradingRewardsViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradingRewardsViewBuilder.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>"; };
64487FFE2AA248340068DD87 /* dydxAlertsWorker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxAlertsWorker.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -848,6 +852,7 @@
0258BA1E299294A90098E1BE /* Profile */ = {
isa = PBXGroup;
children = (
277E90052B1EA093005CCBCB /* TradingRewards */,
02B27A3B2AE8BC6B00A995EC /* Help */,
0273A1392ACCC4A9001B89F5 /* History */,
024FEB552ACB75A40087A55E /* FeesStructure */,
Expand Down Expand Up @@ -1277,6 +1282,23 @@
path = DirectionColorPreference;
sourceTree = "<group>";
};
277E90052B1EA093005CCBCB /* TradingRewards */ = {
isa = PBXGroup;
children = (
277E90172B1EA376005CCBCB /* Components */,
277E90142B1EA0E3005CCBCB /* dydxTradingRewardsViewPresenter.swift */,
);
path = TradingRewards;
sourceTree = "<group>";
};
277E90172B1EA376005CCBCB /* Components */ = {
isa = PBXGroup;
children = (
277E90182B1EA3C3005CCBCB /* dydxTradingRewardsViewBuilder.swift */,
);
path = Components;
sourceTree = "<group>";
};
27DB2E932AC1E7040047BC39 /* Error */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
20 changes: 20 additions & 0 deletions dydx/dydxPresenters/dydxPresenters/_Features/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@
"destination":"dydxPresenters.dydxFeesStuctureViewBuilder",
"presentation":"push"
},
"/profile/trading-rewards":{
"destination":"dydxPresenters.dydxTradingRewardsViewBuilder",
"presentation":"push"
},
"/portfolio":{
"destination":"dydxPresenters.dydxPortfolioViewBuilder"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ public class dydxProfileRewardsViewPresenter: HostedViewPresenter<dydxProfileRew
viewModel = dydxProfileRewardsViewModel()
viewModel?.last7DaysRewardsAmount = "PLACEHOLDER"
viewModel?.allTimeRewardsAmount = "PLACEHOLDER"

viewModel?.tapAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/profile/trading-rewards"), animated: true, completion: nil)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// dydxRewardsSummaryPresenter.swift
// dydxPresenters
//
// Created by Michael Maguire on 12/4/23.
//

import dydxViews
import PlatformParticles
import ParticlesKit

public protocol dydxRewardsSummaryPresenterProtocol: HostedViewPresenterProtocol {
var viewModel: dydxProfileRewardsViewModel? { get }
}

public class dydxRewardsSummaryViewPresenter: HostedViewPresenter<dydxProfileRewardsViewModel>, dydxProfileRewardsViewPresenterProtocol {
override init() {
super.init()

viewModel = dydxProfileRewardsViewModel()
viewModel?.last7DaysRewardsAmount = "PLACEHOLDER"
viewModel?.allTimeRewardsAmount = "PLACEHOLDER"
}
}
Original file line number Diff line number Diff line change
@@ -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>() -> 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<PlatformView, dydxTradingRewardsViewModel> {
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<dydxTradingRewardsViewModel>, 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)
}
}
}
24 changes: 24 additions & 0 deletions dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -496,6 +498,8 @@
277442962AD88C4900C91357 /* Satoshi-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Satoshi-Regular.otf"; sourceTree = "<group>"; };
277E8F9E2B1A847D005CCBCB /* dydxTitledCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTitledCardView.swift; sourceTree = "<group>"; };
277E8FCA2B1E5798005CCBCB /* dydxProfileRewardsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxProfileRewardsViewModel.swift; sourceTree = "<group>"; };
277E90122B1EA0D3005CCBCB /* dydxTradingRewardsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradingRewardsView.swift; sourceTree = "<group>"; };
277E901A2B1EA4F9005CCBCB /* dydxRewardsSummaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxRewardsSummaryView.swift; sourceTree = "<group>"; };
27A799B82A66EC2D007C3D04 /* ThemeClassicDark.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ThemeClassicDark.json; sourceTree = "<group>"; };
27AAA9852ACE34C800AF3C56 /* SwiftMessages+Banner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftMessages+Banner.swift"; sourceTree = "<group>"; };
27C027442AFD734800E92CCB /* dydxSettingsHelpRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSettingsHelpRowView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1001,6 +1005,7 @@
0258BA0F2992947E0098E1BE /* Profile */ = {
isa = PBXGroup;
children = (
277E8FF82B1EA083005CCBCB /* TradingRewards */,
02B27A382AE8BC4500A995EC /* Help */,
0273A12A2ACCC48D001B89F5 /* History */,
024FEB622ACB75C00087A55E /* FeesStructure */,
Expand Down Expand Up @@ -1338,6 +1343,23 @@
path = Settings;
sourceTree = "<group>";
};
277E8FF82B1EA083005CCBCB /* TradingRewards */ = {
isa = PBXGroup;
children = (
277E90162B1EA36E005CCBCB /* Components */,
277E90122B1EA0D3005CCBCB /* dydxTradingRewardsView.swift */,
);
path = TradingRewards;
sourceTree = "<group>";
};
277E90162B1EA36E005CCBCB /* Components */ = {
isa = PBXGroup;
children = (
277E901A2B1EA4F9005CCBCB /* dydxRewardsSummaryView.swift */,
);
path = Components;
sourceTree = "<group>";
};
27AAA9782ACE34B600AF3C56 /* Banner */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit d4f0561

Please sign in to comment.