Skip to content

Commit 2ebdb1d

Browse files
committed
fix: wait for node runs before performs node related calls
1 parent 17e054e commit 2ebdb1d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import kotlinx.coroutines.flow.stateIn
2424
import kotlinx.coroutines.flow.update
2525
import kotlinx.coroutines.isActive
2626
import kotlinx.coroutines.launch
27+
import kotlinx.coroutines.withTimeout
28+
import kotlinx.coroutines.withTimeoutOrNull
2729
import org.lightningdevkit.ldknode.ChannelDetails
2830
import to.bitkit.R
2931
import to.bitkit.data.CacheStore
@@ -42,6 +44,7 @@ import javax.inject.Inject
4244
import kotlin.math.max
4345
import kotlin.math.min
4446
import kotlin.math.roundToLong
47+
import kotlin.time.Duration.Companion.minutes
4548
import kotlin.time.Duration.Companion.seconds
4649

4750
const 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

Comments
 (0)