Skip to content

Commit 191db39

Browse files
committed
refactor: extract hasUsableChannels to WalletViewModel
1 parent b489af0 commit 191db39

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

Bitkit/ViewModels/WalletViewModel.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,10 @@ class WalletViewModel: ObservableObject {
559559
return capacity
560560
}
561561

562+
var hasUsableChannels: Bool {
563+
return channels?.contains(where: \.isChannelReady) ?? false
564+
}
565+
562566
/// Check if there are non-LSP (non-Blocktank) channels available
563567
/// Used for geoblocking to determine if Lightning operations can proceed
564568
func hasNonLspChannels() -> Bool {
@@ -591,8 +595,6 @@ class WalletViewModel: ObservableObject {
591595

592596
let amountSats = invoiceAmountSats > 0 ? invoiceAmountSats : nil
593597

594-
let hasUsableChannels = channels?.contains(where: \.isChannelReady) ?? false
595-
596598
if hasUsableChannels {
597599
if forceRefreshBolt11 || bolt11.isEmpty {
598600
bolt11 = try await createInvoice(amountSats: amountSats, note: invoiceNote)

Bitkit/Views/Wallets/Receive/ReceiveQr.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,9 @@ struct ReceiveQr: View {
4242
}
4343
}
4444

45-
private var hasUsableChannels: Bool {
46-
return wallet.channels?.contains(where: \.isChannelReady) ?? false
47-
}
48-
4945
private var availableTabItems: [TabItem<ReceiveTab>] {
5046
// Only show unified tab if there are usable channels
51-
if hasUsableChannels {
47+
if wallet.hasUsableChannels {
5248
return [
5349
TabItem(.savings),
5450
TabItem(.unified, activeColor: .white),
@@ -63,7 +59,7 @@ struct ReceiveQr: View {
6359
}
6460

6561
var showingCjitOnboarding: Bool {
66-
return !hasUsableChannels && cjitInvoice == nil && selectedTab == .spending
62+
return !wallet.hasUsableChannels && cjitInvoice == nil && selectedTab == .spending
6763
}
6864

6965
var body: some View {
@@ -79,7 +75,7 @@ struct ReceiveQr: View {
7975
TabView(selection: $selectedTab) {
8076
tabContent(for: .savings)
8177

82-
if hasUsableChannels {
78+
if wallet.hasUsableChannels {
8379
tabContent(for: .unified)
8480
}
8581

@@ -100,7 +96,7 @@ struct ReceiveQr: View {
10096
.foregroundColor(.purpleAccent),
10197
isDisabled: wallet.nodeLifecycleState != .running
10298
) {
103-
if GeoService.shared.isGeoBlocked && !hasUsableChannels {
99+
if GeoService.shared.isGeoBlocked && !wallet.hasUsableChannels {
104100
navigationPath.append(.cjitGeoBlocked)
105101
} else {
106102
navigationPath.append(.cjitAmount)

0 commit comments

Comments
 (0)