added keyguard to qr code encrypted key export
This commit is contained in:
+56
@@ -342,6 +342,54 @@ private fun QrCodeButton(accountViewModel: AccountViewModel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun QrCodeButtonEncrypted(
|
||||||
|
accountViewModel: AccountViewModel,
|
||||||
|
password: MutableState<TextFieldValue>,
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
// store the dialog open or close state
|
||||||
|
var dialogOpen by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
val keyguardLauncher =
|
||||||
|
rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
|
||||||
|
if (result.resultCode == Activity.RESULT_OK) {
|
||||||
|
dialogOpen = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IconButton(
|
||||||
|
enabled = password.value.text.isNotBlank(),
|
||||||
|
onClick = {
|
||||||
|
authenticate(
|
||||||
|
title = stringRes(context, R.string.copy_my_secret_key),
|
||||||
|
context = context,
|
||||||
|
keyguardLauncher = keyguardLauncher,
|
||||||
|
onApproved = { dialogOpen = true },
|
||||||
|
onError = { title, message -> accountViewModel.toast(title, message) },
|
||||||
|
)
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(R.drawable.ic_qrcode),
|
||||||
|
contentDescription = stringRes(id = R.string.show_npub_as_a_qr_code),
|
||||||
|
modifier = Modifier.size(24.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dialogOpen) {
|
||||||
|
val key =
|
||||||
|
accountViewModel.account.settings.keyPair.privKey
|
||||||
|
?.toHexKey()
|
||||||
|
?.let { CryptoUtils.encryptNIP49(it, password.value.text) }
|
||||||
|
ShowKeyQRDialog(
|
||||||
|
key,
|
||||||
|
onClose = { dialogOpen = false },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun NSecCopyButton(accountViewModel: AccountViewModel) {
|
private fun NSecCopyButton(accountViewModel: AccountViewModel) {
|
||||||
val clipboardManager = LocalClipboardManager.current
|
val clipboardManager = LocalClipboardManager.current
|
||||||
@@ -403,6 +451,8 @@ private fun EncryptNSecCopyButton(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Row {
|
||||||
|
Column {
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
modifier = Modifier.padding(horizontal = 3.dp),
|
modifier = Modifier.padding(horizontal = 3.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
@@ -430,6 +480,12 @@ private fun EncryptNSecCopyButton(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Column {
|
||||||
|
QrCodeButtonEncrypted(accountViewModel, password)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun Context.getFragmentActivity(): FragmentActivity? {
|
fun Context.getFragmentActivity(): FragmentActivity? {
|
||||||
var currentContext = this
|
var currentContext = this
|
||||||
while (currentContext is ContextWrapper) {
|
while (currentContext is ContextWrapper) {
|
||||||
|
|||||||
Reference in New Issue
Block a user