@@ -55,7 +55,6 @@ import to.bitkit.viewmodels.TransferEffect
5555import to.bitkit.viewmodels.TransferToSpendingUiState
5656import to.bitkit.viewmodels.TransferViewModel
5757import to.bitkit.viewmodels.previewAmountInputViewModel
58- import kotlin.math.min
5958
6059@Suppress(" ViewModelForwarding" )
6160@Composable
@@ -74,6 +73,7 @@ fun SpendingAmountScreen(
7473 val amountUiState by amountInputViewModel.uiState.collectAsStateWithLifecycle()
7574 val context = LocalContext .current
7675 val currentMaxAllowedToSend by rememberUpdatedState(uiState.maxAllowedToSend)
76+ val currentCurrencies by rememberUpdatedState(currencies)
7777
7878 LaunchedEffect (isOffline) {
7979 viewModel.updateLimits()
@@ -92,11 +92,14 @@ fun SpendingAmountScreen(
9292 LaunchedEffect (Unit ) {
9393 amountInputViewModel.effect.collect {
9494 when (it) {
95- AmountInputEffect .MaxExceeded -> toast(
96- context.getString(R .string.lightning__spending_amount__error_max__title),
97- context.getString(R .string.lightning__spending_amount__error_max__description)
98- .replace(" {amount}" , currentMaxAllowedToSend.formatToModernDisplay()),
99- )
95+ AmountInputEffect .MaxExceeded -> {
96+ amountInputViewModel.setSats(currentMaxAllowedToSend, currentCurrencies)
97+ toast(
98+ context.getString(R .string.lightning__spending_amount__error_max__title),
99+ context.getString(R .string.lightning__spending_amount__error_max__description)
100+ .replace(" {amount}" , currentMaxAllowedToSend.formatToModernDisplay()),
101+ )
102+ }
100103 }
101104 }
102105 }
@@ -109,23 +112,10 @@ fun SpendingAmountScreen(
109112 currencies = currencies,
110113 onBackClick = onBackClick,
111114 onClickQuarter = {
112- val quarter = uiState.balanceAfterFeeQuarter()
113- val max = uiState.maxAllowedToSend
114- if (quarter > max) {
115- toast(
116- context.getString(R .string.lightning__spending_amount__error_max__title),
117- context.getString(R .string.lightning__spending_amount__error_max__description)
118- .replace(" {amount}" , max.formatToModernDisplay()),
119- )
120- }
121- val cappedQuarter = min(quarter, max)
122- viewModel.updateLimits(cappedQuarter)
123- amountInputViewModel.setSats(cappedQuarter, currencies)
115+ amountInputViewModel.setSats(uiState.quarterAmount, currencies)
124116 },
125117 onClickMaxAmount = {
126- val newAmountSats = uiState.maxAllowedToSend
127- viewModel.updateLimits(newAmountSats)
128- amountInputViewModel.setSats(newAmountSats, currencies)
118+ amountInputViewModel.setSats(uiState.maxAllowedToSend, currencies)
129119 },
130120 onConfirmAmount = { viewModel.onConfirmAmount(amountUiState.sats) },
131121 )
0 commit comments