@@ -15,6 +15,7 @@ import androidx.compose.material3.HorizontalDivider
1515import androidx.compose.runtime.Composable
1616import androidx.compose.runtime.LaunchedEffect
1717import androidx.compose.runtime.getValue
18+ import androidx.compose.runtime.rememberUpdatedState
1819import androidx.compose.ui.Alignment
1920import androidx.compose.ui.Modifier
2021import androidx.compose.ui.platform.LocalContext
@@ -26,6 +27,7 @@ import androidx.compose.ui.unit.dp
2627import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
2728import androidx.lifecycle.compose.collectAsStateWithLifecycle
2829import to.bitkit.R
30+ import to.bitkit.models.formatToModernDisplay
2931import to.bitkit.repositories.CurrencyState
3032import to.bitkit.ui.LocalCurrencies
3133import to.bitkit.ui.components.ConnectionIssuesView
@@ -47,6 +49,7 @@ import to.bitkit.ui.scaffold.ScreenColumn
4749import to.bitkit.ui.theme.AppThemeSurface
4850import to.bitkit.ui.theme.Colors
4951import to.bitkit.ui.utils.withAccent
52+ import to.bitkit.viewmodels.AmountInputEffect
5053import to.bitkit.viewmodels.AmountInputViewModel
5154import to.bitkit.viewmodels.TransferEffect
5255import to.bitkit.viewmodels.TransferToSpendingUiState
@@ -70,6 +73,7 @@ fun SpendingAmountScreen(
7073 val isNodeRunning by viewModel.isNodeRunning.collectAsStateWithLifecycle()
7174 val amountUiState by amountInputViewModel.uiState.collectAsStateWithLifecycle()
7275 val context = LocalContext .current
76+ val currentMaxAllowedToSend by rememberUpdatedState(uiState.maxAllowedToSend)
7377
7478 LaunchedEffect (isOffline) {
7579 viewModel.updateLimits()
@@ -85,6 +89,18 @@ fun SpendingAmountScreen(
8589 }
8690 }
8791
92+ LaunchedEffect (Unit ) {
93+ amountInputViewModel.effect.collect {
94+ 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+ )
100+ }
101+ }
102+ }
103+
88104 Box {
89105 Content (
90106 isNodeRunning = isNodeRunning,
@@ -99,7 +115,7 @@ fun SpendingAmountScreen(
99115 toast(
100116 context.getString(R .string.lightning__spending_amount__error_max__title),
101117 context.getString(R .string.lightning__spending_amount__error_max__description)
102- .replace(" {amount}" , " $ max" ),
118+ .replace(" {amount}" , max.formatToModernDisplay() ),
103119 )
104120 }
105121 val cappedQuarter = min(quarter, max)
@@ -174,6 +190,10 @@ private fun SpendingAmountNodeRunning(
174190 onClickMaxAmount : () -> Unit ,
175191 onConfirmAmount : () -> Unit ,
176192) {
193+ LaunchedEffect (uiState.maxAllowedToSend) {
194+ amountInputViewModel.setMaxAmount(uiState.maxAllowedToSend)
195+ }
196+
177197 Column (
178198 modifier = Modifier
179199 .padding(horizontal = 16 .dp)
@@ -244,6 +264,7 @@ private fun SpendingAmountNodeRunning(
244264 NumberPad (
245265 viewModel = amountInputViewModel,
246266 currencies = currencies,
267+ enabled = ! uiState.isLoading,
247268 )
248269
249270 PrimaryButton (
0 commit comments