Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mike/trcl 3314 trading rewards profile card #36

Merged
merged 9 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions PlatformUI/PlatformUI/Components/Input/PlatformInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ open class PlatformPopoverOptionsInputViewModel: PlatformOptionsInputViewModel {
guard let self = self else {
return
}
attrs.position = self.position
attrs.position = self.position
attrs.sourceFrameInset.top = -8
let animation = Animation.easeOut(duration: 0.2)
attrs.presentation.animation = animation
Expand Down Expand Up @@ -504,6 +504,17 @@ open class PlatformBooleanInputViewModel: PlatformValueInputViewModel {

open var isEnabled: Bool = true

open override var header: PlatformViewModel {
if let label = label, label.length > 0 {
return Text(label)
.themeColor(foreground: isEnabled ? .textSecondary : .textTertiary)
.themeFont(fontSize: .smaller)
.wrappedViewModel

}
return PlatformView.nilViewModel
}

override open var value: String? {
didSet {
inputBinding.update()
Expand All @@ -525,8 +536,9 @@ open class PlatformBooleanInputViewModel: PlatformValueInputViewModel {
guard let self = self else { return AnyView(PlatformView.nilView) }

return AnyView(
HStack {
HStack(spacing: 0) {
self.header.createView(parentStyle: style)
.fixedSize()
Spacer()
Toggle("", isOn: self.inputBinding)
.toggleStyle(SwitchToggleStyle(tint: ThemeColor.SemanticColor.colorPurple.color))
Expand Down
12 changes: 8 additions & 4 deletions dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
027CA87229EDFC990069781A /* dydxTransferInputCtaButtonViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027CA87129EDFC990069781A /* dydxTransferInputCtaButtonViewPresenter.swift */; };
027CB28729EEFF910069781A /* dydxTransferStatusViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027CB28629EEFF910069781A /* dydxTransferStatusViewBuilder.swift */; };
027E1EF829CA27CD0098666F /* dydxSettingsLandingViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027E1EF729CA27CD0098666F /* dydxSettingsLandingViewBuilder.swift */; };
027F3F062AB93B3700602E5B /* dydxProfileRewardsViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027F3F052AB93B3700602E5B /* dydxProfileRewardsViewPresenter.swift */; };
027F3F062AB93B3700602E5B /* dydxProfileBalancesViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027F3F052AB93B3700602E5B /* dydxProfileBalancesViewPresenter.swift */; };
0280B3A629CB63E10017D64A /* dydxOnboardWelcomeViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0280B3A529CB63E10017D64A /* dydxOnboardWelcomeViewBuilder.swift */; };
0284202F29AD727200C0E7CC /* dydxViews.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0284201F29AD725000C0E7CC /* dydxViews.framework */; };
02860A9F29C15E760079E644 /* dydxOnboardScanViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02860A9329C15E760079E644 /* dydxOnboardScanViewBuilder.swift */; };
Expand Down 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 @@ -409,7 +410,7 @@
027CA87129EDFC990069781A /* dydxTransferInputCtaButtonViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTransferInputCtaButtonViewPresenter.swift; sourceTree = "<group>"; };
027CB28629EEFF910069781A /* dydxTransferStatusViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTransferStatusViewBuilder.swift; sourceTree = "<group>"; };
027E1EF729CA27CD0098666F /* dydxSettingsLandingViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSettingsLandingViewBuilder.swift; sourceTree = "<group>"; };
027F3F052AB93B3700602E5B /* dydxProfileRewardsViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxProfileRewardsViewPresenter.swift; sourceTree = "<group>"; };
027F3F052AB93B3700602E5B /* dydxProfileBalancesViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxProfileBalancesViewPresenter.swift; sourceTree = "<group>"; };
0280B3A529CB63E10017D64A /* dydxOnboardWelcomeViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxOnboardWelcomeViewBuilder.swift; sourceTree = "<group>"; };
0284201929AD725000C0E7CC /* dydxViews.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = dydxViews.xcodeproj; path = ../dydxViews/dydxViews.xcodeproj; sourceTree = "<group>"; };
02860A9329C15E760079E644 /* dydxOnboardScanViewBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxOnboardScanViewBuilder.swift; sourceTree = "<group>"; };
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,7 +869,8 @@
0258BA2729929E7D0098E1BE /* Components */ = {
isa = PBXGroup;
children = (
027F3F052AB93B3700602E5B /* dydxProfileRewardsViewPresenter.swift */,
277E8FC82B1E576B005CCBCB /* dydxProfileRewardsViewPresenter.swift */,
027F3F052AB93B3700602E5B /* dydxProfileBalancesViewPresenter.swift */,
0258BA2829929E870098E1BE /* dydxProfileButtonsViewPresenter.swift */,
028DB33F2A05893D0090BE58 /* dydxProfileHeaderViewPresenter.swift */,
02F95A8D2A1D6AAD00828F9A /* dydxProfileHistoryViewPresenter.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 All @@ -1821,7 +1825,7 @@
02031F142AC374150069E00D /* dydxTradeSheetTipBuySellViewPresenter.swift in Sources */,
02B6CE752A7087A700C5F088 /* dydxTransferSubaccountWorker.swift in Sources */,
02FF0BD229AE92FE00781EDA /* dydxWalletListViewBuilder.swift in Sources */,
027F3F062AB93B3700602E5B /* dydxProfileRewardsViewPresenter.swift in Sources */,
027F3F062AB93B3700602E5B /* dydxProfileBalancesViewPresenter.swift in Sources */,
02F6E71F2A8293270018F00C /* dydxProfileFeesViewPresenter.swift in Sources */,
647D0F152A9FB1C600DA7815 /* dydxFrontendAlertsProvider.swift in Sources */,
02D1345828ECF30000B46941 /* dydxMarketsSearchViewBuilder.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// dydxProfileBalancesViewPresenter.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 dydxProfileBalancesViewPresenterProtocol: HostedViewPresenterProtocol {
var viewModel: dydxProfileBalancesViewModel? { get }
}

public class dydxProfileBalancesViewPresenter: HostedViewPresenter<dydxProfileBalancesViewModel>, dydxProfileBalancesViewPresenterProtocol {
override init() {
super.init()

viewModel = dydxProfileBalancesViewModel()
viewModel?.nativeTokenName = dydxTokenConstants.nativeTokenName
viewModel?.nativeTokenLogoUrl = dydxTokenConstants.nativeTokenLogoUrl
}

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

AbacusStateManager.shared.state.accountBalance(of: .dydx)
.sink { [weak self] dydxAmount in
if let dydxAmount = dydxAmount {
self?.viewModel?.walletAmount = dydxFormatter.shared.raw(number: Parser.standard.asNumber(dydxAmount), digits: 4)
self?.viewModel?.transferAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/transfer", params: ["section": "transferOut"]), animated: true, completion: nil)
}
} else {
self?.viewModel?.walletAmount = "-"
self?.viewModel?.transferAction = nil
}
}
.store(in: &subscriptions)

AbacusStateManager.shared.state.stakingBalance(of: .dydx)
.sink { [weak self] dydxAmount in
if let dydxAmount = dydxAmount {
self?.viewModel?.stakedAmount = dydxFormatter.shared.raw(number: Parser.standard.asNumber(dydxAmount), digits: 4)
} else {
self?.viewModel?.stakedAmount = "-"
}
}
.store(in: &subscriptions)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,7 @@ public class dydxProfileRewardsViewPresenter: HostedViewPresenter<dydxProfileRew
super.init()

viewModel = dydxProfileRewardsViewModel()
viewModel?.nativeTokenName = dydxTokenConstants.nativeTokenName
viewModel?.nativeTokenLogoUrl = dydxTokenConstants.nativeTokenLogoUrl
}

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

AbacusStateManager.shared.state.accountBalance(of: .dydx)
.sink { [weak self] dydxAmount in
if let dydxAmount = dydxAmount {
self?.viewModel?.walletAmount = dydxFormatter.shared.raw(number: Parser.standard.asNumber(dydxAmount), digits: 4)
self?.viewModel?.transferAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/transfer", params: ["section": "transferOut"]), animated: true, completion: nil)
}
} else {
self?.viewModel?.walletAmount = "-"
self?.viewModel?.transferAction = nil
}
}
.store(in: &subscriptions)

AbacusStateManager.shared.state.stakingBalance(of: .dydx)
.sink { [weak self] dydxAmount in
if let dydxAmount = dydxAmount {
self?.viewModel?.stakedAmount = dydxFormatter.shared.raw(number: Parser.standard.asNumber(dydxAmount), digits: 4)
} else {
self?.viewModel?.stakedAmount = "-"
}
}
.store(in: &subscriptions)
viewModel?.last7DaysRewardsAmount = "PLACEHOLDER"
viewModel?.allTimeRewardsAmount = "PLACEHOLDER"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ private class dydxProfileViewPresenter: HostedViewPresenter<dydxProfileViewModel
private let historyPresenter: dydxProfileHistoryViewPresenter
private let feesPresenter: dydxProfileFeesViewPresenter
private let rewardsPresenter: dydxProfileRewardsViewPresenter
private let balancesPresenter: dydxProfileBalancesViewPresenter

private lazy var childPresenters: [HostedViewPresenterProtocol] = [
buttonsPresenter,
settingsHelpRowPresenter,
headerPresenter,
historyPresenter,
feesPresenter,
rewardsPresenter
rewardsPresenter,
balancesPresenter
]

override init() {
Expand All @@ -58,6 +60,7 @@ private class dydxProfileViewPresenter: HostedViewPresenter<dydxProfileViewModel
historyPresenter = .init()
feesPresenter = .init()
rewardsPresenter = .init()
balancesPresenter = .init()

super.init()

Expand All @@ -66,6 +69,7 @@ private class dydxProfileViewPresenter: HostedViewPresenter<dydxProfileViewModel
historyPresenter.$viewModel.assign(to: &viewModel.$history)
feesPresenter.$viewModel.assign(to: &viewModel.$fees)
rewardsPresenter.$viewModel.assign(to: &viewModel.$rewards)
balancesPresenter.$viewModel.assign(to: &viewModel.$balances)

attachChildren(workers: childPresenters)
}
Expand Down
Loading
Loading