Skip to content

Commit 14021ef

Browse files
committed
refactor: clean code
1 parent 37eacb7 commit 14021ef

File tree

1 file changed

+2
-113
lines changed

1 file changed

+2
-113
lines changed

app/src/main/java/to/bitkit/ui/components/NumberPadTextField.kt

Lines changed: 2 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import androidx.compose.runtime.remember
1313
import androidx.compose.runtime.setValue
1414
import androidx.compose.ui.Alignment
1515
import androidx.compose.ui.Modifier
16-
import androidx.compose.ui.graphics.Color
17-
import androidx.compose.ui.platform.testTag
1816
import androidx.compose.ui.semantics.contentDescription
1917
import androidx.compose.ui.semantics.semantics
2018
import androidx.compose.ui.text.TextStyle
@@ -23,12 +21,10 @@ import androidx.compose.ui.unit.dp
2321
import androidx.compose.ui.unit.sp
2422
import to.bitkit.ext.removeSpaces
2523
import to.bitkit.models.BitcoinDisplayUnit
26-
import to.bitkit.models.ConvertedAmount
2724
import to.bitkit.models.PrimaryDisplay
2825
import to.bitkit.ui.LocalCurrencies
2926
import to.bitkit.ui.currencyViewModel
3027
import to.bitkit.ui.theme.Colors
31-
import kotlin.math.abs
3228

3329
@Composable
3430
fun NumberPadTextField(
@@ -40,7 +36,6 @@ fun NumberPadTextField(
4036
val (rates, _, _, _, displayUnit, primaryDisplay) = LocalCurrencies.current
4137
val currency = currencyViewModel ?: return
4238

43-
4439
val satoshis by remember {
4540
derivedStateOf {
4641
val result = if (primaryDisplay == PrimaryDisplay.FIAT) {
@@ -75,7 +70,6 @@ fun NumberPadTextField(
7570
}
7671

7772
if (input.isNotEmpty()) {
78-
7973
val whole = input.split(".").firstOrNull().orEmpty().removeSpaces()
8074
val fraction = input.split(".").getOrNull(1).orEmpty().removeSpaces()
8175

@@ -108,15 +102,13 @@ fun NumberPadTextField(
108102
placeholder = placeholder,
109103
showPlaceholder = true,
110104
satoshis = satoshis.toIntOrNull() ?: 0,
111-
converted = convertedAmount
112105
)
113106
}
114107

115108
@Composable
116109
fun MoneyAmount(
117110
modifier: Modifier = Modifier,
118111
value: String,
119-
converted: ConvertedAmount?,
120112
unit: PrimaryDisplay,
121113
placeholder: String,
122114
showPlaceholder: Boolean,
@@ -130,26 +122,8 @@ fun MoneyAmount(
130122
.semantics { contentDescription = value },
131123
horizontalAlignment = Alignment.Start
132124
) {
133-
// if (showConversion && !reverse) {
134-
// Money(
135-
// sats = satoshis,
136-
// showSymbol = true,
137-
// unitType = PrimaryDisplay.FIAT,
138-
// modifier = Modifier.padding(bottom = 16.dp),
139-
// converted = converted
140-
// )
141-
// }
142-
//
143-
// if (showConversion && reverse) {
144-
// Money(
145-
// sats = satoshis,
146-
// color = Colors.White50,
147-
// showSymbol = true,
148-
// unitType = PrimaryDisplay.FIAT,
149-
// converted = converted
150-
// )
151-
// }
152-
MoneySSB(sats = satoshis.toLong())
125+
126+
MoneySSB(sats = satoshis.toLong(), reversed = true)
153127

154128
Row(
155129
verticalAlignment = Alignment.CenterVertically
@@ -183,88 +157,3 @@ fun MoneyAmount(
183157
}
184158
}
185159
}
186-
187-
@Composable
188-
fun Money(
189-
sats: Int,
190-
converted: ConvertedAmount?,
191-
unitType: PrimaryDisplay = PrimaryDisplay.BITCOIN,
192-
unit: PrimaryDisplay? = null,
193-
showSymbol: Boolean = false,
194-
symbolColor: Color? = null,
195-
color: Color? = null,
196-
sign: String? = null,
197-
shouldRoundUp: Boolean = false,
198-
modifier: Modifier = Modifier,
199-
testID: String? = null,
200-
) {
201-
val nextUnit = remember { PrimaryDisplay.FIAT } // Replace with actual state management
202-
203-
val absSats = abs(sats)
204-
val actualUnit = unit ?: if (unitType == PrimaryDisplay.FIAT) nextUnit else PrimaryDisplay.BITCOIN
205-
val actualShowSymbol = showSymbol || actualUnit == PrimaryDisplay.FIAT
206-
207-
// Replace with actual display value calculation
208-
val displayValues = remember(absSats, shouldRoundUp) { //TODO IMPLEMENT
209-
DisplayValues(
210-
bitcoinFormatted = absSats.toString(),
211-
fiatFormatted = converted?.formatted.orEmpty(),
212-
fiatWhole = converted?.value.toString().orEmpty(),
213-
fiatSymbol = converted?.symbol.orEmpty()
214-
)
215-
}
216-
217-
val symbol = @Composable {
218-
Text(
219-
text = if (actualUnit == PrimaryDisplay.BITCOIN) "" else displayValues.fiatSymbol,
220-
color = symbolColor ?: color ?: Colors.White50,
221-
)
222-
}
223-
224-
// val text = remember(actualUnit, denomination, decimalLength, shouldHide) {
225-
// when {
226-
//// shouldHide -> if (size == TextSize.Display) " • • • • • • • • •" else " • • • • •"
227-
// actualUnit == PrimaryDisplay.FIAT -> displayValues.fiatFormatted
228-
// }
229-
// actualUnit == PrimaryDisplay.BITCOIN && denomination == BitcoinDisplayUnit.CLASSIC -> {
230-
// if (decimalLength == DecimalLength.Long) {
231-
// "%.8f".format(displayValues.bitcoinFormatted.toDouble())
232-
// } else {
233-
// "%.5f".format(displayValues.bitcoinFormatted.toDouble())
234-
// }
235-
// }
236-
// else -> displayValues.bitcoinFormatted
237-
// }
238-
// }
239-
240-
val text = remember { displayValues.bitcoinFormatted }
241-
242-
Row(
243-
modifier = modifier
244-
.then(testID?.let { Modifier.testTag(it) } ?: Modifier)
245-
.semantics { contentDescription = text },
246-
verticalAlignment = Alignment.CenterVertically
247-
) {
248-
if (sign != null) {
249-
Text(
250-
text = sign,
251-
color = color ?: Colors.White50,
252-
modifier = Modifier.padding(end = 3.dp),
253-
)
254-
}
255-
if (actualShowSymbol) {
256-
symbol()
257-
}
258-
Text(
259-
text = text,
260-
color = color ?: Colors.Black50,
261-
)
262-
}
263-
}
264-
265-
data class DisplayValues(
266-
val bitcoinFormatted: String,
267-
val fiatFormatted: String,
268-
val fiatWhole: String,
269-
val fiatSymbol: String
270-
)

0 commit comments

Comments
 (0)