Fix account switching

This commit is contained in:
maxmoney21m 2023-03-12 14:27:34 +08:00
parent 269197a59d
commit f34d79106d
3 changed files with 15 additions and 2 deletions

View File

@ -83,6 +83,10 @@ object LocalPreferences {
addAccount(npub)
}
fun switchToAccount(npub: String) {
currentAccount = npub
}
/**
* Removes the account from the app level shared preferences
*/

View File

@ -86,7 +86,7 @@ fun AccountSwitchBottomSheet(
) {
Row(
modifier = Modifier.clickable {
accountStateViewModel.login(acc.npub)
accountStateViewModel.switchUser(acc.npub)
},
verticalAlignment = Alignment.CenterVertically
) {

View File

@ -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()
}