demo: add offline wallet confirmation dialog

This commit is contained in:
Oscar Mira 2023-10-25 17:41:34 +02:00
parent 45edf35d83
commit 02f8575f82
4 changed files with 61 additions and 46 deletions

View File

@ -49,7 +49,7 @@ class AddWalletViewModel(
.stateIn(
scope = viewModelScope,
started = WhileSubscribed(5000),
initialValue = listOf(RemoteNode.EMPTY),
initialValue = emptyList(),
)
val selectedRemoteNodes = mutableStateMapOf<Long?, Boolean>()

View File

@ -44,21 +44,16 @@ private fun FirstStepScreen(
onRestoreClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Scaffold(
topBar = {
Toolbar(
title = "Add wallet",
navigationIcon = {
IconButton(onClick = onBackClick) {
Icon(
imageVector = AppIcons.ArrowBack,
contentDescription = "Back",
)
}
}
)
}
) { padding ->
Scaffold(topBar = {
Toolbar(title = "Add wallet", navigationIcon = {
IconButton(onClick = onBackClick) {
Icon(
imageVector = AppIcons.ArrowBack,
contentDescription = "Back",
)
}
})
}) { padding ->
Column(
modifier = modifier
.fillMaxSize()
@ -144,21 +139,20 @@ private fun SecondStepScreen(
remoteNodes: List<RemoteNode>,
selectedRemoteNodeIds: MutableMap<Long?, Boolean> = mutableMapOf(),
) {
Scaffold(
topBar = {
Toolbar(
title = if (showRestoreOptions) "Restore wallet" else "New wallet",
navigationIcon = {
IconButton(onClick = onBackClick) {
Icon(
imageVector = AppIcons.ArrowBack,
contentDescription = "Back",
)
}
var showOffLineConfirmationDialog by remember { mutableStateOf(false) }
Scaffold(topBar = {
Toolbar(
title = if (showRestoreOptions) "Restore wallet" else "New wallet",
navigationIcon = {
IconButton(onClick = onBackClick) {
Icon(
imageVector = AppIcons.ArrowBack,
contentDescription = "Back",
)
}
)
}
) { padding ->
})
}) { padding ->
Column(
modifier = modifier
.padding(padding)
@ -188,21 +182,18 @@ private fun SecondStepScreen(
Text(
text = "Remote node selection",
style = MaterialTheme.typography.titleMedium,
modifier = Modifier
.padding(16.dp),
modifier = Modifier.padding(16.dp),
)
MultiSelectRemoteNodeList(
remoteNodes = remoteNodes,
selectedIds = selectedRemoteNodeIds,
modifier = Modifier
.padding(start = 16.dp),
modifier = Modifier.padding(start = 16.dp),
)
if (showRestoreOptions) {
Text(
text = "Deterministic wallet recovery",
style = MaterialTheme.typography.titleMedium,
modifier = Modifier
.padding(16.dp),
modifier = Modifier.padding(16.dp),
)
OutlinedTextField(
value = secretSpendKeyHex,
@ -217,8 +208,7 @@ private fun SecondStepScreen(
Text(
text = "Synchronization",
style = MaterialTheme.typography.titleMedium,
modifier = Modifier
.padding(16.dp),
modifier = Modifier.padding(16.dp),
)
OutlinedTextField(
value = creationDate,
@ -246,21 +236,47 @@ private fun SecondStepScreen(
}
Column(
modifier = Modifier
.fillMaxWidth(),
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
val validInput = !showRestoreOptions || !(secretSpendKeyHexError || creationDateError || restoreHeightError)
val validInput =
!showRestoreOptions || !(secretSpendKeyHexError || creationDateError || restoreHeightError)
Button(
onClick = onCreateClick,
onClick = {
if (selectedRemoteNodeIds.filterValues { checked -> checked }.isEmpty()) {
showOffLineConfirmationDialog = true
} else {
onCreateClick()
}
},
enabled = validInput,
modifier = Modifier
.padding(16.dp),
modifier = Modifier.padding(16.dp),
) {
Text("Finish")
}
}
}
if (showOffLineConfirmationDialog) {
AlertDialog(onDismissRequest = { showOffLineConfirmationDialog = false }, title = {
Text("No remote nodes selected")
}, text = {
Text("There are no remote nodes added to your wallet settings. Are you sure you want to start an offline wallet?")
}, confirmButton = {
TextButton(onClick = {
showOffLineConfirmationDialog = false
onCreateClick()
}) {
Text("Continue")
}
}, dismissButton = {
TextButton(onClick = {
showOffLineConfirmationDialog = false
}) {
Text("Cancel")
}
})
}
}
}

View File

@ -31,7 +31,7 @@ fun MultiSelectRemoteNodeList(
}
} else {
Text(
text = "No matching remote nodes",
text = "Empty list. Start by adding new remote nodes in the settings.",
style = MaterialTheme.typography.labelMedium,
)
}

View File

@ -19,7 +19,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import im.molly.monero.MoneroAmount
import im.molly.monero.Balance
import im.molly.monero.BlockchainTime