@@ -22,7 +22,7 @@ import androidx.compose.ui.tooling.preview.Preview
2222import androidx.compose.ui.unit.dp
2323import okhttp3.internal.toLongOrDefault
2424import to.bitkit.R
25- import to.bitkit.ext.removeSpaces
25+ import to.bitkit.models.BalanceState
2626import to.bitkit.models.BitcoinDisplayUnit
2727import to.bitkit.models.NodeLifecycleState
2828import to.bitkit.models.PrimaryDisplay
@@ -69,6 +69,30 @@ fun SendAmountScreen(
6969 currencyVM = currencyVM
7070 )
7171
72+ SendAmountContent (
73+ input = input,
74+ uiState = uiState,
75+ walletUiState = walletUiState,
76+ currencyUiState = currencyUiState,
77+ onInputChanged = { input = it },
78+ onEvent = onEvent,
79+ onBack = onBack
80+ )
81+
82+
83+ }
84+
85+ @Composable
86+ private fun SendAmountContent (
87+ input : String ,
88+ walletUiState : MainUiState ,
89+ uiState : SendUiState ,
90+ balances : BalanceState = LocalBalances .current,
91+ currencyUiState : CurrencyUiState ,
92+ onInputChanged : (String ) -> Unit ,
93+ onEvent : (SendEvent ) -> Unit ,
94+ onBack : () -> Unit ,
95+ ) {
7296 Column (
7397 modifier = Modifier
7498 .fillMaxSize()
@@ -81,14 +105,16 @@ fun SendAmountScreen(
81105
82106 when (walletUiState.nodeLifecycleState) {
83107 is NodeLifecycleState .Running -> {
84- SendAmountContent (
108+ SendAmountNodeRunning (
85109 input = input,
86110 uiState = uiState,
87111 currencyUiState = currencyUiState,
88- onInputChanged = { input = it },
112+ onInputChanged = onInputChanged,
113+ balances = balances,
89114 onEvent = onEvent
90115 )
91116 }
117+
92118 else -> {
93119 SyncNodeView (
94120 modifier = Modifier
@@ -101,14 +127,14 @@ fun SendAmountScreen(
101127}
102128
103129@Composable
104- private fun SendAmountContent (
130+ private fun SendAmountNodeRunning (
105131 input : String ,
106132 uiState : SendUiState ,
133+ balances : BalanceState ,
107134 currencyUiState : CurrencyUiState ,
108135 onInputChanged : (String ) -> Unit ,
109136 onEvent : (SendEvent ) -> Unit ,
110137) {
111- val balances = LocalBalances .current
112138 val availableAmount = when (uiState.payMethod) {
113139 SendMethod .ONCHAIN -> balances.totalOnchainSats.toLong()
114140 SendMethod .LIGHTNING -> balances.totalLightningSats.toLong()
@@ -204,24 +230,28 @@ private fun AmountInputHandler(
204230 currencyVM : CurrencyViewModel
205231) {
206232 LaunchedEffect (primaryDisplay) {
207- val newInput = when (primaryDisplay) {
233+ val newInput = when (primaryDisplay) {
208234 PrimaryDisplay .BITCOIN -> {
209235 val amountLong = currencyVM.convertFiatToSats(input.toDoubleOrNull() ? : 0.0 ) ? : 0
210236 if (amountLong > 0.0 ) amountLong.toString() else " "
211237 }
238+
212239 PrimaryDisplay .FIAT -> {
213240 val convertedAmount = currencyVM.convert(input.toLongOrDefault(0L ))
214- if ((convertedAmount?.value ? : BigDecimal (0 )) > BigDecimal (0 )) convertedAmount?.formatted.toString() else " "
241+ if ((convertedAmount?.value
242+ ? : BigDecimal (0 )) > BigDecimal (0 )
243+ ) convertedAmount?.formatted.toString() else " "
215244 }
216245 }
217246 onInputChanged(newInput)
218247 }
219248
220249 LaunchedEffect (input) {
221- val sats = when (primaryDisplay) {
250+ val sats = when (primaryDisplay) {
222251 PrimaryDisplay .BITCOIN -> {
223252 if (displayUnit == BitcoinDisplayUnit .MODERN ) input else (input.toLongOrDefault(0L ) * 100_000_000 ).toString()
224253 }
254+
225255 PrimaryDisplay .FIAT -> {
226256 val convertedAmount = currencyVM.convertFiatToSats(input.toDoubleOrNull() ? : 0.0 ) ? : 0L
227257 convertedAmount.toString()
@@ -235,7 +265,7 @@ private fun AmountInputHandler(
235265@Composable
236266private fun PreviewRunningLightning () {
237267 AppThemeSurface {
238- SendAmountScreen (
268+ SendAmountContent (
239269 uiState = SendUiState (
240270 payMethod = SendMethod .LIGHTNING ,
241271 amountInput = " 100" ,
@@ -247,6 +277,9 @@ private fun PreviewRunningLightning() {
247277 ),
248278 onBack = {},
249279 onEvent = {},
280+ input = " 100" ,
281+ currencyUiState = CurrencyUiState (),
282+ onInputChanged = {}
250283 )
251284 }
252285}
@@ -255,7 +288,7 @@ private fun PreviewRunningLightning() {
255288@Composable
256289private fun PreviewRunningOnchain () {
257290 AppThemeSurface {
258- SendAmountScreen (
291+ SendAmountContent (
259292 uiState = SendUiState (
260293 payMethod = SendMethod .ONCHAIN ,
261294 amountInput = " 5000" ,
@@ -267,6 +300,9 @@ private fun PreviewRunningOnchain() {
267300 ),
268301 onBack = {},
269302 onEvent = {},
303+ input = " 5000" ,
304+ currencyUiState = CurrencyUiState (),
305+ onInputChanged = {}
270306 )
271307 }
272308}
@@ -275,7 +311,7 @@ private fun PreviewRunningOnchain() {
275311@Composable
276312private fun PreviewInitializing () {
277313 AppThemeSurface {
278- SendAmountScreen (
314+ SendAmountContent (
279315 uiState = SendUiState (
280316 payMethod = SendMethod .LIGHTNING ,
281317 amountInput = " 100"
@@ -285,6 +321,9 @@ private fun PreviewInitializing() {
285321 ),
286322 onBack = {},
287323 onEvent = {},
324+ input = " 100" ,
325+ currencyUiState = CurrencyUiState (),
326+ onInputChanged = {}
288327 )
289328 }
290329}
0 commit comments