@@ -2,7 +2,9 @@ import SwiftUI
22
33struct ReceiveEdit : View {
44 @EnvironmentObject private var app : AppViewModel
5+ @EnvironmentObject private var blocktank : BlocktankViewModel
56 @EnvironmentObject private var currency : CurrencyViewModel
7+ @EnvironmentObject private var transfer : TransferViewModel
68 @EnvironmentObject private var wallet : WalletViewModel
79 @Environment ( \. dismiss) private var dismiss
810
@@ -13,6 +15,10 @@ struct ReceiveEdit: View {
1315 @State private var isAmountInputFocused : Bool = false
1416 @FocusState private var isNoteEditorFocused : Bool
1517
18+ var amountSats : UInt64 {
19+ amountViewModel. amountSats
20+ }
21+
1622 var body : some View {
1723 VStack ( spacing: 0 ) {
1824 SheetHeader ( title: t ( " wallet__receive_specify " ) )
@@ -122,10 +128,17 @@ struct ReceiveEdit: View {
122128 // Wait until node is running if it's in starting state
123129 if await wallet. waitForNodeToRun ( ) {
124130 do {
125- wallet. invoiceAmountSats = amountViewModel . amountSats
131+ wallet. invoiceAmountSats = amountSats
126132 wallet. invoiceNote = note
127133 try await wallet. refreshBip21 ( forceRefreshBolt11: true )
128- dismiss ( )
134+
135+ // Check if CJIT flow should be shown
136+ if needsAdditionalCjit ( ) {
137+ let entry = try await blocktank. createCjit ( amountSats: amountSats, description: note)
138+ navigationPath. append ( . cjitConfirm( entry: entry, receiveAmountSats: amountSats, isAdditional: true ) )
139+ } else {
140+ dismiss ( )
141+ }
129142 } catch {
130143 app. toast ( error)
131144 }
@@ -139,6 +152,34 @@ struct ReceiveEdit: View {
139152 }
140153 }
141154
155+ private func needsAdditionalCjit( ) -> Bool {
156+ let isGeoBlocked = app. isGeoBlocked ?? false
157+ let minimumAmount = blocktank. minCjitSats ?? 0
158+ let inboundCapacity = wallet. totalInboundLightningSats ?? 0
159+ let invoiceAmount = amountViewModel. amountSats
160+
161+ // Calculate maxClientBalance using TransferViewModel
162+ let maxChannelSize = blocktank. info? . options. maxChannelSizeSat ?? 0
163+ let maxClientBalance = transfer. getMaxClientBalance ( maxChannelSize: UInt64 ( maxChannelSize) )
164+
165+ if
166+ // user is geo-blocked
167+ isGeoBlocked ||
168+ // failed to get minimum amount
169+ minimumAmount == 0 ||
170+ // amount is less than minimum CJIT amount
171+ invoiceAmount < minimumAmount ||
172+ // there is enough inbound capacity
173+ invoiceAmount <= inboundCapacity ||
174+ // amount is above the maximum client balance
175+ invoiceAmount > maxClientBalance
176+ {
177+ return false
178+ }
179+
180+ return true
181+ }
182+
142183 @ViewBuilder
143184 private var numberPadButtons : some View {
144185 HStack ( alignment: . bottom) {
0 commit comments