Skip to content

Commit

Permalink
add rewards card to profile landing screen
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Dec 4, 2023
1 parent b3f1305 commit 3d3861c
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 2 deletions.
4 changes: 4 additions & 0 deletions dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -468,6 +469,7 @@
2741E3632A68787A000FA190 /* settings_direction_color_preference.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = settings_direction_color_preference.json; sourceTree = "<group>"; };
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>"; };
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 @@ -867,6 +869,7 @@
0258BA2729929E7D0098E1BE /* Components */ = {
isa = PBXGroup;
children = (
277E8FC82B1E576B005CCBCB /* dydxProfileRewardsViewPresenter.swift */,
027F3F052AB93B3700602E5B /* dydxProfileBalancesViewPresenter.swift */,
0258BA2829929E870098E1BE /* dydxProfileButtonsViewPresenter.swift */,
028DB33F2A05893D0090BE58 /* dydxProfileHeaderViewPresenter.swift */,
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<dydxProfileRewardsViewModel>, dydxProfileRewardsViewPresenterProtocol {
override init() {
super.init()

viewModel = dydxProfileRewardsViewModel()
viewModel?.last7DaysRewardsAmount = "PLACEHOLDER"
viewModel?.allTimeRewardsAmount = "PLACEHOLDER"
}
}
4 changes: 4 additions & 0 deletions dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -494,6 +495,7 @@
277442952AD88C4900C91357 /* Satoshi-Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Satoshi-Bold.otf"; sourceTree = "<group>"; };
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>"; };
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 @@ -1014,6 +1016,7 @@
0258BA2429929D050098E1BE /* Components */ = {
isa = PBXGroup;
children = (
277E8FCA2B1E5798005CCBCB /* dydxProfileRewardsViewModel.swift */,
027F3EF62AB93ADC00602E5B /* dydxProfileBalancesViewModel.swift */,
0258BA2529929D1B0098E1BE /* dydxProfileButtonsView.swift */,
028DB33D2A0589270090BE58 /* dydxProfileHeaderView.swift */,
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public class dydxProfileFeesViewModel: dydxTitledCardViewModel, Equatable {
.leftAligned()
}
}
.padding(16)
.wrappedInAnyView()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public class dydxProfileHistoryViewModel: dydxTitledCardViewModel {
}
}
.frame(maxWidth: .infinity)
.padding()
.themeFont(fontSize: .smaller)
.themeColor(foreground: .textTertiary)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }

Expand Down Expand Up @@ -50,6 +51,8 @@ public class dydxProfileViewModel: PlatformViewModel {
HStack(spacing: 14) {
self.fees?
.createView(parentStyle: style)
// self.rewards?
// .createView(parentStyle: style)
}

Spacer(minLength: 100)
Expand Down

0 comments on commit 3d3861c

Please sign in to comment.