mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-06-03 22:49:20 +02:00
Fix account switching
This commit is contained in:
parent
269197a59d
commit
f34d79106d
@ -83,6 +83,10 @@ object LocalPreferences {
|
||||
addAccount(npub)
|
||||
}
|
||||
|
||||
fun switchToAccount(npub: String) {
|
||||
currentAccount = npub
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the account from the app level shared preferences
|
||||
*/
|
||||
|
@ -86,7 +86,7 @@ fun AccountSwitchBottomSheet(
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.clickable {
|
||||
accountStateViewModel.login(acc.npub)
|
||||
accountStateViewModel.switchUser(acc.npub)
|
||||
},
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
|
@ -55,6 +55,12 @@ class AccountStateViewModel() : ViewModel() {
|
||||
login(account)
|
||||
}
|
||||
|
||||
fun switchUser(npub: String) {
|
||||
prepareLogoutOrSwitch()
|
||||
LocalPreferences.switchToAccount(npub)
|
||||
tryLoginExistingAccount()
|
||||
}
|
||||
|
||||
fun newKey() {
|
||||
val account = Account(Persona())
|
||||
LocalPreferences.updatePrefsForLogin(account)
|
||||
@ -86,7 +92,7 @@ class AccountStateViewModel() : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun logOff(npub: String) {
|
||||
private fun prepareLogoutOrSwitch() {
|
||||
val state = accountContent.value
|
||||
|
||||
when (state) {
|
||||
@ -104,7 +110,10 @@ class AccountStateViewModel() : ViewModel() {
|
||||
}
|
||||
|
||||
_accountContent.update { AccountState.LoggedOff }
|
||||
}
|
||||
|
||||
fun logOff(npub: String) {
|
||||
prepareLogoutOrSwitch()
|
||||
LocalPreferences.updatePrefsForLogout(npub)
|
||||
tryLoginExistingAccount()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user