Skip to content

Commit

Permalink
MOB-240 : Trading Rewards hook in real data pt 2 (launch incentives) (#…
Browse files Browse the repository at this point in the history
…94)

* hook in new launch incentive properties

* temp

* integrate new abacus launch incentives fields

* add background texture

* use incentive points
  • Loading branch information
mike-dydx committed Aug 21, 2024
1 parent 88f842f commit 8e0275d
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 29 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 @@ -127,6 +127,7 @@
27351D452AC4A67900E4A563 /* dydxRestrictionsWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27351D442AC4A67900E4A563 /* dydxRestrictionsWorker.swift */; };
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 */; };
2749F8FF2B853B8700D6BA16 /* dydxRewardsLaunchIncentivesPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2749F8FE2B853B8700D6BA16 /* dydxRewardsLaunchIncentivesPresenter.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 */; };
Expand Down Expand Up @@ -468,6 +469,7 @@
27351D442AC4A67900E4A563 /* dydxRestrictionsWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxRestrictionsWorker.swift; sourceTree = "<group>"; };
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>"; };
2749F8FE2B853B8700D6BA16 /* dydxRewardsLaunchIncentivesPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxRewardsLaunchIncentivesPresenter.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>"; };
Expand Down Expand Up @@ -1295,6 +1297,7 @@
277E90182B1EA3C3005CCBCB /* dydxRewardsSummaryPresenter.swift */,
277E90322B1FAE9A005CCBCB /* dydxRewardsHelpViewPresenter.swift */,
277E908A2B2118AE005CCBCB /* dydxRewardsHistoryViewPresenter.swift */,
2749F8FE2B853B8700D6BA16 /* dydxRewardsLaunchIncentivesPresenter.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -1856,6 +1859,7 @@
64529A4C2AE8705E000810E6 /* dydxUpdateWorker.swift in Sources */,
02DDAD55292587C600CC7531 /* QRCodeDisplayBuilder.swift in Sources */,
0268BBFB2A8BE27800D0C59B /* dydxTransferOutViewPresenter.swift in Sources */,
2749F8FF2B853B8700D6BA16 /* dydxRewardsLaunchIncentivesPresenter.swift in Sources */,
027CA87229EDFC990069781A /* dydxTransferInputCtaButtonViewPresenter.swift in Sources */,
02D1CEE129C8DEA7009ADF9A /* dydxLanguageViewBuilder.swift in Sources */,
02D1342828EB572100B46941 /* SharedMarketPresenter.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// dydxRewardsLaunchIncentivesPresenter.swift
// dydxPresenters
//
// Created by Michael Maguire on 2/20/24.
//

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

public protocol dydxRewardsLaunchIncentivesPresenterProtocol: HostedViewPresenterProtocol {
var viewModel: dydxRewardsLaunchIncentivesViewModel? { get }
}

public class dydxRewardsLaunchIncentivesPresenter: HostedViewPresenter<dydxRewardsLaunchIncentivesViewModel>, dydxRewardsLaunchIncentivesPresenterProtocol {

override init() {
super.init()

viewModel = dydxRewardsLaunchIncentivesViewModel()
}

public override func start() {
super.start()

Publishers.CombineLatest(
AbacusStateManager.shared.state.account,
AbacusStateManager.shared.state.launchIncentive)
.sink { [weak self] (account, launchIncentive) in
self?.update(currentSeason: launchIncentive?.currentSeason, seasonPointMap: account?.launchIncentivePoints?.points)

}
.store(in: &subscriptions)

viewModel?.aboutAction = {
Router.shared?.navigate(to: URL(string: "https://dydx.exchange/blog/v4-full-trading"), completion: nil)
}

viewModel?.leaderboardAction = {
Router.shared?.navigate(to: URL(string: "https://community.chaoslabs.xyz/dydx-v4/risk/leaderboard"), completion: nil)
}
}

private func update(currentSeason: String?, seasonPointMap: [String: LaunchIncentivePoint]?) {
viewModel?.seasonOrdinal = currentSeason
if let currentSeason, let incentivePoints = seasonPointMap?[currentSeason]?.incentivePoints {
viewModel?.points = "\(incentivePoints)"
} else {
viewModel?.points = "--"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ private protocol dydxTradingRewardsViewPresenterProtocol: HostedViewPresenterPro

private class dydxTradingRewardsViewPresenter: HostedViewPresenter<dydxTradingRewardsViewModel>, dydxTradingRewardsViewPresenterProtocol {

private let launchIncentivesPresenter = dydxRewardsLaunchIncentivesPresenter()
private let summaryPresenter = dydxRewardsSummaryViewPresenter()
private let helpPresenter = dydxRewardsHelpViewPresenter()
private let historyPresenter = dydxRewardsHistoryViewPresenter()

private lazy var childPresenters: [HostedViewPresenterProtocol] = [
launchIncentivesPresenter,
summaryPresenter,
helpPresenter,
historyPresenter
Expand All @@ -54,13 +56,6 @@ private class dydxTradingRewardsViewPresenter: HostedViewPresenter<dydxTradingRe
Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss"), animated: true, completion: nil)
}

viewModel.launchIncentivesViewModel.aboutAction = {
Router.shared?.navigate(to: URL(string: "https://dydx.exchange/blog/v4-full-trading"), completion: nil)
}
viewModel.launchIncentivesViewModel.leaderboardAction = {
Router.shared?.navigate(to: URL(string: "https://community.chaoslabs.xyz/dydx-v4/risk/leaderboard"), completion: nil)
}

// comment out as part of https://linear.app/dydx/issue/TRCL-3445/remove-governance-and-staking-cards
// non-zero chance we add back
// these vars and their corresponding files can be fully deleted if rewards is no longer relevant
Expand All @@ -78,6 +73,7 @@ private class dydxTradingRewardsViewPresenter: HostedViewPresenter<dydxTradingRe
// Router.shared?.navigate (to: , completion: nil)
// }

launchIncentivesPresenter.$viewModel.assign(to: &viewModel.$launchIncentivesViewModel)
summaryPresenter.$viewModel.assign(to: &viewModel.$rewardsSummary)
helpPresenter.$viewModel.assign(to: &viewModel.$help)
historyPresenter.$viewModel.assign(to: &viewModel.$history)
Expand All @@ -92,18 +88,4 @@ private class dydxTradingRewardsViewPresenter: HostedViewPresenter<dydxTradingRe

attachChildren(workers: childPresenters)
}

override func start() {
super.start()

AbacusStateManager.shared.state.account
.sink { [weak self] _ in
// TODO: get from chaos labs
self?.viewModel?.launchIncentivesViewModel.seasonOrdinal = "--"
self?.viewModel?.launchIncentivesViewModel.estimatedPoints = "--"
self?.viewModel?.launchIncentivesViewModel.points = "--"
}
.store(in: &subscriptions)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ public final class AbacusState {
.eraseToAnyPublisher()
}

public var launchIncentive: AnyPublisher<LaunchIncentive?, Never> {
statePublisher
.map(\.?.launchIncentive)
.removeDuplicates()
.share()
.eraseToAnyPublisher()
}

public var hasAccount: AnyPublisher<Bool, Never> {
statePublisher
.compactMap {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "texture.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import PlatformUI
import Utilities

public class dydxRewardsLaunchIncentivesViewModel: PlatformViewModel {
@Published public var estimatedPoints: String?
@Published public var seasonOrdinal: String?
@Published public var points: String?
@Published public var aboutAction: (() -> Void)?
@Published public var leaderboardAction: (() -> Void)?

public static var previewValue: dydxRewardsLaunchIncentivesViewModel = {
let vm = dydxRewardsLaunchIncentivesViewModel()
vm.estimatedPoints = "10"
vm.seasonOrdinal = "1"
return vm
}()
Expand Down Expand Up @@ -61,16 +59,23 @@ public class dydxRewardsLaunchIncentivesViewModel: PlatformViewModel {
Text(DataLocalizer.shared?.localize(path: "APP.PORTFOLIO.ESTIMATED_REWARDS", params: nil) ?? "")
.themeFont(fontType: .text, fontSize: .medium)
.themeColor(foreground: .textPrimary)
Text(DataLocalizer.shared?.localize(path: "APP.TRADING_REWARDS.SEASON_ID", params: ["SEASON_ID": self.seasonOrdinal ?? ""]) ?? "")
.themeFont(fontType: .text, fontSize: .small)
.themeColor(foreground: .textPrimary)
if let seasonOrdinal {
Text(DataLocalizer.shared?.localize(path: "APP.TRADING_REWARDS.SEASON_ID", params: ["SEASON_ID": seasonOrdinal]) ?? "")
.themeFont(fontType: .text, fontSize: .small)
.themeColor(foreground: .textPrimary)
}
}
Text(pointsFormatted)
}
Spacer()
Image("stars", bundle: .dydxView)
}
.padding(.all, 16)
.background {
Image("texture", bundle: .dydxView)
.resizable()
.scaledToFill()
}
.themeColor(background: .layer4)
.borderAndClip(style: .cornerRadius(12), borderColor: .layer6, lineWidth: 1)
}
Expand Down Expand Up @@ -101,7 +106,7 @@ public class dydxRewardsLaunchIncentivesViewModel: PlatformViewModel {
}
.wrappedInAnyView()
}
return PlatformButtonViewModel(content: content, type: .defaultType, state: .primary, action: self.aboutAction ?? {})
return PlatformButtonViewModel(content: content, type: .defaultType, state: .primary, action: self.leaderboardAction ?? {})
.createView(parentStyle: parentStyle)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Utilities
public class dydxTradingRewardsViewModel: PlatformViewModel {

@Published public var headerViewModel: NavHeaderModel = NavHeaderModel()
@Published public var launchIncentivesViewModel: dydxRewardsLaunchIncentivesViewModel = dydxRewardsLaunchIncentivesViewModel()
@Published public var launchIncentivesViewModel: dydxRewardsLaunchIncentivesViewModel? = dydxRewardsLaunchIncentivesViewModel()
@Published public var rewardsSummary: dydxRewardsSummaryViewModel? = dydxRewardsSummaryViewModel()
@Published public var help: dydxRewardsHelpViewModel? = dydxRewardsHelpViewModel()
@Published public var history: dydxRewardsHistoryViewModel? = dydxRewardsHistoryViewModel()
Expand All @@ -36,7 +36,7 @@ public class dydxTradingRewardsViewModel: PlatformViewModel {
self.headerViewModel.createView(parentStyle: parentStyle)
ScrollView(showsIndicators: false) {
VStack(spacing: 16) {
self.launchIncentivesViewModel.createView(parentStyle: style)
self.launchIncentivesViewModel?.createView(parentStyle: style)
self.rewardsSummary?.createView(parentStyle: style)
self.help?.createView(parentStyle: style)
self.history?.createView(parentStyle: style)
Expand Down

0 comments on commit 8e0275d

Please sign in to comment.