This commit is contained in:
Philip Cappelli
2025-03-28 11:44:42 -04:00
parent b0729e8cd2
commit f698d09b43
4 changed files with 17 additions and 9 deletions
@@ -50,7 +50,6 @@ private const val AUTH_CODE_SPACING_INTERVAL = 3
fun VaultItemLoginContent(
commonState: VaultItemState.ViewState.Content.Common,
loginItemState: VaultItemState.ViewState.Content.ItemType.Login,
totpCodeItemData: TotpCodeItemData?,
vaultCommonItemTypeHandlers: VaultCommonItemTypeHandlers,
vaultLoginItemTypeHandlers: VaultLoginItemTypeHandlers,
modifier: Modifier = Modifier,
@@ -137,7 +136,7 @@ fun VaultItemLoginContent(
}
}
totpCodeItemData?.let { totpCodeItemData ->
loginItemState.totpCodeItemData?.let { totpCodeItemData ->
item(key = "totpCode") {
Spacer(modifier = Modifier.height(8.dp))
TotpField(
@@ -45,7 +45,6 @@ import com.x8bit.bitwarden.ui.vault.feature.item.handlers.VaultCommonItemTypeHan
import com.x8bit.bitwarden.ui.vault.feature.item.handlers.VaultIdentityItemTypeHandlers
import com.x8bit.bitwarden.ui.vault.feature.item.handlers.VaultLoginItemTypeHandlers
import com.x8bit.bitwarden.ui.vault.feature.item.handlers.VaultSshKeyItemTypeHandlers
import com.x8bit.bitwarden.ui.vault.feature.item.model.TotpCodeItemData
import com.x8bit.bitwarden.ui.vault.model.VaultAddEditType
/**
@@ -261,7 +260,6 @@ fun VaultItemScreen(
) {
VaultItemContent(
viewState = state.viewState,
totpCodeItemData = state.totpCodeItemData,
modifier = Modifier
.fillMaxSize(),
vaultCommonItemTypeHandlers = remember(viewModel) {
@@ -352,7 +350,6 @@ private fun VaultItemDialogs(
@Composable
private fun VaultItemContent(
viewState: VaultItemState.ViewState,
totpCodeItemData: TotpCodeItemData?,
vaultCommonItemTypeHandlers: VaultCommonItemTypeHandlers,
vaultLoginItemTypeHandlers: VaultLoginItemTypeHandlers,
vaultCardItemTypeHandlers: VaultCardItemTypeHandlers,
@@ -373,7 +370,6 @@ private fun VaultItemContent(
VaultItemLoginContent(
commonState = viewState.common,
loginItemState = viewState.type,
totpCodeItemData = totpCodeItemData,
vaultCommonItemTypeHandlers = vaultCommonItemTypeHandlers,
vaultLoginItemTypeHandlers = vaultLoginItemTypeHandlers,
modifier = modifier,
@@ -1210,6 +1210,7 @@ class VaultItemViewModel @Inject constructor(
baseIconUrl = environmentRepository.environment.environmentUrlData.baseIconUrl,
isIconLoadingDisabled = settingsRepository.isIconLoadingDisabled,
relatedLocations = this.data?.relatedLocations.orEmpty().toImmutableList(),
totpCodeItemData = state.totpCodeItemData
)
?: VaultItemState.ViewState.Error(message = errorText)
@@ -1361,7 +1362,15 @@ class VaultItemViewModel @Inject constructor(
private fun handleTotpDataReceive(
action: VaultItemAction.Internal.TotpDataReceive,
) {
mutableStateFlow.update { it.copy(totpCodeItemData = action.totpData) }
onLoginContent { content, login ->
mutableStateFlow.update { currentState ->
currentState.copy(
viewState = content.copy(
type = login.copy(totpCodeItemData = action.totpData),
),
)
}
}
}
//endregion Internal Type Handlers
@@ -1684,6 +1693,7 @@ data class VaultItemState(
val passwordData: PasswordData?,
val uris: List<UriData>,
val passwordRevisionDate: String?,
val totpCodeItemData: TotpCodeItemData?,
val isPremiumUser: Boolean,
val canViewTotpCode: Boolean,
val fido2CredentialCreationDateText: Text?,
@@ -1695,7 +1705,8 @@ data class VaultItemState(
val hasLoginCredentials: Boolean
get() = username != null ||
passwordData != null ||
fido2CredentialCreationDateText != null
fido2CredentialCreationDateText != null ||
totpCodeItemData != null
/**
* A wrapper for the password data.
@@ -42,6 +42,7 @@ fun CipherView.toViewState(
previousState: VaultItemState.ViewState.Content?,
isPremiumUser: Boolean,
hasMasterPassword: Boolean,
totpCodeItemData: TotpCodeItemData?,
clock: Clock = Clock.systemDefaultZone(),
canDelete: Boolean,
canAssignToCollections: Boolean,
@@ -124,7 +125,8 @@ fun CipherView.toViewState(
),
isPremiumUser = isPremiumUser,
canViewTotpCode = isPremiumUser || this.organizationUseTotp,
fido2CredentialCreationDateText = loginValues
totpCodeItemData = totpCodeItemData,
fido2CredentialCreationDateText = loginValues
.fido2Credentials
?.firstOrNull()
?.getCreationDateText(clock),