mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 03:18:23 +00:00
login redesign
This commit is contained in:
@@ -52,6 +52,8 @@ private object PrefKeys {
|
||||
const val USE_AUTH = "use_auth"
|
||||
const val BIOMETRICS_TYPE = "biometrics_type"
|
||||
const val LAST_BIOMETRICS_TIME = "last_biometrics_time"
|
||||
const val SIGN_POLICY = "sign_policy"
|
||||
const val SEED_WORDS = "seed_words"
|
||||
}
|
||||
|
||||
@Immutable
|
||||
@@ -285,6 +287,8 @@ object LocalPreferences {
|
||||
putString(PrefKeys.ACCOUNT_NAME, account.name)
|
||||
putString(PrefKeys.LANGUAGE_PREFS, account.language)
|
||||
putBoolean(PrefKeys.ALLOW_NEW_CONNECTIONS, account.allowNewConnections)
|
||||
putInt(PrefKeys.SIGN_POLICY, account.signPolicy)
|
||||
putStringSet(PrefKeys.SEED_WORDS, account.seedWords.toSet())
|
||||
}.apply()
|
||||
}
|
||||
|
||||
@@ -428,6 +432,8 @@ object LocalPreferences {
|
||||
val proxy = HttpClientManager.initProxy(useProxy, "127.0.0.1", proxyPort)
|
||||
val language = getString(PrefKeys.LANGUAGE_PREFS, null)
|
||||
val allowNewConnections = getBoolean(PrefKeys.ALLOW_NEW_CONNECTIONS, false)
|
||||
val signPolicy = getInt(PrefKeys.SIGN_POLICY, 0)
|
||||
val seedWords = getStringSet(PrefKeys.SEED_WORDS, null) ?: emptySet()
|
||||
HttpClientManager.setDefaultProxy(proxy)
|
||||
val account =
|
||||
Account(
|
||||
@@ -437,6 +443,8 @@ object LocalPreferences {
|
||||
proxyPort = proxyPort,
|
||||
language = language,
|
||||
allowNewConnections = allowNewConnections,
|
||||
signPolicy = signPolicy,
|
||||
seedWords = seedWords,
|
||||
)
|
||||
accountCache.put(npub, account)
|
||||
return account
|
||||
|
||||
@@ -17,6 +17,8 @@ class Account(
|
||||
var proxyPort: Int,
|
||||
var language: String?,
|
||||
var allowNewConnections: Boolean,
|
||||
var signPolicy: Int,
|
||||
var seedWords: Set<String>,
|
||||
) {
|
||||
val saveable: AccountLiveData = AccountLiveData(this)
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ fun AccountScreen(
|
||||
) { state ->
|
||||
when (state) {
|
||||
is AccountState.LoggedOff -> {
|
||||
LoginPage(accountStateViewModel)
|
||||
MainLoginPage(accountStateViewModel)
|
||||
}
|
||||
is AccountState.LoggedIn -> {
|
||||
var intentData by remember {
|
||||
|
||||
@@ -108,26 +108,121 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
tryLoginExistingAccount(route, npub)
|
||||
}
|
||||
|
||||
fun isValidKey(key: String, password: String): Boolean {
|
||||
try {
|
||||
val account =
|
||||
if (key.startsWith("ncryptsec")) {
|
||||
val newKey =
|
||||
CryptoUtils.decryptNIP49(key, password)
|
||||
?: throw Exception("Could not decrypt key with provided password")
|
||||
Account(
|
||||
KeyPair(Hex.decode(newKey)),
|
||||
name = "",
|
||||
useProxy = false,
|
||||
proxyPort = 0,
|
||||
language = null,
|
||||
allowNewConnections = false,
|
||||
signPolicy = 0,
|
||||
seedWords = emptySet(),
|
||||
)
|
||||
} else if (key.startsWith("nsec")) {
|
||||
Account(
|
||||
KeyPair(privKey = key.bechToBytes()),
|
||||
name = "",
|
||||
useProxy = false,
|
||||
proxyPort = 0,
|
||||
language = null,
|
||||
allowNewConnections = false,
|
||||
signPolicy = 0,
|
||||
seedWords = emptySet(),
|
||||
)
|
||||
} else if (key.contains(" ") && CryptoUtils.isValidMnemonic(key)) {
|
||||
val keyPair = KeyPair(privKey = CryptoUtils.privateKeyFromMnemonic(key))
|
||||
Account(
|
||||
keyPair,
|
||||
name = "",
|
||||
useProxy = false,
|
||||
proxyPort = 0,
|
||||
language = null,
|
||||
allowNewConnections = false,
|
||||
signPolicy = 0,
|
||||
seedWords = emptySet(),
|
||||
)
|
||||
} else {
|
||||
Account(
|
||||
KeyPair(Hex.decode(key)),
|
||||
name = "",
|
||||
useProxy = false,
|
||||
proxyPort = 0,
|
||||
language = null,
|
||||
allowNewConnections = false,
|
||||
signPolicy = 0,
|
||||
seedWords = emptySet(),
|
||||
)
|
||||
}
|
||||
return account.keyPair.privKey != null
|
||||
} catch (e: Exception) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
fun startUI(
|
||||
key: String,
|
||||
password: String,
|
||||
route: String?,
|
||||
useProxy: Boolean,
|
||||
proxyPort: Int,
|
||||
signPolicy: Int,
|
||||
) {
|
||||
val account =
|
||||
if (key.startsWith("ncryptsec")) {
|
||||
val newKey =
|
||||
CryptoUtils.decryptNIP49(key, password)
|
||||
?: throw Exception("Could not decrypt key with provided password")
|
||||
Account(KeyPair(Hex.decode(newKey)), name = "", useProxy = useProxy, proxyPort = proxyPort, language = null, allowNewConnections = false)
|
||||
Account(
|
||||
KeyPair(Hex.decode(newKey)),
|
||||
name = "",
|
||||
useProxy = useProxy,
|
||||
proxyPort = proxyPort,
|
||||
language = null,
|
||||
allowNewConnections = false,
|
||||
signPolicy = signPolicy,
|
||||
seedWords = emptySet(),
|
||||
)
|
||||
} else if (key.startsWith("nsec")) {
|
||||
Account(KeyPair(privKey = key.bechToBytes()), name = "", useProxy = useProxy, proxyPort = proxyPort, language = null, allowNewConnections = false)
|
||||
Account(
|
||||
KeyPair(privKey = key.bechToBytes()),
|
||||
name = "",
|
||||
useProxy = useProxy,
|
||||
proxyPort = proxyPort,
|
||||
language = null,
|
||||
allowNewConnections = false,
|
||||
signPolicy = signPolicy,
|
||||
seedWords = emptySet(),
|
||||
)
|
||||
} else if (key.contains(" ") && CryptoUtils.isValidMnemonic(key)) {
|
||||
val keyPair = KeyPair(privKey = CryptoUtils.privateKeyFromMnemonic(key))
|
||||
Account(keyPair, name = "", useProxy = useProxy, proxyPort = proxyPort, language = null, allowNewConnections = false)
|
||||
Account(
|
||||
keyPair,
|
||||
name = "",
|
||||
useProxy = useProxy,
|
||||
proxyPort = proxyPort,
|
||||
language = null,
|
||||
allowNewConnections = false,
|
||||
signPolicy = signPolicy,
|
||||
seedWords = emptySet(),
|
||||
)
|
||||
} else {
|
||||
Account(KeyPair(Hex.decode(key)), name = "", useProxy = useProxy, proxyPort = proxyPort, language = null, allowNewConnections = false)
|
||||
Account(
|
||||
KeyPair(Hex.decode(key)),
|
||||
name = "",
|
||||
useProxy = useProxy,
|
||||
proxyPort = proxyPort,
|
||||
language = null,
|
||||
allowNewConnections = false,
|
||||
signPolicy = signPolicy,
|
||||
seedWords = emptySet(),
|
||||
)
|
||||
}
|
||||
|
||||
LocalPreferences.updatePrefsForLogin(NostrSigner.getInstance(), account)
|
||||
@@ -137,8 +232,19 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
fun newKey(
|
||||
useProxy: Boolean,
|
||||
proxyPort: Int,
|
||||
signPolicy: Int,
|
||||
seedWords: Set<String>,
|
||||
) {
|
||||
val account = Account(KeyPair(), name = "", useProxy = useProxy, proxyPort = proxyPort, language = null, allowNewConnections = false)
|
||||
val account = Account(
|
||||
KeyPair(),
|
||||
name = "",
|
||||
useProxy = useProxy,
|
||||
proxyPort = proxyPort,
|
||||
language = null,
|
||||
allowNewConnections = false,
|
||||
signPolicy = signPolicy,
|
||||
seedWords = seedWords,
|
||||
)
|
||||
LocalPreferences.updatePrefsForLogin(NostrSigner.getInstance(), account)
|
||||
startUI(account, null)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -47,7 +47,7 @@ import com.greenart7c3.nostrsigner.R
|
||||
import com.greenart7c3.nostrsigner.models.Account
|
||||
import com.greenart7c3.nostrsigner.service.toShortenHex
|
||||
import com.greenart7c3.nostrsigner.ui.AccountStateViewModel
|
||||
import com.greenart7c3.nostrsigner.ui.LoginPage
|
||||
import com.greenart7c3.nostrsigner.ui.MainLoginPage
|
||||
import com.greenart7c3.nostrsigner.ui.components.ActiveMarker
|
||||
import com.greenart7c3.nostrsigner.ui.components.CloseButton
|
||||
import com.greenart7c3.nostrsigner.ui.components.PostButton
|
||||
@@ -165,7 +165,7 @@ fun AccountsBottomSheet(
|
||||
) {
|
||||
Surface(modifier = Modifier.fillMaxSize()) {
|
||||
Box {
|
||||
LoginPage(accountStateViewModel)
|
||||
MainLoginPage(accountStateViewModel)
|
||||
TopAppBar(
|
||||
title = { Text(text = stringResource(R.string.add_new_account)) },
|
||||
navigationIcon = {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<string name="invalid_key">Invalid key</string>
|
||||
<string name="key_is_required">Key is required</string>
|
||||
<string name="login">Login</string>
|
||||
<string name="generate_a_new_key">Generate a new key</string>
|
||||
<string name="generate_a_new_key">Create a key</string>
|
||||
<string name="backup_keys">Backup Keys</string>
|
||||
<string name="read_your_public_key">Read your public key</string>
|
||||
<string name="no_permissions_granted">No permissions granted</string>
|
||||
@@ -335,4 +335,16 @@
|
||||
<string name="nip_not_found">Nip %1$s not found</string>
|
||||
<string name="nip_not_found_for_the_event_kind">Nip not found for the event kind %1$s</string>
|
||||
<string name="use_secret_to_connect_to_the_application">Use secret to connect to the application</string>
|
||||
<string name="add_a_key">Add a key</string>
|
||||
<string name="next">Next</string>
|
||||
<string name="add_your_key">Add your key</string>
|
||||
<string name="sign_policy_basic">Approve basic actions</string>
|
||||
<string name="sign_policy_basic_explainer">Recommended for most people. This will minimize the number of interruptions during your app usage.</string>
|
||||
<string name="sign_policy_manual">Manually approve each app</string>
|
||||
<string name="sign_policy_manual_explainer">Recommended for privacy-minded people who would like control over each app. Choosing this will prompt you set a preference every time you try a new app.</string>
|
||||
<string name="sign_policy_title">Select a signing policy</string>
|
||||
<string name="sign_policy_explainer">Should I approve nostr events automatically or would you like to review them for each app?</string>
|
||||
<string name="finish">Finish</string>
|
||||
<string name="seed_words_title">Your recovery phrase</string>
|
||||
<string name="seed_words_explainer">These words let you recreate your account in case you lose access. Write them down in a safe place</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user