From 121280aef93587535a83b8fe552eb8ad7a9193d1 Mon Sep 17 00:00:00 2001 From: Chung Tran Date: Tue, 6 Feb 2024 16:34:41 +0700 Subject: [PATCH] feat: add FT for PnL --- .../Services/FeatureFlags/Features.swift | 3 +++ .../ViewModel/DebugMenuViewModel.swift | 3 +++ .../CryptoAccountCellView.swift | 3 ++- .../CryptoAccountsViewModel.swift | 6 ++++-- .../Crypto/Container/CryptoViewModel.swift | 20 ++++++++++--------- .../Main/History/New/HistoryViewModel.swift | 6 ++++-- .../WalletDetail/New/AccountDetailsView.swift | 4 +++- .../ActionsPanel/ActionsPanelView.swift | 12 ++++++----- 8 files changed, 37 insertions(+), 20 deletions(-) diff --git a/p2p_wallet/Common/Services/FeatureFlags/Features.swift b/p2p_wallet/Common/Services/FeatureFlags/Features.swift index 205b66c64..71c884378 100755 --- a/p2p_wallet/Common/Services/FeatureFlags/Features.swift +++ b/p2p_wallet/Common/Services/FeatureFlags/Features.swift @@ -30,4 +30,7 @@ public extension Feature { // Referral program static let referralProgramEnabled = Feature(rawValue: "referral_program_enabled") + + // Referral program + static let pnlEnabled = Feature(rawValue: "pnl_enabled") } diff --git a/p2p_wallet/Scenes/DebugMenu/ViewModel/DebugMenuViewModel.swift b/p2p_wallet/Scenes/DebugMenu/ViewModel/DebugMenuViewModel.swift index bdbd730f8..e88363486 100644 --- a/p2p_wallet/Scenes/DebugMenu/ViewModel/DebugMenuViewModel.swift +++ b/p2p_wallet/Scenes/DebugMenu/ViewModel/DebugMenuViewModel.swift @@ -113,6 +113,7 @@ extension DebugMenuViewModel { case onboardingUsernameButtonSkipEnabled case referralProgramEnabled + case pnlEnabled case investSolend case solendDisablePlaceholder @@ -142,6 +143,7 @@ extension DebugMenuViewModel { case .solanaEthAddressEnabled: return "solana ETH address enabled" case .swapTransactionSimulation: return "Swap transaction simulation" case .referralProgramEnabled: return "Referral program enabled" + case .pnlEnabled: return "PnL Enabled" } } @@ -161,6 +163,7 @@ extension DebugMenuViewModel { case .solanaEthAddressEnabled: return .solanaEthAddressEnabled case .swapTransactionSimulation: return .swapTransactionSimulationEnabled case .referralProgramEnabled: return .referralProgramEnabled + case .pnlEnabled: return .pnlEnabled } } } diff --git a/p2p_wallet/Scenes/Main/Crypto/Components/Crypto Accounts/CryptoAccountCellView.swift b/p2p_wallet/Scenes/Main/Crypto/Components/Crypto Accounts/CryptoAccountCellView.swift index cb986b2a0..e7253ce97 100644 --- a/p2p_wallet/Scenes/Main/Crypto/Components/Crypto Accounts/CryptoAccountCellView.swift +++ b/p2p_wallet/Scenes/Main/Crypto/Components/Crypto Accounts/CryptoAccountCellView.swift @@ -68,7 +68,8 @@ struct CryptoAccountCellView: View, Equatable { @ViewBuilder private var detailView: some View { switch rendable.detail { case let .text(text): - if showPnL, + if available(.pnlEnabled), + showPnL, let solanaAccount = rendable as? RenderableSolanaAccount { VStack(alignment: .trailing, spacing: 4) { diff --git a/p2p_wallet/Scenes/Main/Crypto/Components/Crypto Accounts/CryptoAccountsViewModel.swift b/p2p_wallet/Scenes/Main/Crypto/Components/Crypto Accounts/CryptoAccountsViewModel.swift index f3cef204a..439196c52 100644 --- a/p2p_wallet/Scenes/Main/Crypto/Components/Crypto Accounts/CryptoAccountsViewModel.swift +++ b/p2p_wallet/Scenes/Main/Crypto/Components/Crypto Accounts/CryptoAccountsViewModel.swift @@ -114,8 +114,10 @@ final class CryptoAccountsViewModel: BaseViewModel, ObservableObject { func refresh() async { await HomeAccountsSynchronisationService().refresh() - Task { - await Resolver.resolve(PnLRepository.self).reload() + if available(.pnlEnabled) { + Task { + await Resolver.resolve(PnLRepository.self).reload() + } } } diff --git a/p2p_wallet/Scenes/Main/Crypto/Container/CryptoViewModel.swift b/p2p_wallet/Scenes/Main/Crypto/Container/CryptoViewModel.swift index ff5403b88..715089549 100644 --- a/p2p_wallet/Scenes/Main/Crypto/Container/CryptoViewModel.swift +++ b/p2p_wallet/Scenes/Main/Crypto/Container/CryptoViewModel.swift @@ -200,16 +200,18 @@ private extension CryptoViewModel { .store(in: &subscriptions) // solana account vs pnl, get for the first time - solanaAccountsService.statePublisher - .receive(on: RunLoop.main) - .filter { $0.status == .ready } - .prefix(1) - .sink { _ in - Task { - await Resolver.resolve(PnLRepository.self).reload() + if available(.pnlEnabled) { + solanaAccountsService.statePublisher + .receive(on: RunLoop.main) + .filter { $0.status == .ready } + .prefix(1) + .sink { _ in + Task { + await Resolver.resolve(PnLRepository.self).reload() + } } - } - .store(in: &subscriptions) + .store(in: &subscriptions) + } } } diff --git a/p2p_wallet/Scenes/Main/History/New/HistoryViewModel.swift b/p2p_wallet/Scenes/Main/History/New/HistoryViewModel.swift index 15e32e8a0..6e626ddc5 100644 --- a/p2p_wallet/Scenes/Main/History/New/HistoryViewModel.swift +++ b/p2p_wallet/Scenes/Main/History/New/HistoryViewModel.swift @@ -237,8 +237,10 @@ class HistoryViewModel: BaseViewModel, ObservableObject { func refresh() async throws { try await reload() - Task.detached { - await Resolver.resolve(PnLRepository.self).reload() + if available(.pnlEnabled) { + Task.detached { + await Resolver.resolve(PnLRepository.self).reload() + } } } diff --git a/p2p_wallet/Scenes/Main/WalletDetail/New/AccountDetailsView.swift b/p2p_wallet/Scenes/Main/WalletDetail/New/AccountDetailsView.swift index ecc72167c..440c442d7 100644 --- a/p2p_wallet/Scenes/Main/WalletDetail/New/AccountDetailsView.swift +++ b/p2p_wallet/Scenes/Main/WalletDetail/New/AccountDetailsView.swift @@ -23,7 +23,9 @@ struct AccountDetailsView: View { .apply(style: .text3) .foregroundColor(Color(.night)) - if let account = viewModel.rendableAccountDetails as? RendableNewSolanaAccountDetails { + if available(.pnlEnabled), + let account = viewModel.rendableAccountDetails as? RendableNewSolanaAccountDetails + { RepositoryView( repository: Resolver.resolve(PnLRepository.self) ) { _ in diff --git a/p2p_wallet/UI/SwiftUI/ActionsPanel/ActionsPanelView.swift b/p2p_wallet/UI/SwiftUI/ActionsPanel/ActionsPanelView.swift index 9cf5d69dd..004617f87 100644 --- a/p2p_wallet/UI/SwiftUI/ActionsPanel/ActionsPanelView.swift +++ b/p2p_wallet/UI/SwiftUI/ActionsPanel/ActionsPanelView.swift @@ -17,11 +17,13 @@ struct ActionsPanelView: View { usdAmountView } - pnlView - .onTapGesture { - pnlTapAction?() - } - .padding(.top, usdAmount.isEmpty ? 12 : 0) + if available(.pnlEnabled) { + pnlView + .onTapGesture { + pnlTapAction?() + } + .padding(.top, usdAmount.isEmpty ? 12 : 0) + } actionsView .padding(.top, 36)