-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCalculatorValues.kt
More file actions
32 lines (28 loc) · 1005 Bytes
/
Copy pathCalculatorValues.kt
File metadata and controls
32 lines (28 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package to.bitkit.models.widget
import kotlinx.serialization.Serializable
import to.bitkit.ext.removeSpaces
import to.bitkit.models.BitcoinDisplayUnit
import to.bitkit.ui.screens.widgets.calculator.calculatorBtcValueToSats
@Serializable
data class CalculatorValues(
val btcValue: String = "10000",
val fiatValue: String = "",
val satsValue: Long? = null,
val displayUnit: BitcoinDisplayUnit? = null,
)
internal fun CalculatorValues.resolveCalculatorSatsValue(): Long {
satsValue?.let { return it }
if (btcValue.isEmpty()) return 0L
return calculatorBtcValueToSats(
btcValue = btcValue,
displayUnit = displayUnit ?: inferLegacyCalculatorDisplayUnit(btcValue),
)
}
private fun inferLegacyCalculatorDisplayUnit(btcValue: String): BitcoinDisplayUnit {
val normalizedValue = btcValue.removeSpaces()
return if (normalizedValue.any { it == '.' || it == ',' }) {
BitcoinDisplayUnit.CLASSIC
} else {
BitcoinDisplayUnit.MODERN
}
}