feat: Add paste functionality for seed phrase confirmation with success message

This commit is contained in:
k1ngsterr1
2026-01-09 01:55:43 +05:00
parent 3ae544dac2
commit 634d3094e3

View File

@@ -1,5 +1,7 @@
package com.rosetta.messenger.ui.auth
import android.content.ClipboardManager
import android.content.Context
import androidx.compose.animation.*
import androidx.compose.animation.core.*
import androidx.compose.foundation.*
@@ -16,6 +18,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
@@ -50,6 +53,7 @@ fun ConfirmSeedPhraseScreen(
val backgroundColor = if (isDarkTheme) Color(0xFF1E1E1E) else Color(0xFFFFFFFF)
val textColor = if (isDarkTheme) Color.White else Color.Black
val secondaryTextColor = if (isDarkTheme) Color(0xFF8E8E93) else Color(0xFF666666)
val context = LocalContext.current
// Select 4 words at fixed positions to confirm (2, 5, 9, 12)
val wordsToConfirm = remember {
@@ -59,6 +63,56 @@ fun ConfirmSeedPhraseScreen(
var userInputs by remember { mutableStateOf(List(12) { "" }) }
var showError by remember { mutableStateOf(false) }
var visible by remember { mutableStateOf(false) }
var showPasteSuccess by remember { mutableStateOf(false) }
// Function to handle paste from clipboard
val handlePaste: () -> Unit = {
try {
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = clipboard.primaryClip
if (clipData != null && clipData.itemCount > 0) {
val pastedText = clipData.getItemAt(0).text?.toString() ?: ""
// Split by spaces, commas, or newlines and filter empty strings
val pastedWords = pastedText
.split(Regex("\\s+|,|\\n"))
.map { it.trim().lowercase() }
.filter { it.isNotEmpty() }
if (pastedWords.size >= 12) {
// Fill all 12 words
userInputs = pastedWords.take(12)
showPasteSuccess = true
showError = false
} else if (pastedWords.isNotEmpty()) {
// Fill only the required input fields with available words
val newInputs = userInputs.toMutableList()
var pasteIndex = 0
wordsToConfirm.forEach { (index, _) ->
if (pasteIndex < pastedWords.size) {
newInputs[index] = pastedWords[pasteIndex]
pasteIndex++
}
}
userInputs = newInputs
showPasteSuccess = pasteIndex > 0
showError = false
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
// Hide success message after delay
LaunchedEffect(showPasteSuccess) {
if (showPasteSuccess) {
kotlinx.coroutines.delay(2000)
showPasteSuccess = false
}
}
LaunchedEffect(Unit) {
visible = true
@@ -86,11 +140,30 @@ fun ConfirmSeedPhraseScreen(
modifier = Modifier
.fillMaxWidth()
.padding(4.dp),
verticalAlignment = Alignment.CenterVertically
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
IconButton(onClick = onBack) {
Icon(Icons.Default.ArrowBack, "Back", tint = textColor)
}
// Paste button
OutlinedButton(
onClick = handlePaste,
modifier = Modifier.height(40.dp),
colors = ButtonDefaults.outlinedButtonColors(
contentColor = PrimaryBlue
),
border = BorderStroke(1.dp, PrimaryBlue)
) {
Icon(
Icons.Default.ContentPaste,
contentDescription = "Paste",
modifier = Modifier.size(18.dp)
)
Spacer(modifier = Modifier.width(6.dp))
Text("Paste", fontSize = 14.sp)
}
}
Column(
@@ -136,6 +209,42 @@ fun ConfirmSeedPhraseScreen(
)
}
// Paste success message
AnimatedVisibility(
visible = showPasteSuccess,
enter = fadeIn(tween(300)) + scaleIn(initialScale = 0.9f),
exit = fadeOut(tween(300))
) {
Column {
Spacer(modifier = Modifier.height(12.dp))
Card(
colors = CardDefaults.cardColors(
containerColor = Color(0xFF4CAF50).copy(alpha = 0.15f)
),
shape = RoundedCornerShape(8.dp)
) {
Row(
modifier = Modifier.padding(12.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
Icons.Default.CheckCircle,
contentDescription = null,
tint = Color(0xFF4CAF50),
modifier = Modifier.size(20.dp)
)
Spacer(modifier = Modifier.width(8.dp))
Text(
text = "Words pasted successfully!",
fontSize = 14.sp,
color = Color(0xFF4CAF50),
fontWeight = FontWeight.Medium
)
}
}
}
}
Spacer(modifier = Modifier.height(32.dp))
// Two column layout like SeedPhraseScreen