Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/java/to/bitkit/repositories/BlocktankRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ class BlocktankRepo @Inject constructor(
companion object {
private const val TAG = "BlocktankRepo"
private const val REFUND_ADDRESS_ALLOCATION_LIMIT = 20

private const val DEFAULT_CHANNEL_EXPIRY_WEEKS = 6u
private const val DEFAULT_SOURCE = "bitkit-android"
private const val PEER_CONNECTION_DELAY_MS = 2_000L
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/to/bitkit/ui/ContentView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ private fun RootNavHost(
viewModel = transferViewModel,
isOffline = connectivityState != ConnectivityState.CONNECTED,
onBackClick = { navController.popBackStack() },
onOrderCreated = { navController.navigateTo(Routes.SpendingConfirm) },
onQuoteReady = { navController.navigateTo(Routes.SpendingConfirm) },
toastException = { appViewModel.toast(it) },
toast = { title, description ->
appViewModel.toast(
Expand All @@ -945,7 +945,7 @@ private fun RootNavHost(
viewModel = transferViewModel,
isOffline = connectivityState != ConnectivityState.CONNECTED,
onBackClick = { navController.popBackStack() },
onOrderCreated = { navController.navigateTo(Routes.SpendingHwSign(walletId)) },
onQuoteReady = { navController.navigateTo(Routes.SpendingHwSign(walletId)) },
)
}
composableWithDefaultTransitions<Routes.SpendingHwSign> { entry ->
Expand Down Expand Up @@ -981,8 +981,7 @@ private fun RootNavHost(
SpendingAdvancedScreen(
viewModel = transferViewModel,
onBackClick = { navController.popBackStack() },
// Pops back to whoever opened Advanced: SpendingConfirm or SpendingHwSign.
onOrderCreated = { navController.popBackStack() },
onQuoteReady = { navController.popBackStack() },
)
}
deepLinkableComposable<Routes.TransferLiquidity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ fun LiquidityScreen(
) {
val transfer = transferViewModel ?: return
val state by transfer.spendingUiState.collectAsStateWithLifecycle()
val order = state.order ?: return
if (state.feeSat == 0uL) return

val channelSize = (order.clientBalanceSat + order.lspBalanceSat).toLong()
val localBalance = order.clientBalanceSat.toLong()
val remoteBalance = order.lspBalanceSat.toLong()
val channelSize = (state.clientBalanceSat + state.lspBalanceSat).toLong()
val localBalance = state.clientBalanceSat.toLong()
val remoteBalance = state.lspBalanceSat.toLong()

LiquidityScreen(
channelSize = channelSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import to.bitkit.R
import to.bitkit.ext.mockOrder
import to.bitkit.models.Toast
import to.bitkit.models.formatToModernDisplay
import to.bitkit.repositories.CurrencyState
Expand Down Expand Up @@ -61,24 +60,24 @@ import to.bitkit.viewmodels.previewAmountInputViewModel
fun SpendingAdvancedScreen(
viewModel: TransferViewModel,
onBackClick: () -> Unit = {},
onOrderCreated: () -> Unit = {},
onQuoteReady: () -> Unit = {},
currencies: CurrencyState = LocalCurrencies.current,
amountInputViewModel: AmountInputViewModel = hiltViewModel(),
) {
val currentOnOrderCreated by rememberUpdatedState(onOrderCreated)
val currentOnQuoteReady by rememberUpdatedState(onQuoteReady)
val app = appViewModel ?: return
val context = LocalContext.current
val state by viewModel.spendingUiState.collectAsStateWithLifecycle()
val order = state.order ?: return
if (state.feeSat == 0uL) return
val amountUiState by amountInputViewModel.uiState.collectAsStateWithLifecycle()
var isLoading by remember { mutableStateOf(false) }

val transferValues by viewModel.transferValues.collectAsStateWithLifecycle()
val currentMaxLspBalance by rememberUpdatedState(transferValues.maxLspBalance)
val currentCurrencies by rememberUpdatedState(currencies)

LaunchedEffect(order.clientBalanceSat) {
viewModel.updateAdvancedTransferValues(order)
LaunchedEffect(state.clientBalanceSat) {
viewModel.updateAdvancedTransferValues(state.clientBalanceSat)
}

LaunchedEffect(amountUiState.sats) {
Expand All @@ -96,7 +95,7 @@ fun SpendingAdvancedScreen(
LaunchedEffect(Unit) {
viewModel.transferEffects.collect { effect ->
when (effect) {
TransferEffect.OnOrderCreated -> currentOnOrderCreated()
TransferEffect.OnQuoteReady -> currentOnQuoteReady()
is TransferEffect.ToastException -> {
isLoading = false
app.toast(effect.e)
Expand Down Expand Up @@ -137,7 +136,7 @@ fun SpendingAdvancedScreen(
val amount = amountUiState.sats.toULong()
amount > 0u && it.maxLspBalance > 0u && amount in it.minLspBalance..it.maxLspBalance
}
val isValid = isInRange && state.canAfford(order.clientBalanceSat)
val isValid = isInRange && state.canAfford(state.clientBalanceSat)

Content(
uiState = state,
Expand Down Expand Up @@ -169,11 +168,6 @@ private fun AmountInputViewModel.applyMaxLspBalance(
}
}

/**
* The max is settled on an affordable capacity before it is offered, so the quote for the typed
* amount only has to catch what moves after that. Until it lands the confirm step is the authority,
* so continue is left enabled.
*/
private fun TransferToSpendingUiState.canAfford(clientBalanceSat: ULong): Boolean {
val budget = fundingBudgetSats ?: return true
val fee = feeEstimate ?: return true
Expand Down Expand Up @@ -300,7 +294,7 @@ private fun Preview() {
AppThemeSurface {
Content(
uiState = TransferToSpendingUiState(
order = mockOrder().copy(clientBalanceSat = 100_000u),
clientBalanceSat = 100_000uL,
receivingAmount = 55_000L,
feeEstimate = 2_500L,
),
Expand All @@ -324,7 +318,7 @@ private fun PreviewLoading() {
AppThemeSurface {
Content(
uiState = TransferToSpendingUiState(
order = mockOrder().copy(clientBalanceSat = 50_000u),
clientBalanceSat = 50_000uL,
receivingAmount = 20_000L,
feeEstimate = null,
isLoading = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fun SpendingAmountScreen(
viewModel: TransferViewModel,
isOffline: Boolean,
onBackClick: () -> Unit = {},
onOrderCreated: () -> Unit = {},
onQuoteReady: () -> Unit = {},
toastException: (Throwable) -> Unit,
toast: (title: String, description: String) -> Unit,
currencies: CurrencyState = LocalCurrencies.current,
Expand All @@ -82,7 +82,7 @@ fun SpendingAmountScreen(
LaunchedEffect(Unit) {
viewModel.transferEffects.collect { effect ->
when (effect) {
TransferEffect.OnOrderCreated -> onOrderCreated()
TransferEffect.OnQuoteReady -> onQuoteReady()
is TransferEffect.ToastError -> toast(effect.title, effect.description)
is TransferEffect.ToastException -> toastException(effect.e)
else -> Unit
Expand Down
Loading