@@ -3,13 +3,11 @@ package to.bitkit.ui.screens.wallets.send
33import androidx.compose.foundation.layout.BoxWithConstraints
44import androidx.compose.foundation.layout.Column
55import androidx.compose.foundation.layout.Row
6- import androidx.compose.foundation.layout.Spacer
76import androidx.compose.foundation.layout.fillMaxSize
87import androidx.compose.foundation.layout.fillMaxWidth
98import androidx.compose.foundation.layout.height
109import androidx.compose.foundation.layout.navigationBarsPadding
1110import androidx.compose.foundation.layout.padding
12- import androidx.compose.foundation.layout.sizeIn
1311import androidx.compose.material3.HorizontalDivider
1412import androidx.compose.runtime.Composable
1513import androidx.compose.runtime.getValue
@@ -69,6 +67,7 @@ import to.bitkit.viewmodels.SendUiState
6967fun SendAmountScreen (
7068 uiState : SendUiState ,
7169 walletUiState : MainUiState ,
70+ canGoBack : Boolean ,
7271 currencyUiState : CurrencyUiState = LocalCurrencies .current,
7372 onBack : () -> Unit ,
7473 onEvent : (SendEvent ) -> Unit ,
@@ -101,8 +100,10 @@ fun SendAmountScreen(
101100 displayUnit = currencyUiState.displayUnit,
102101 onInputChanged = { input = it },
103102 onEvent = onEvent,
103+ canGoBack = canGoBack,
104104 onBack = onBack,
105105 onClickMax = { maxSats ->
106+ // TODO port the RN sendMax logic if still needed
106107 if (uiState.payMethod == SendMethod .LIGHTNING && uiState.lnurl == null ) {
107108 app?.toast(
108109 type = Toast .ToastType .WARNING ,
@@ -112,6 +113,7 @@ fun SendAmountScreen(
112113 }
113114 overrideSats = maxSats
114115 },
116+ onClickAmount = { currencyVM.togglePrimaryDisplay() },
115117 )
116118}
117119
@@ -127,8 +129,10 @@ fun SendAmountContent(
127129 currencyUiState : CurrencyUiState ,
128130 onInputChanged : (String ) -> Unit ,
129131 onEvent : (SendEvent ) -> Unit ,
132+ canGoBack : Boolean = true,
130133 onBack : () -> Unit ,
131134 onClickMax : (Long ) -> Unit = {},
135+ onClickAmount : () -> Unit = {},
132136) {
133137 Column (
134138 modifier = modifier
@@ -143,10 +147,13 @@ fun SendAmountContent(
143147 else -> R .string.wallet__send_amount
144148 }
145149
146- SheetTopBar (stringResource(titleRes)) {
147- onEvent(SendEvent .AmountReset )
148- onBack()
149- }
150+ SheetTopBar (
151+ titleText = stringResource(titleRes),
152+ onBack = {
153+ onEvent(SendEvent .AmountReset )
154+ onBack()
155+ }.takeIf { canGoBack },
156+ )
150157
151158 when (walletUiState.nodeLifecycleState) {
152159 is NodeLifecycleState .Running -> {
@@ -160,6 +167,7 @@ fun SendAmountContent(
160167 primaryDisplay = primaryDisplay,
161168 onEvent = onEvent,
162169 onClickMax = onClickMax,
170+ onClickAmount = onClickAmount,
163171 )
164172 }
165173
@@ -186,6 +194,7 @@ private fun SendAmountNodeRunning(
186194 onInputChanged : (String ) -> Unit ,
187195 onEvent : (SendEvent ) -> Unit ,
188196 onClickMax : (Long ) -> Unit ,
197+ onClickAmount : () -> Unit ,
189198) {
190199 BoxWithConstraints {
191200 val maxHeight = this .maxHeight
@@ -200,14 +209,15 @@ private fun SendAmountNodeRunning(
200209 Column (
201210 modifier = Modifier .padding(horizontal = 16 .dp)
202211 ) {
203- Spacer ( Modifier .height( 16 .dp) )
212+ VerticalSpacer ( 16 .dp)
204213
205214 NumberPadTextField (
206215 input = input,
207216 displayUnit = displayUnit,
208217 primaryDisplay = primaryDisplay,
209218 modifier = Modifier
210219 .fillMaxWidth()
220+ .clickableAlpha(onClick = onClickAmount)
211221 .testTag(" SendNumberField" )
212222 )
213223
@@ -226,10 +236,7 @@ private fun SendAmountNodeRunning(
226236 ) {
227237 Column (
228238 modifier = Modifier
229- .clickableAlpha {
230- // TODO port the RN sendMax logic
231- onClickMax(availableAmount)
232- }
239+ .clickableAlpha { onClickMax(availableAmount) }
233240 .testTag(" AvailableAmount" )
234241 ) {
235242 Text13Up (
@@ -284,12 +291,6 @@ private fun SendAmountNodeRunning(
284291 .testTag(" SendAmountNumberPad" )
285292 )
286293
287- Spacer (
288- modifier = Modifier
289- .weight(1f )
290- .sizeIn(minHeight = 16 .dp, maxHeight = 41 .dp)
291- )
292-
293294 PrimaryButton (
294295 text = stringResource(R .string.common__continue),
295296 enabled = uiState.isAmountInputValid,
@@ -330,23 +331,23 @@ private fun PaymentMethodButton(
330331 )
331332}
332333
333- @Preview(showSystemUi = true , name = " Running - Lightning " )
334+ @Preview(showSystemUi = true )
334335@Composable
335- private fun PreviewRunningLightning () {
336+ private fun PreviewLightningNoAmount () {
336337 AppThemeSurface {
337338 BottomSheetPreview {
338339 SendAmountContent (
339340 uiState = SendUiState (
340341 payMethod = SendMethod .LIGHTNING ,
341- amountInput = " 100 " ,
342- isAmountInputValid = true ,
342+ amountInput = " 0 " ,
343+ isAmountInputValid = false ,
343344 isUnified = false
344345 ),
345346 balances = BalanceState (totalSats = 150u , totalOnchainSats = 50u , maxSendLightningSats = 100u ),
346347 walletUiState = MainUiState (nodeLifecycleState = NodeLifecycleState .Running ),
347348 onBack = {},
348349 onEvent = {},
349- input = " 100 " ,
350+ input = " 0 " ,
350351 displayUnit = BitcoinDisplayUnit .MODERN ,
351352 primaryDisplay = PrimaryDisplay .FIAT ,
352353 currencyUiState = CurrencyUiState (),
@@ -357,9 +358,9 @@ private fun PreviewRunningLightning() {
357358 }
358359}
359360
360- @Preview(showSystemUi = true , name = " Running - Unified " )
361+ @Preview(showSystemUi = true )
361362@Composable
362- private fun PreviewRunningUnified () {
363+ private fun PreviewUnified () {
363364 AppThemeSurface {
364365 BottomSheetPreview {
365366 SendAmountContent (
@@ -384,9 +385,9 @@ private fun PreviewRunningUnified() {
384385 }
385386}
386387
387- @Preview(showSystemUi = true , name = " Running - Onchain " )
388+ @Preview(showSystemUi = true )
388389@Composable
389- private fun PreviewRunningOnchain () {
390+ private fun PreviewOnchain () {
390391 AppThemeSurface {
391392 BottomSheetPreview {
392393 SendAmountContent (
@@ -411,15 +412,14 @@ private fun PreviewRunningOnchain() {
411412 }
412413}
413414
414- @Preview(showSystemUi = true , name = " Initializing " )
415+ @Preview(showSystemUi = true )
415416@Composable
416417private fun PreviewInitializing () {
417418 AppThemeSurface {
418419 BottomSheetPreview {
419420 SendAmountContent (
420421 uiState = SendUiState (
421422 payMethod = SendMethod .LIGHTNING ,
422- amountInput = " 100"
423423 ),
424424 walletUiState = MainUiState (nodeLifecycleState = NodeLifecycleState .Initializing ),
425425 balances = BalanceState (totalSats = 150u , totalOnchainSats = 50u , maxSendLightningSats = 100u ),
@@ -509,7 +509,7 @@ private fun PreviewLnurlPay() {
509509 }
510510}
511511
512- @Preview(showSystemUi = true , name = " Running - Short screen " , device = NEXUS_5 )
512+ @Preview(showSystemUi = true , device = NEXUS_5 )
513513@Composable
514514private fun PreviewSmallScreen () {
515515 AppThemeSurface {
@@ -519,7 +519,6 @@ private fun PreviewSmallScreen() {
519519 payMethod = SendMethod .LIGHTNING ,
520520 amountInput = " 100" ,
521521 isAmountInputValid = true ,
522- isUnified = false
523522 ),
524523 balances = BalanceState (totalSats = 150u , totalOnchainSats = 50u , maxSendLightningSats = 100u ),
525524 walletUiState = MainUiState (nodeLifecycleState = NodeLifecycleState .Running ),
0 commit comments