refactor: remove excessive logging and improve code clarity in various components

This commit is contained in:
2026-02-05 03:45:24 +05:00
parent a3549e1793
commit f5a8070aa9
8 changed files with 42 additions and 62 deletions

View File

@@ -82,23 +82,17 @@ private suspend fun performUnlock(
}
onUnlocking(true)
android.util.Log.d(TAG, "🔓 Starting unlock for account: ${selectedAccount.name}")
try {
val account = selectedAccount.encryptedAccount
// Try to decrypt private key
val decryptStart = System.currentTimeMillis()
android.util.Log.d(TAG, "🔐 Decrypting private key (PBKDF2)...")
val decryptedPrivateKey = CryptoManager.decryptWithPassword(
val decryptedPrivateKey = CryptoManager.decryptWithPassword(
account.encryptedPrivateKey,
password
)
val decryptPrivateKeyTime = System.currentTimeMillis() - decryptStart
android.util.Log.d(TAG, "🔐 Private key decrypted in ${decryptPrivateKeyTime}ms")
if (decryptedPrivateKey == null) {
android.util.Log.w(TAG, "❌ Decryption failed - incorrect password")
onError("Incorrect password")
onUnlocking(false)
return
@@ -106,21 +100,15 @@ private suspend fun performUnlock(
// Decrypt seed phrase
val seedStart = System.currentTimeMillis()
android.util.Log.d(TAG, "🌱 Decrypting seed phrase...")
val decryptedSeedPhrase = CryptoManager.decryptWithPassword(
account.encryptedSeedPhrase,
password
)?.split(" ") ?: emptyList()
val seedTime = System.currentTimeMillis() - seedStart
android.util.Log.d(TAG, "🌱 Seed phrase decrypted in ${seedTime}ms")
// Generate private key hash
val hashStart = System.currentTimeMillis()
android.util.Log.d(TAG, "🔑 Generating private key hash...")
val privateKeyHash = CryptoManager.generatePrivateKeyHash(decryptedPrivateKey)
val hashTime = System.currentTimeMillis() - hashStart
android.util.Log.d(TAG, "🔑 Hash generated in ${hashTime}ms")
val decryptedAccount = DecryptedAccount(
publicKey = account.publicKey,
privateKey = decryptedPrivateKey,
@@ -131,7 +119,6 @@ private suspend fun performUnlock(
// Connect to server
val connectStart = System.currentTimeMillis()
android.util.Log.d(TAG, "🌐 Connecting to server...")
ProtocolManager.connect()
// Wait for websocket connection
@@ -141,10 +128,7 @@ private suspend fun performUnlock(
waitAttempts++
}
val connectTime = System.currentTimeMillis() - connectStart
android.util.Log.d(TAG, "🌐 Connected in ${connectTime}ms (attempts: $waitAttempts)")
if (ProtocolManager.state.value == ProtocolState.DISCONNECTED) {
android.util.Log.e(TAG, "❌ Connection failed after $waitAttempts attempts")
if (ProtocolManager.state.value == ProtocolState.DISCONNECTED) {
onError("Failed to connect to server")
onUnlocking(false)
return
@@ -154,20 +138,13 @@ private suspend fun performUnlock(
// Authenticate
val authStart = System.currentTimeMillis()
android.util.Log.d(TAG, "🔒 Authenticating...")
ProtocolManager.authenticate(account.publicKey, privateKeyHash)
val authTime = System.currentTimeMillis() - authStart
android.util.Log.d(TAG, "🔒 Auth request sent in ${authTime}ms")
accountManager.setCurrentAccount(account.publicKey)
val totalTime = System.currentTimeMillis() - totalStart
android.util.Log.d(TAG, "✅ UNLOCK COMPLETE in ${totalTime}ms")
android.util.Log.d(TAG, " 📊 Breakdown: privateKey=${decryptPrivateKeyTime}ms, seed=${seedTime}ms, hash=${hashTime}ms, connect=${connectTime}ms, auth=${authTime}ms")
onSuccess(decryptedAccount)
} catch (e: Exception) {
android.util.Log.e(TAG, "❌ Unlock failed: ${e.message}", e)
onError("Failed to unlock: ${e.message}")
onUnlocking(false)
}