@@ -34,6 +34,7 @@ import to.bitkit.ui.components.MoneySSB
3434import to.bitkit.ui.components.NumberPadActionButton
3535import to.bitkit.ui.components.NumberPadTextField
3636import to.bitkit.ui.components.PrimaryButton
37+ import to.bitkit.ui.components.SyncNodeView
3738import to.bitkit.ui.components.Text13Up
3839import to.bitkit.ui.components.UnitButton
3940import to.bitkit.ui.components.VerticalSpacer
@@ -59,9 +60,10 @@ fun SpendingAmountScreen(
5960) {
6061 val currencies = LocalCurrencies .current
6162 val uiState by viewModel.spendingUiState.collectAsStateWithLifecycle()
63+ val isNodeRunning by viewModel.isNodeRunning.collectAsStateWithLifecycle()
6264
6365 LaunchedEffect (Unit ) {
64- viewModel.updateLimits(retry = true )
66+ viewModel.updateLimits()
6567 }
6668
6769 LaunchedEffect (Unit ) {
@@ -86,6 +88,7 @@ fun SpendingAmountScreen(
8688 )
8789
8890 Content (
91+ isNodeRunning = isNodeRunning,
8992 uiState = uiState,
9093 currencies = currencies,
9194 onBackClick = onBackClick,
@@ -99,6 +102,7 @@ fun SpendingAmountScreen(
99102
100103@Composable
101104private fun Content (
105+ isNodeRunning : Boolean ,
102106 uiState : TransferToSpendingUiState ,
103107 currencies : CurrencyUiState ,
104108 onBackClick : () -> Unit ,
@@ -114,92 +118,123 @@ private fun Content(
114118 onBackClick = onBackClick,
115119 actions = { CloseNavIcon (onCloseClick) },
116120 )
117- Column (
118- modifier = Modifier
119- .padding(horizontal = 16 .dp)
120- .fillMaxSize()
121- .imePadding()
122- .testTag(" SpendingAmount" )
123- ) {
124- VerticalSpacer (16 .dp)
125- Display (
126- text = stringResource(R .string.lightning__spending_amount__title)
127- .withAccent(accentColor = Colors .Purple )
128- )
129121
130- NumberPadTextField (
131- input = uiState.input,
132- displayUnit = currencies.displayUnit,
133- showSecondaryField = false ,
134- primaryDisplay = currencies.primaryDisplay,
122+ if (isNodeRunning) {
123+ SpendingAmountNodeRunning (
124+ uiState = uiState,
125+ currencies = currencies,
126+ onClickQuarter = onClickQuarter,
127+ onClickMaxAmount = onClickMaxAmount,
128+ onConfirmAmount = onConfirmAmount,
129+ onInputChange = onInputChange,
130+ )
131+ } else {
132+ SyncNodeView (
135133 modifier = Modifier
136134 .fillMaxWidth()
137- .testTag( " SpendingAmountNumberField " )
135+ .weight( 1f )
138136 )
137+ }
138+ }
139+ }
139140
140- FillHeight ()
141+ @Composable
142+ private fun SpendingAmountNodeRunning (
143+ uiState : TransferToSpendingUiState ,
144+ currencies : CurrencyUiState ,
145+ onClickQuarter : () -> Unit ,
146+ onClickMaxAmount : () -> Unit ,
147+ onConfirmAmount : () -> Unit ,
148+ onInputChange : (String ) -> Unit ,
149+ ) {
150+ Column (
151+ modifier = Modifier
152+ .padding(horizontal = 16 .dp)
153+ .fillMaxSize()
154+ .imePadding()
155+ .testTag(" SpendingAmount" )
156+ ) {
157+ VerticalSpacer (minHeight = 16 .dp, maxHeight = 32 .dp)
141158
142- Row (
143- verticalAlignment = Alignment . Bottom ,
144- horizontalArrangement = Arrangement .spacedBy( 8 .dp),
145- modifier = Modifier
146- .padding(vertical = 8 .dp)
147- .testTag( " SendAmountNumberPad " )
148- ) {
149- Column {
150- Text13Up (
151- text = stringResource( R .string.wallet__send_available) ,
152- color = Colors . White64 ,
153- modifier = Modifier .testTag( " SpendingAmountAvailable " )
154- )
155- Spacer (modifier = Modifier .height( 8 .dp) )
156- MoneySSB (sats = uiState.balanceAfterFee, modifier = Modifier . testTag(" SpendingAmountUnit " ) )
157- }
158- FillWidth ()
159- UnitButton (color = Colors . Purple )
160- // 25% Button
161- NumberPadActionButton (
162- text = stringResource( R .string.lightning__spending_amount__quarter) ,
163- color = Colors . Purple ,
164- onClick = onClickQuarter,
165- modifier = Modifier .testTag( " SpendingAmountQuarter " )
166- )
167- // Max Button
168- NumberPadActionButton (
169- text = stringResource( R .string.common__max),
170- color = Colors . Purple ,
171- onClick = onClickMaxAmount ,
172- modifier = Modifier .testTag(" SpendingAmountMax " )
159+ Display (
160+ text = stringResource( R .string.lightning__spending_amount__title)
161+ .withAccent(accentColor = Colors . Purple )
162+ )
163+
164+ FillHeight ( )
165+
166+ NumberPadTextField (
167+ input = uiState.input,
168+ displayUnit = currencies.displayUnit ,
169+ showSecondaryField = false ,
170+ primaryDisplay = currencies.primaryDisplay,
171+ modifier = Modifier
172+ .fillMaxWidth( )
173+ . testTag(" SpendingAmountNumberField " )
174+ )
175+
176+ FillHeight ( )
177+
178+ Row (
179+ verticalAlignment = Alignment . Bottom ,
180+ horizontalArrangement = Arrangement .spacedBy( 8 .dp) ,
181+ modifier = Modifier
182+ .padding(vertical = 8 .dp )
183+ .testTag( " SendAmountNumberPad " )
184+ ) {
185+ Column {
186+ Text13Up (
187+ text = stringResource( R .string.wallet__send_available) ,
188+ color = Colors . White64 ,
189+ modifier = Modifier .testTag(" SpendingAmountAvailable " )
173190 )
191+ Spacer (modifier = Modifier .height(8 .dp))
192+ MoneySSB (sats = uiState.balanceAfterFee, modifier = Modifier .testTag(" SpendingAmountUnit" ))
174193 }
175- HorizontalDivider ()
176-
177- VerticalSpacer (16 .dp)
178-
179- Keyboard (
180- onClick = { number ->
181- onInputChange(if (uiState.input == " 0" ) number else uiState.input + number)
182- },
183- onClickBackspace = {
184- onInputChange(if (uiState.input.length > 1 ) uiState.input.dropLast(1 ) else " 0" )
185- },
186- isDecimal = currencies.primaryDisplay == PrimaryDisplay .FIAT ,
187- modifier = Modifier
188- .fillMaxWidth()
194+ FillWidth ()
195+ UnitButton (color = Colors .Purple )
196+ // 25% Button
197+ NumberPadActionButton (
198+ text = stringResource(R .string.lightning__spending_amount__quarter),
199+ color = Colors .Purple ,
200+ onClick = onClickQuarter,
201+ modifier = Modifier .testTag(" SpendingAmountQuarter" )
202+ )
203+ // Max Button
204+ NumberPadActionButton (
205+ text = stringResource(R .string.common__max),
206+ color = Colors .Purple ,
207+ onClick = onClickMaxAmount,
208+ modifier = Modifier .testTag(" SpendingAmountMax" )
189209 )
210+ }
211+ HorizontalDivider ()
190212
191- VerticalSpacer (8 .dp)
213+ VerticalSpacer (16 .dp)
192214
193- PrimaryButton (
194- text = stringResource(R .string.common__continue),
195- onClick = onConfirmAmount,
196- enabled = uiState.satsAmount != 0L && uiState.satsAmount <= uiState.maxAllowedToSend,
197- isLoading = uiState.isLoading,
198- modifier = Modifier .testTag(" SpendingAmountContinue" )
199- )
215+ Keyboard (
216+ onClick = { number ->
217+ onInputChange(if (uiState.input == " 0" ) number else uiState.input + number)
218+ },
219+ onClickBackspace = {
220+ onInputChange(if (uiState.input.length > 1 ) uiState.input.dropLast(1 ) else " 0" )
221+ },
222+ isDecimal = currencies.primaryDisplay == PrimaryDisplay .FIAT ,
223+ modifier = Modifier
224+ .fillMaxWidth()
225+ )
200226
201- VerticalSpacer (16 .dp)
202- }
227+ VerticalSpacer (8 .dp)
228+
229+ PrimaryButton (
230+ text = stringResource(R .string.common__continue),
231+ onClick = onConfirmAmount,
232+ enabled = uiState.satsAmount != 0L && uiState.satsAmount <= uiState.maxAllowedToSend,
233+ isLoading = uiState.isLoading,
234+ modifier = Modifier .testTag(" SpendingAmountContinue" )
235+ )
236+
237+ VerticalSpacer (16 .dp)
203238 }
204239}
205240
@@ -208,6 +243,7 @@ private fun Content(
208243private fun Preview () {
209244 AppThemeSurface {
210245 Content (
246+ isNodeRunning = true ,
211247 uiState = TransferToSpendingUiState (input = " 5 000" ),
212248 currencies = CurrencyUiState (),
213249 onBackClick = {},
@@ -225,6 +261,25 @@ private fun Preview() {
225261private fun Preview2 () {
226262 AppThemeSurface {
227263 Content (
264+ isNodeRunning = true ,
265+ uiState = TransferToSpendingUiState (input = " 5 000" ),
266+ currencies = CurrencyUiState (),
267+ onBackClick = {},
268+ onCloseClick = {},
269+ onClickQuarter = {},
270+ onClickMaxAmount = {},
271+ onConfirmAmount = {},
272+ onInputChange = {},
273+ )
274+ }
275+ }
276+
277+ @Preview(showBackground = true , device = NEXUS_5 )
278+ @Composable
279+ private fun Preview3 () {
280+ AppThemeSurface {
281+ Content (
282+ isNodeRunning = false ,
228283 uiState = TransferToSpendingUiState (input = " 5 000" ),
229284 currencies = CurrencyUiState (),
230285 onBackClick = {},
0 commit comments