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

feat: add FT for PnL #1685

Merged
merged 3 commits into from
Feb 8, 2024
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ final class CryptoCoordinator: Coordinator<CryptoResult> {
showPnLInfo()
}())
.eraseToAnyPublisher()

default:
return Just(())
.eraseToAnyPublisher()
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
Loading