@@ -24,6 +24,8 @@ import kotlinx.coroutines.flow.stateIn
2424import kotlinx.coroutines.flow.update
2525import kotlinx.coroutines.isActive
2626import kotlinx.coroutines.launch
27+ import kotlinx.coroutines.withTimeout
28+ import kotlinx.coroutines.withTimeoutOrNull
2729import org.lightningdevkit.ldknode.ChannelDetails
2830import to.bitkit.R
2931import to.bitkit.data.CacheStore
@@ -42,6 +44,7 @@ import javax.inject.Inject
4244import kotlin.math.max
4345import kotlin.math.min
4446import kotlin.math.roundToLong
47+ import kotlin.time.Duration.Companion.minutes
4548import kotlin.time.Duration.Companion.seconds
4649
4750const val RETRY_INTERVAL_MS = 1 * 60 * 1000L // 1 minutes in ms
@@ -141,7 +144,11 @@ class TransferViewModel @Inject constructor(
141144 _spendingUiState .update { it.copy(overrideSats = minAmount, isLoading = false ) }
142145 return @launch
143146 }
144- // TODO Collect isNodeRunning here
147+
148+ withTimeoutOrNull(1 .minutes) {
149+ isNodeRunning.first { it }
150+ }
151+
145152 blocktankRepo.createOrder(_spendingUiState .value.satsAmount.toULong())
146153 .onSuccess { order ->
147154 settingsStore.update { it.copy(lightningSetupStep = 0 ) }
@@ -271,6 +278,10 @@ class TransferViewModel @Inject constructor(
271278 // Get the max available balance discounting onChain fee
272279 val availableAmount = walletRepo.getMaxSendAmount()
273280
281+ withTimeoutOrNull(1 .minutes) {
282+ isNodeRunning.first { it }
283+ }
284+
274285 // Calculate the LSP fee to the total balance
275286 blocktankRepo.estimateOrderFee(
276287 spendingBalanceSats = availableAmount,
0 commit comments