Skip to content

Commit

Permalink
Merge pull request #1685 from p2p-org/feature/pwn-876
Browse files Browse the repository at this point in the history
feat: add FT for PnL
  • Loading branch information
lisemyon authored Feb 8, 2024
2 parents 0eabc4a + d9a3e9d commit daab51f
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 20 deletions.
3 changes: 3 additions & 0 deletions p2p_wallet/Common/Services/FeatureFlags/Features.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ extension DebugMenuViewModel {
case onboardingUsernameButtonSkipEnabled

case referralProgramEnabled
case pnlEnabled

case investSolend
case solendDisablePlaceholder
Expand Down Expand Up @@ -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"
}
}

Expand All @@ -161,6 +163,7 @@ extension DebugMenuViewModel {
case .solanaEthAddressEnabled: return .solanaEthAddressEnabled
case .swapTransactionSimulation: return .swapTransactionSimulationEnabled
case .referralProgramEnabled: return .referralProgramEnabled
case .pnlEnabled: return .pnlEnabled
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand Down
20 changes: 11 additions & 9 deletions p2p_wallet/Scenes/Main/Crypto/Container/CryptoViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions p2p_wallet/Scenes/Main/History/New/HistoryViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions p2p_wallet/UI/SwiftUI/ActionsPanel/ActionsPanelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit daab51f

Please sign in to comment.