Skip to content

Commit

Permalink
Merge pull request #1288 from radixdlt/fix/claim-wallet
Browse files Browse the repository at this point in the history
Hotfix 1.11.2
  • Loading branch information
sergiupuhalschi-rdx authored Dec 18, 2024
2 parents 163a1ab + 0869617 commit 422ccec
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ class SignWithDeviceFactorSourceUseCase @Inject constructor(
is EntitySecurityState.Unsecured -> {
val factorInstance = when (signRequest) {
is SignRequest.RolaSignRequest ->
securityState.value.authenticationSigning
?: securityState.value.transactionSigning
// TODO AuthSigningFactorInstance update this when the feature is implemented
// securityState.value.authenticationSigning
// ?:
securityState.value.transactionSigning

is SignRequest.TransactionIntentSignRequest,
is SignRequest.SubintentSignRequest -> securityState.value.transactionSigning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,11 @@ class GetSignaturesViewModel @Inject constructor(
is EntitySecurityState.Unsecured -> {
val factorSourceId = when (state.value.signPurpose) {
SignPurpose.SignTransaction -> securityState.value.transactionSigning.factorSourceId.asGeneral()
SignPurpose.SignAuth -> securityState.value.authenticationSigning?.factorSourceId?.asGeneral()
?: securityState.value.transactionSigning.factorSourceId.asGeneral()
SignPurpose.SignAuth ->
// TODO AuthSigningFactorInstance update this when the feature is implemented, for now hiding the button
// securityState.value.authenticationSigning?.factorSourceId?.asGeneral()
// ?:
securityState.value.transactionSigning.factorSourceId.asGeneral()
}
val factorSource = requireNotNull(profile.factorSourceById(factorSourceId))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import rdx.works.core.sargon.activeAccountsOnCurrentNetwork
import rdx.works.core.sargon.hasAuthSigning
import rdx.works.profile.domain.GetProfileUseCase
import rdx.works.profile.domain.ProfileException
import rdx.works.profile.domain.account.AddAuthSigningFactorInstanceUseCase
Expand Down Expand Up @@ -58,7 +57,9 @@ class DevSettingsViewModel @Inject constructor(
_state.update { state ->
state.copy(
account = account,
hasAuthKey = account.hasAuthSigning
// TODO AuthSigningFactorInstance update this when the feature is implemented, for now hiding the button
// hasAuthKey = account.hasAuthSigning
hasAuthKey = true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.babylon.wallet.android.presentation.common.resetwallet

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import com.babylon.wallet.android.R
import com.babylon.wallet.android.designsystem.theme.RadixTheme

@Composable
fun ResetWalletDialog(
modifier: Modifier = Modifier,
onConfirm: () -> Unit,
onDeny: () -> Unit
) {
AlertDialog(
modifier = modifier,
onDismissRequest = onDeny,
shape = RadixTheme.shapes.roundedRectSmall,
containerColor = RadixTheme.colors.defaultBackground,
title = {
Text(
text = stringResource(id = R.string.factoryReset_dialog_title),
style = RadixTheme.typography.body2Header,
color = RadixTheme.colors.gray1
)
},
text = {
Text(
text = stringResource(id = R.string.factoryReset_dialog_message),
style = RadixTheme.typography.body1Regular,
color = RadixTheme.colors.gray1
)
},
confirmButton = {
Text(
modifier = modifier
.clickable(role = Role.Button) { onConfirm() }
.padding(
horizontal = RadixTheme.dimensions.paddingSmall,
vertical = RadixTheme.dimensions.paddingXSmall
),
text = stringResource(id = R.string.common_confirm),
color = RadixTheme.colors.red1
)
},
dismissButton = {
Text(
modifier = modifier
.clickable(role = Role.Button) { onDeny() }
.padding(
horizontal = RadixTheme.dimensions.paddingSmall,
vertical = RadixTheme.dimensions.paddingXSmall
),
text = stringResource(id = R.string.common_cancel),
color = RadixTheme.colors.blue2
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import rdx.works.core.domain.DApp
import rdx.works.core.sargon.activePersonaOnCurrentNetwork
import rdx.works.core.sargon.hasAuthSigning
import rdx.works.profile.data.repository.DAppConnectionRepository
import rdx.works.profile.domain.ChangeEntityVisibilityUseCase
import rdx.works.profile.domain.GetProfileUseCase
Expand Down Expand Up @@ -77,7 +76,9 @@ class PersonaDetailViewModel @Inject constructor(
authorizedDapps = dApps.toImmutableList(),
persona = personaToDApps.first,
loading = false,
hasAuthKey = personaToDApps.first.hasAuthSigning
// TODO AuthSigningFactorInstance update this when the feature is implemented, for now hiding the button
// hasAuthKey = personaToDApps.first.hasAuthSigning
hasAuthKey = true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.babylon.wallet.android.presentation.settings.troubleshooting.reset

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -15,7 +14,6 @@ import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHostState
Expand All @@ -29,7 +27,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
Expand All @@ -38,6 +35,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.babylon.wallet.android.R
import com.babylon.wallet.android.designsystem.theme.RadixTheme
import com.babylon.wallet.android.designsystem.theme.RadixWalletTheme
import com.babylon.wallet.android.presentation.common.resetwallet.ResetWalletDialog
import com.babylon.wallet.android.presentation.settings.securitycenter.RecoverableStatusCard
import com.babylon.wallet.android.presentation.ui.composables.DSR
import com.babylon.wallet.android.presentation.ui.composables.RadixCenteredTopAppBar
Expand Down Expand Up @@ -86,7 +84,7 @@ private fun FactoryResetScreenContent(
onBackClick: () -> Unit
) {
if (state.deleteWalletDialogVisible) {
DeleteWalletDialog(
ResetWalletDialog(
onConfirm = onDeleteWalletConfirm,
onDeny = onDeleteWalletDeny
)
Expand Down Expand Up @@ -200,58 +198,6 @@ private fun FactoryResetScreenContent(
}
}

@Composable
private fun DeleteWalletDialog(
modifier: Modifier = Modifier,
onConfirm: () -> Unit,
onDeny: () -> Unit
) {
AlertDialog(
modifier = modifier,
onDismissRequest = onDeny,
shape = RadixTheme.shapes.roundedRectSmall,
containerColor = RadixTheme.colors.defaultBackground,
title = {
Text(
text = stringResource(id = R.string.factoryReset_dialog_title),
style = RadixTheme.typography.body2Header,
color = RadixTheme.colors.gray1
)
},
text = {
Text(
text = stringResource(id = R.string.factoryReset_dialog_message),
style = RadixTheme.typography.body1Regular,
color = RadixTheme.colors.gray1
)
},
confirmButton = {
Text(
modifier = modifier
.clickable(role = Role.Button) { onConfirm() }
.padding(
horizontal = RadixTheme.dimensions.paddingSmall,
vertical = RadixTheme.dimensions.paddingXSmall
),
text = stringResource(id = R.string.common_confirm),
color = RadixTheme.colors.red1
)
},
dismissButton = {
Text(
modifier = modifier
.clickable(role = Role.Button) { onDeny() }
.padding(
horizontal = RadixTheme.dimensions.paddingSmall,
vertical = RadixTheme.dimensions.paddingXSmall
),
text = stringResource(id = R.string.common_cancel),
color = RadixTheme.colors.blue2
)
}
)
}

@Composable
fun UnrecoverableStatusCard(modifier: Modifier = Modifier, text: String) {
Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.babylon.wallet.android.R
import com.babylon.wallet.android.designsystem.composable.RadixPrimaryButton
import com.babylon.wallet.android.designsystem.composable.RadixTextButton
import com.babylon.wallet.android.designsystem.theme.RadixTheme
import com.babylon.wallet.android.presentation.common.FullscreenCircularProgressContent
import com.babylon.wallet.android.presentation.common.resetwallet.ResetWalletDialog
import com.babylon.wallet.android.presentation.ui.RadixWalletPreviewTheme
import com.babylon.wallet.android.presentation.ui.composables.WarningButton

@Composable
fun ClaimedByAnotherDeviceScreen(
Expand Down Expand Up @@ -62,7 +63,10 @@ fun ClaimedByAnotherDeviceScreen(
.padding(padding)
.padding(vertical = RadixTheme.dimensions.paddingLarge)
.fillMaxSize(),
onClearWalletClick = viewModel::onClearWalletClick,
state = state,
onResetWalletClick = viewModel::onResetWalletClick,
onResetWalletConfirmClick = viewModel::onResetWalletConfirm,
onResetWalletDenyClick = viewModel::onResetWalletDeny,
onTransferControlBackClick = viewModel::onTransferWalletBackClick
)
}
Expand All @@ -72,9 +76,19 @@ fun ClaimedByAnotherDeviceScreen(
@Composable
fun ClaimedByAnotherDeviceContent(
modifier: Modifier = Modifier,
onClearWalletClick: () -> Unit,
state: ClaimedByAnotherDeviceViewModel.State,
onResetWalletClick: () -> Unit,
onResetWalletConfirmClick: () -> Unit,
onResetWalletDenyClick: () -> Unit,
onTransferControlBackClick: () -> Unit
) {
if (state.isResetWalletConfirmationVisible) {
ResetWalletDialog(
onConfirm = onResetWalletConfirmClick,
onDeny = onResetWalletDenyClick
)
}

Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally
Expand Down Expand Up @@ -122,12 +136,12 @@ fun ClaimedByAnotherDeviceContent(
}

Spacer(Modifier.weight(0.5f))
RadixPrimaryButton(
WarningButton(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = RadixTheme.dimensions.paddingDefault),
text = stringResource(id = R.string.configurationBackup_automated_walletTransferredClearButton),
onClick = onClearWalletClick
text = stringResource(id = R.string.factoryReset_resetWallet),
onClick = onResetWalletClick
)
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingSmall))
RadixTextButton(
Expand All @@ -148,7 +162,10 @@ fun ClaimedByAnotherDeviceContent(
fun ClaimedByAnotherDeviceScreenPreview() {
RadixWalletPreviewTheme {
ClaimedByAnotherDeviceContent(
onClearWalletClick = {},
state = ClaimedByAnotherDeviceViewModel.State(),
onResetWalletClick = {},
onResetWalletConfirmClick = {},
onResetWalletDenyClick = {},
onTransferControlBackClick = {}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,22 @@ class ClaimedByAnotherDeviceViewModel @Inject constructor(

override fun initialState(): State = State()

fun onClearWalletClick() = viewModelScope.launch {
deleteWalletUseCase()
cloudBackupErrorStream.resetErrors()
sendEvent(Event.ResetToOnboarding)
fun onResetWalletClick() {
_state.update { it.copy(isResetWalletConfirmationVisible = true) }
}

fun onResetWalletConfirm() {
_state.update { it.copy(isResetWalletConfirmationVisible = false) }

viewModelScope.launch {
deleteWalletUseCase()
cloudBackupErrorStream.resetErrors()
sendEvent(Event.ResetToOnboarding)
}
}

fun onResetWalletDeny() {
_state.update { it.copy(isResetWalletConfirmationVisible = false) }
}

fun onTransferWalletBackClick() = viewModelScope.launch {
Expand All @@ -63,7 +75,8 @@ class ClaimedByAnotherDeviceViewModel @Inject constructor(
}

data class State(
val isReclaiming: Boolean = false
val isReclaiming: Boolean = false,
val isResetWalletConfirmationVisible: Boolean = false,
) : UiState

sealed interface Event : OneOffEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fun EntitySecurityState.Companion.unsecured(
factorSourceId = factorSourceId.value,
publicKey = hdPublicKey
),
authenticationSigning = null
provisionalSecurifiedConfig = null
)
)

Expand Down Expand Up @@ -62,7 +62,8 @@ val EntitySecurityState.transactionSigningFactorInstance: HierarchicalDeterminis

val EntitySecurityState.authenticationSigningFactorInstance: HierarchicalDeterministicFactorInstance?
get() = when (this) {
is EntitySecurityState.Unsecured -> value.authenticationSigning
// TODO AuthSigningFactorInstance: delete this and all the usages when the replacement is ready
is EntitySecurityState.Unsecured -> null
}

val EntitySecurityState.hasAuthSigning: Boolean
Expand Down
Loading

0 comments on commit 422ccec

Please sign in to comment.