Skip to content

Commit 656b829

Browse files
committed
chore: cleanup after self review
1 parent b66c2c9 commit 656b829

File tree

11 files changed

+153
-158
lines changed

11 files changed

+153
-158
lines changed

app/src/main/java/to/bitkit/repositories/CurrencyRepo.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class CurrencyRepo @Inject constructor(
156156
}
157157

158158
suspend fun switchUnit() = withContext(bgDispatcher) {
159-
settingsStore.update { it.copy(primaryDisplay = _currencyState.value.primaryDisplay.not()) }
159+
settingsStore.update { it.copy(primaryDisplay = it.primaryDisplay.not()) }
160160
}
161161

162162
override suspend fun switchUnit(unit: PrimaryDisplay): PrimaryDisplay = withContext(bgDispatcher) {
@@ -265,17 +265,12 @@ interface AmountInputHandler {
265265

266266
companion object {
267267
fun stub(state: CurrencyState = CurrencyState()) = object : AmountInputHandler {
268-
private var currentPrimaryDisplay = state.primaryDisplay
269-
270268
override fun convertSatsToFiatString(sats: Long): String {
271269
return sats.asBtc().multiply(BigDecimal.valueOf(STUB_RATE)).formatCurrency() ?: ""
272270
}
273271

274272
override fun convertFiatToSats(fiat: Double) = (fiat / STUB_RATE * SATS_IN_BTC).toLong()
275-
override suspend fun switchUnit(unit: PrimaryDisplay): PrimaryDisplay {
276-
currentPrimaryDisplay = currentPrimaryDisplay.not()
277-
return currentPrimaryDisplay
278-
}
273+
override suspend fun switchUnit(unit: PrimaryDisplay) = unit.not()
279274
}
280275
}
281276
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ fun rememberMoneyText(
125125
if (unit == PrimaryDisplay.BITCOIN) {
126126
append(sats.formatToModernDisplay())
127127
} else {
128-
// For fiat preview, convert sats to fiat using STUB_RATE and formatCurrency
129128
val fiatValue = sats.asBtc().multiply(BigDecimal.valueOf(STUB_RATE))
130129
append(fiatValue.formatCurrency() ?: "0.00")
131130
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ fun NumberPadTextField(
4242
) {
4343
MoneyAmount(
4444
modifier = modifier.then(Modifier.clickableAlpha(onClick = onClick)),
45-
value = uiState.value.displayText,
45+
value = uiState.value.text,
4646
unit = currencies.primaryDisplay,
4747
placeholder = viewModel.getPlaceholder(currencies),
4848
showPlaceholder = true,
49-
satoshis = uiState.value.amountSats,
49+
satoshis = uiState.value.sats,
5050
currencySymbol = currencies.currencySymbol,
5151
showSecondaryField = showSecondaryField,
5252
)

app/src/main/java/to/bitkit/ui/screens/transfer/FundingScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ import to.bitkit.ui.utils.withAccent
4141

4242
@Composable
4343
fun FundingScreen(
44+
isGeoBlocked: Boolean,
4445
onTransfer: () -> Unit = {},
4546
onFund: () -> Unit = {},
4647
onAdvanced: () -> Unit = {},
4748
onBackClick: () -> Unit = {},
4849
onCloseClick: () -> Unit = {},
49-
isGeoBlocked: Boolean
5050
) {
5151
val balances = LocalBalances.current
5252
val canTransfer = remember(balances.totalOnchainSats) {

app/src/main/java/to/bitkit/ui/screens/transfer/SpendingAmountScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fun SpendingAmountScreen(
108108
viewModel.updateLimits(newAmountSats)
109109
amountInputViewModel.setSats(newAmountSats, currencies)
110110
},
111-
onConfirmAmount = { viewModel.onConfirmAmount(amountUiState.amountSats) },
111+
onConfirmAmount = { viewModel.onConfirmAmount(amountUiState.sats) },
112112
)
113113
}
114114

@@ -238,7 +238,7 @@ private fun SpendingAmountNodeRunning(
238238
PrimaryButton(
239239
text = stringResource(R.string.common__continue),
240240
onClick = onConfirmAmount,
241-
enabled = amountUiState.amountSats != 0L && amountUiState.amountSats <= uiState.maxAllowedToSend,
241+
enabled = amountUiState.sats != 0L && amountUiState.sats <= uiState.maxAllowedToSend,
242242
isLoading = uiState.isLoading,
243243
modifier = Modifier.testTag("SpendingAmountContinue")
244244
)

app/src/main/java/to/bitkit/ui/screens/wallets/receive/EditInvoiceScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fun EditInvoiceScreen(
8888

8989
LaunchedEffect(Unit) {
9090
editInvoiceVM.editInvoiceEffect.collect { effect ->
91-
val receiveSats = amountInputUiState.amountSats.toULong()
91+
val receiveSats = amountInputUiState.sats.toULong()
9292
when (effect) {
9393
is EditInvoiceVM.EditInvoiceScreenEffects.NavigateAddLiquidity -> {
9494
updateInvoice(receiveSats)
@@ -140,7 +140,7 @@ fun EditInvoiceScreen(
140140
},
141141
onContinueKeyboard = { keyboardVisible = false },
142142
onContinueGeneral = {
143-
updateInvoice(amountInputUiState.amountSats.toULong())
143+
updateInvoice(amountInputUiState.sats.toULong())
144144
editInvoiceVM.onClickContinue()
145145
},
146146
onClickAddTag = onClickAddTag,

app/src/main/java/to/bitkit/ui/screens/wallets/receive/ReceiveAmountScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ fun ReceiveAmountScreen(
8282
minCjitSats = minCjitSats,
8383
currencies = currencies,
8484
isCreatingInvoice = isCreatingInvoice,
85-
canContinue = amountInputUiState.amountSats >= (minCjitSats?.toLong() ?: 0),
85+
canContinue = amountInputUiState.sats >= (minCjitSats?.toLong() ?: 0),
8686
onBack = onBack,
8787
onClickMin = { amountInputViewModel.setSats(it, currencies) },
8888
onContinue = {
89-
val sats = amountInputUiState.amountSats
89+
val sats = amountInputUiState.sats
9090
scope.launch {
9191
isCreatingInvoice = true
9292
runCatching {

app/src/main/java/to/bitkit/ui/screens/wallets/send/SendAmountScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ fun SendAmountScreen(
8787
}
8888
}
8989

90-
LaunchedEffect(amountInputUiState.amountSats) {
91-
currentOnEvent(SendEvent.AmountChange(amountInputUiState.amountSats.toULong()))
90+
LaunchedEffect(amountInputUiState.sats) {
91+
currentOnEvent(SendEvent.AmountChange(amountInputUiState.sats.toULong()))
9292
}
9393

9494
SendAmountContent(

app/src/main/java/to/bitkit/viewmodels/AmountInputViewModel.kt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class AmountInputViewModel @Inject constructor(
7777
rawInputText = newText
7878
_uiState.update {
7979
it.copy(
80-
displayText = formatDisplayTextFromAmount(newAmount, primaryDisplay, isModern = true),
81-
amountSats = newAmount,
80+
text = formatDisplayTextFromAmount(newAmount, primaryDisplay, isModern = true),
81+
sats = newAmount,
8282
errorKey = null
8383
)
8484
}
@@ -95,12 +95,12 @@ class AmountInputViewModel @Inject constructor(
9595
rawInputText = newText
9696
_uiState.update {
9797
it.copy(
98-
displayText = if (primaryDisplay == PrimaryDisplay.FIAT) {
98+
text = if (primaryDisplay == PrimaryDisplay.FIAT) {
9999
formatFiatGroupingOnly(newText)
100100
} else {
101101
newText
102102
},
103-
amountSats = newAmount,
103+
sats = newAmount,
104104
errorKey = null
105105
)
106106
}
@@ -113,8 +113,8 @@ class AmountInputViewModel @Inject constructor(
113113
rawInputText = newText
114114
_uiState.update {
115115
it.copy(
116-
amountSats = 0,
117-
displayText = "",
116+
sats = 0,
117+
text = "",
118118
errorKey = null
119119
)
120120
}
@@ -128,14 +128,14 @@ class AmountInputViewModel @Inject constructor(
128128

129129
_uiState.update {
130130
it.copy(
131-
amountSats = sats,
132-
displayText = formatDisplayTextFromAmount(sats, primaryDisplay, isModern)
131+
sats = sats,
132+
text = formatDisplayTextFromAmount(sats, primaryDisplay, isModern)
133133
)
134134
}
135135
// Update raw input text based on the formatted display
136136
rawInputText = when (primaryDisplay) {
137-
PrimaryDisplay.FIAT -> _uiState.value.displayText.replace(",", "")
138-
else -> _uiState.value.displayText
137+
PrimaryDisplay.FIAT -> _uiState.value.text.replace(",", "")
138+
else -> _uiState.value.text
139139
}
140140
}
141141

@@ -149,17 +149,17 @@ class AmountInputViewModel @Inject constructor(
149149
val newPrimaryDisplay = amountInputHandler.switchUnit(currencies.primaryDisplay)
150150

151151
// Update display text when currency changes
152-
val amountSats = _uiState.value.amountSats
152+
val amountSats = _uiState.value.sats
153153
if (amountSats > 0) {
154154
_uiState.update {
155155
it.copy(
156-
displayText = formatDisplayTextFromAmount(amountSats, newPrimaryDisplay, isModern)
156+
text = formatDisplayTextFromAmount(amountSats, newPrimaryDisplay, isModern)
157157
)
158158
}
159159
// Update raw input text based on the new display
160160
rawInputText = when (newPrimaryDisplay) {
161-
PrimaryDisplay.FIAT -> _uiState.value.displayText.replace(",", "")
162-
else -> _uiState.value.displayText
161+
PrimaryDisplay.FIAT -> _uiState.value.text.replace(",", "")
162+
else -> _uiState.value.text
163163
}
164164
} else if (currentRawInput.isNotEmpty()) {
165165
// Convert the raw input from the old currency to the new currency
@@ -170,7 +170,7 @@ class AmountInputViewModel @Inject constructor(
170170
val converted = amountInputHandler.convertSatsToFiatString(sats)
171171
if (converted.isNotEmpty()) {
172172
rawInputText = converted.replace(",", "")
173-
_uiState.update { it.copy(displayText = formatFiatGroupingOnly(rawInputText)) }
173+
_uiState.update { it.copy(text = formatFiatGroupingOnly(rawInputText)) }
174174
}
175175
}
176176

@@ -179,7 +179,7 @@ class AmountInputViewModel @Inject constructor(
179179
val sats = convertFiatToSats(currentRawInput)
180180
if (sats != null) {
181181
rawInputText = formatBitcoinFromSats(sats, isModern)
182-
_uiState.update { it.copy(displayText = rawInputText) }
182+
_uiState.update { it.copy(text = rawInputText) }
183183
}
184184
}
185185
}
@@ -212,7 +212,7 @@ class AmountInputViewModel @Inject constructor(
212212
fun getPlaceholder(currencyState: CurrencyState): String {
213213
val primaryDisplay = currencyState.primaryDisplay
214214
val isModern = currencyState.displayUnit.isModern()
215-
if (_uiState.value.displayText.isEmpty()) {
215+
if (_uiState.value.text.isEmpty()) {
216216
return when (primaryDisplay) {
217217
PrimaryDisplay.BITCOIN -> if (isModern) PLACEHOLDER_MODERN else PLACEHOLDER_CLASSIC
218218
PrimaryDisplay.FIAT -> PLACEHOLDER_FIAT
@@ -223,8 +223,8 @@ class AmountInputViewModel @Inject constructor(
223223
if (isModern) {
224224
PLACEHOLDER_MODERN_DECIMALS
225225
} else {
226-
if (_uiState.value.displayText.contains(".")) {
227-
val parts = _uiState.value.displayText.split(".", limit = 2)
226+
if (_uiState.value.text.contains(".")) {
227+
val parts = _uiState.value.text.split(".", limit = 2)
228228
val decimalPart = if (parts.size > 1) parts[1] else ""
229229
val remainingDecimals = CLASSIC_DECIMALS - decimalPart.length
230230
if (remainingDecimals > 0) "0".repeat(remainingDecimals) else ""
@@ -235,8 +235,8 @@ class AmountInputViewModel @Inject constructor(
235235
}
236236

237237
PrimaryDisplay.FIAT -> {
238-
if (_uiState.value.displayText.contains(".")) {
239-
val parts = _uiState.value.displayText.split(".", limit = 2)
238+
if (_uiState.value.text.contains(".")) {
239+
val parts = _uiState.value.text.split(".", limit = 2)
240240
val decimalPart = if (parts.size > 1) parts[1] else ""
241241
val remainingDecimals = FIAT_DECIMALS - decimalPart.length
242242
if (remainingDecimals > 0) "0".repeat(remainingDecimals) else ""
@@ -406,8 +406,8 @@ class AmountInputViewModel @Inject constructor(
406406
}
407407

408408
data class AmountInputUiState(
409-
val amountSats: Long = 0L,
410-
val displayText: String = "",
409+
val sats: Long = 0L,
410+
val text: String = "",
411411
val errorKey: String? = null,
412412
)
413413

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import to.bitkit.utils.Logger
8787
import java.math.BigDecimal
8888
import javax.inject.Inject
8989

90+
@Suppress("LongParameterList")
9091
@HiltViewModel
9192
class AppViewModel @Inject constructor(
9293
@ApplicationContext private val context: Context,

0 commit comments

Comments
 (0)