Skip to content

Commit 578d07a

Browse files
committed
refactor: remove unnecessary retry logic
1 parent 2ebdb1d commit 578d07a

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

app/src/main/java/to/bitkit/ui/screens/transfer/SpendingAmountScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fun SpendingAmountScreen(
6363
val isNodeRunning by viewModel.isNodeRunning.collectAsStateWithLifecycle()
6464

6565
LaunchedEffect(Unit) {
66-
viewModel.updateLimits(retry = true)
66+
viewModel.updateLimits()
6767
}
6868

6969
LaunchedEffect(Unit) {

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

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ 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
2827
import kotlinx.coroutines.withTimeoutOrNull
2928
import org.lightningdevkit.ldknode.ChannelDetails
3029
import to.bitkit.R
@@ -78,7 +77,6 @@ class TransferViewModel @Inject constructor(
7877

7978
val transferEffects = MutableSharedFlow<TransferEffect>()
8079
fun setTransferEffect(effect: TransferEffect) = viewModelScope.launch { transferEffects.emit(effect) }
81-
var retryTimes = 0
8280
var maxLspFee = 0uL
8381

8482
// region Spending
@@ -90,7 +88,7 @@ class TransferViewModel @Inject constructor(
9088
overrideSats = it.maxAllowedToSend,
9189
)
9290
}
93-
updateLimits(false)
91+
updateLimits()
9492
}
9593

9694
fun onClickQuarter() {
@@ -113,7 +111,7 @@ class TransferViewModel @Inject constructor(
113111
overrideSats = min(quarter, it.maxAllowedToSend),
114112
)
115113
}
116-
updateLimits(false)
114+
updateLimits()
117115
}
118116

119117
fun onConfirmAmount() {
@@ -183,13 +181,12 @@ class TransferViewModel @Inject constructor(
183181

184182
_spendingUiState.update { it.copy(satsAmount = sats, overrideSats = null) }
185183

186-
retryTimes = 0
187-
updateLimits(retry = false)
184+
updateLimits()
188185
}
189186

190-
fun updateLimits(retry: Boolean) {
187+
fun updateLimits() {
191188
updateTransferValues(_spendingUiState.value.satsAmount.toULong())
192-
updateAvailableAmount(retry = retry)
189+
updateAvailableAmount()
193190
}
194191

195192
fun onAdvancedOrderCreated(order: IBtOrder) {
@@ -271,7 +268,7 @@ class TransferViewModel @Inject constructor(
271268
setTransferEffect(TransferEffect.OnOrderCreated)
272269
}
273270

274-
private fun updateAvailableAmount(retry: Boolean) {
271+
private fun updateAvailableAmount() {
275272
viewModelScope.launch {
276273
_spendingUiState.update { it.copy(isLoading = true) }
277274

@@ -287,7 +284,6 @@ class TransferViewModel @Inject constructor(
287284
spendingBalanceSats = availableAmount,
288285
receivingBalanceSats = _transferValues.value.maxLspBalance
289286
).onSuccess { estimate ->
290-
retryTimes = 0
291287
maxLspFee = estimate.feeSat
292288

293289
// Calculate the available balance to send after LSP fee
@@ -305,17 +301,9 @@ class TransferViewModel @Inject constructor(
305301
)
306302
}
307303
}.onFailure { exception ->
308-
if (exception is ServiceError.NodeNotStarted && retry) {
309-
// Retry after delay
310-
Logger.warn("Error getting the available amount. Node not started. trying again in 2 seconds")
311-
delay(2.seconds)
312-
updateAvailableAmount(retry = retryTimes <= RETRY_LIMIT)
313-
retryTimes++
314-
} else {
315-
_spendingUiState.update { it.copy(isLoading = false) }
316-
Logger.error("Failure", exception)
317-
setTransferEffect(TransferEffect.ToastException(exception))
318-
}
304+
_spendingUiState.update { it.copy(isLoading = false) }
305+
Logger.error("Failure", exception)
306+
setTransferEffect(TransferEffect.ToastException(exception))
319307
}
320308
}
321309
}

0 commit comments

Comments
 (0)