Try to change account when theres a incoming request

This commit is contained in:
greenart7c3
2024-10-30 14:41:33 -03:00
parent 4bb5af78f6
commit 1b17dc9061
@@ -40,8 +40,11 @@ import com.greenart7c3.nostrsigner.ui.AccountScreen
import com.greenart7c3.nostrsigner.ui.AccountStateViewModel
import com.greenart7c3.nostrsigner.ui.BiometricsTimeType
import com.greenart7c3.nostrsigner.ui.components.RandomPinInput
import com.greenart7c3.nostrsigner.ui.navigation.Route
import com.greenart7c3.nostrsigner.ui.theme.NostrSignerTheme
import com.vitorpamplona.ammolite.service.HttpClientManager
import com.vitorpamplona.quartz.encoders.toNpub
import fr.acinq.secp256k1.Hex
import java.time.Duration
import java.time.Instant
import kotlinx.coroutines.Dispatchers
@@ -211,6 +214,17 @@ class MainActivity : AppCompatActivity() {
}
LaunchedEffect(Unit) {
launch(Dispatchers.IO) {
val currentAccount = LocalPreferences.currentAccount(context)
if (currentAccount != null && npub != null && currentAccount != npub) {
if (npub.startsWith("npub")) {
accountStateViewModel.switchUser(npub, Route.IncomingRequest.route)
} else {
val localNpub = Hex.decode(npub).toNpub()
accountStateViewModel.switchUser(localNpub, Route.IncomingRequest.route)
}
}
}
launch {
IntentUtils.state
.receiveAsFlow()