Updated on 2026-08-14
This commit is contained in:
parent
6c6ce3d05e
commit
8c8c0ada45
6 changed files with 31 additions and 21 deletions
|
|
@ -34,8 +34,8 @@ internal class DefaultRenameWalletComponent @AssistedInject constructor(
|
|||
private val stateFlow: MutableStateFlow<RenameWalletUM> = MutableStateFlow(
|
||||
value = RenameWalletUM(
|
||||
walletNameValue = TextFieldValue(text = params.currentName),
|
||||
isNameCorrect = false,
|
||||
updateValue = ::updateValue,
|
||||
isConfirmEnabled = false,
|
||||
onConfirm = { renameWallet(params.userWalletId) },
|
||||
),
|
||||
)
|
||||
|
|
@ -58,12 +58,14 @@ internal class DefaultRenameWalletComponent @AssistedInject constructor(
|
|||
stateFlow.update {
|
||||
it.copy(
|
||||
walletNameValue = value,
|
||||
isNameCorrect = value.text.isNotBlank() && value.text != currentWalletName,
|
||||
isConfirmEnabled = value.text.isNotBlank() && value.text != currentWalletName,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun renameWallet(userWalletId: UserWalletId) = componentScope.launch {
|
||||
stateFlow.update { it.copy(isConfirmEnabled = false) }
|
||||
|
||||
val newName = stateFlow.value.walletNameValue
|
||||
val maybeError = renameWalletUseCase(userWalletId, newName.text).leftOrNull()
|
||||
|
||||
|
|
@ -71,9 +73,7 @@ internal class DefaultRenameWalletComponent @AssistedInject constructor(
|
|||
Timber.e("Unable to rename wallet: $maybeError")
|
||||
|
||||
val message = when (maybeError) {
|
||||
is UpdateWalletError.DataError -> resourceReference(
|
||||
id = R.string.common_unknown_error,
|
||||
)
|
||||
is UpdateWalletError.DataError -> resourceReference(id = R.string.common_unknown_error)
|
||||
is UpdateWalletError.NameAlreadyExists -> resourceReference(
|
||||
id = R.string.user_wallet_list_rename_popup_error_already_exists,
|
||||
formatArgs = wrappedList(newName),
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ internal class PreviewRenameWalletComponent : RenameWalletComponent {
|
|||
|
||||
private val previewState = RenameWalletUM(
|
||||
walletNameValue = TextFieldValue(text = "My Wallet"),
|
||||
isNameCorrect = false,
|
||||
isConfirmEnabled = false,
|
||||
updateValue = {},
|
||||
onConfirm = {},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import androidx.compose.ui.text.input.TextFieldValue
|
|||
@Immutable
|
||||
internal data class RenameWalletUM(
|
||||
val walletNameValue: TextFieldValue,
|
||||
val isNameCorrect: Boolean,
|
||||
val updateValue: (value: TextFieldValue) -> Unit,
|
||||
val isConfirmEnabled: Boolean,
|
||||
val onConfirm: () -> Unit,
|
||||
)
|
||||
|
|
@ -23,7 +23,7 @@ internal fun RenameWalletDialog(model: RenameWalletUM, onDismiss: () -> Unit) {
|
|||
fieldValue = value,
|
||||
confirmButton = DialogButton(
|
||||
title = stringResource(id = R.string.common_ok),
|
||||
enabled = model.isNameCorrect,
|
||||
enabled = model.isConfirmEnabled,
|
||||
onClick = model.onConfirm,
|
||||
),
|
||||
dismissButton = DialogButton(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue