Skip to content

Commit b220206

Browse files
committed
fix: handle auth state consistency when requiresIapForRegistration is false
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent f7b6b47 commit b220206

File tree

10 files changed

+35
-50
lines changed

10 files changed

+35
-50
lines changed

apps/flipcash/app/src/main/kotlin/com/flipcash/app/internal/ui/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ internal fun App(
169169
userManager.authState
170170
) {
171171
if (codeNavigator.lastItem is MainRoot) return@LaunchedEffect
172-
if (userManager.authState !is AuthState.LoggedIn) {
172+
if (userManager.authState !is AuthState.LoggedInWithUser) {
173173
// reset login request here
174174
// if we are not currently logged in, then the deeplink
175175
// is most likely being processed in [MainRoot] during launch

apps/flipcash/app/src/main/kotlin/com/flipcash/app/internal/ui/navigation/MainRoot.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ import com.flipcash.services.internal.model.account.UserFlags
3636
import com.flipcash.services.user.AuthState
3737
import com.getcode.theme.CodeTheme
3838
import com.getcode.ui.theme.CodeCircularProgressIndicator
39-
import com.getcode.util.permissions.LocalPermissionChecker
40-
import com.getcode.util.permissions.PermissionChecker
4139
import com.getcode.utils.trace
4240
import dev.theolm.rinku.DeepLink
4341
import kotlinx.coroutines.delay
@@ -122,7 +120,7 @@ internal class MainRoot(private val deepLink: () -> DeepLink?) : Screen, Parcela
122120
showLogo = true
123121
}
124122

125-
AuthState.LoggedIn -> {
123+
AuthState.LoggedInWithUser -> {
126124
showLogo = false
127125
}
128126

@@ -167,7 +165,7 @@ internal class MainRoot(private val deepLink: () -> DeepLink?) : Screen, Parcela
167165
}
168166
}
169167

170-
AuthState.LoggedIn -> {
168+
AuthState.LoggedInWithUser -> {
171169
val screens = router.processDestination(deepLink())
172170

173171
screens.ifEmpty {

apps/flipcash/features/menu/src/main/kotlin/com/flipcash/app/menu/internal/MenuScreenViewModel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ internal class MenuScreenViewModel @Inject constructor(
7474

7575
init {
7676
userManager.state
77-
.filter { it.authState is AuthState.LoggedIn }
77+
.filter { it.authState is AuthState.LoggedInWithUser }
7878
.mapNotNull { it.flags }
7979
.map { it.isStaff }
8080
.onEach {
@@ -83,12 +83,12 @@ internal class MenuScreenViewModel @Inject constructor(
8383
}.launchIn(viewModelScope)
8484

8585
featureFlags.observeOverride()
86-
.filter { userManager.authState is AuthState.LoggedIn }
86+
.filter { userManager.authState is AuthState.LoggedInWithUser }
8787
.onEach { dispatchEvent(Event.OnBetaFeaturesUnlocked(it)) }
8888
.launchIn(viewModelScope)
8989

9090
featureFlags.observe()
91-
.filter { userManager.authState is AuthState.LoggedIn }
91+
.filter { userManager.authState is AuthState.LoggedInWithUser }
9292
.onEach { dispatchEvent(Event.OnFeatureFlagsUpdated(it)) }
9393
.launchIn(viewModelScope)
9494

apps/flipcash/features/scanner/src/main/kotlin/com/flipcash/app/scanner/internal/ui/components/ScannerNavigationBar.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,15 @@ internal fun ScannerNavigationBar(
7272
onClick = { onAction(ScannerDecorItem.Cash) }
7373
)
7474

75-
if (state.poolsOpen) {
76-
BottomBarAction(
77-
modifier = Modifier.weight(1f),
78-
label = stringResource(R.string.action_pool),
79-
painter = painterResource(R.drawable.ic_flipcash_pools),
80-
badgeCount = 0,
81-
onClick = { onAction(ScannerDecorItem.Pools) },
82-
toast = {}
83-
)
84-
}
75+
76+
BottomBarAction(
77+
modifier = Modifier.weight(1f),
78+
label = stringResource(R.string.action_pool),
79+
painter = painterResource(R.drawable.ic_flipcash_pools),
80+
badgeCount = 0,
81+
onClick = { onAction(ScannerDecorItem.Pools) },
82+
toast = {}
83+
)
8584

8685
BottomBarAction(
8786
modifier = Modifier.weight(1f),

apps/flipcash/shared/authentication/src/main/kotlin/com/flipcash/app/auth/AuthManager.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import com.bugsnag.android.Bugsnag
55
import com.flipcash.app.appsettings.AppSettingsCoordinator
66
import com.flipcash.app.auth.internal.credentials.LookupResult
77
import com.flipcash.app.auth.internal.credentials.PassphraseCredentialManager
8-
import com.flipcash.app.persistence.PersistenceProvider
98
import com.flipcash.app.auth.internal.extensions.token
109
import com.flipcash.app.featureflags.FeatureFlagController
10+
import com.flipcash.app.persistence.PersistenceProvider
1111
import com.flipcash.services.controllers.AccountController
1212
import com.flipcash.services.controllers.PushController
1313
import com.flipcash.services.user.AuthState
@@ -16,7 +16,6 @@ import com.flipcash.shared.authentication.BuildConfig
1616
import com.getcode.crypt.MnemonicPhrase
1717
import com.getcode.opencode.controllers.BalanceController
1818
import com.getcode.opencode.model.core.ID
19-
import com.getcode.utils.ErrorUtils
2019
import com.getcode.utils.TraceType
2120
import com.getcode.utils.trace
2221
import com.google.firebase.Firebase
@@ -75,7 +74,6 @@ class AuthManager @Inject constructor(
7574

7675
private suspend fun softLogin(entropyB64: String): Result<ID> {
7776
if (softLoginDisabled) return Result.failure(Throwable("Disabled"))
78-
println("entropyB64: $entropyB64")
7977
return login(entropyB64, isSoftLogin = true)
8078
}
8179

@@ -101,7 +99,9 @@ class AuthManager @Inject constructor(
10199
suspend fun onUserAccessKeySeen(): Result<Unit> {
102100
return credentialManager.onUserAccessKeySeen()
103101
.onSuccess {
104-
userManager.set(AuthState.Registered(true))
102+
if (userManager.authState !is AuthState.LoggedIn) {
103+
userManager.set(AuthState.Registered(true))
104+
}
105105
}.map { Unit }
106106
}
107107

@@ -116,7 +116,7 @@ class AuthManager @Inject constructor(
116116
return credentialManager.onAccountPurchased()
117117
.fold(
118118
onSuccess = {
119-
userManager.set(AuthState.LoggedIn)
119+
userManager.set(AuthState.LoggedInWithUser)
120120
accountController.getUserFlags()
121121
.onSuccess { userManager.set(it) }
122122
},
@@ -149,9 +149,8 @@ class AuthManager @Inject constructor(
149149

150150
accountController.getUserFlags()
151151
.onSuccess { flags ->
152-
println("flags: $flags")
153152
userManager.set(flags)
154-
userManager.set(if (flags.isRegistered) AuthState.LoggedIn else AuthState.Registered())
153+
userManager.set(if (flags.isRegistered) AuthState.LoggedInWithUser else AuthState.Registered())
155154
}.onFailure {
156155
taggedTrace("Failed to get user flags", type = TraceType.Error, cause = it)
157156
userManager.set(authState = AuthState.Registered())

apps/flipcash/shared/authentication/src/main/kotlin/com/flipcash/app/auth/internal/credentials/PassphraseCredentialManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class PassphraseCredentialManager @Inject constructor(
202202
val selectedMetadata = getSelectedMetadata()
203203
if (selectedMetadata != null && selectedMetadata.entropy == entropy) {
204204
storeMetadata(selectedMetadata, isSelected = true)
205-
updateUserManager(selectedMetadata.id, AuthState.LoggedIn)
205+
updateUserManager(selectedMetadata.id, AuthState.LoggedInWithUser)
206206
return Result.success(selectedMetadata)
207207
}
208208

apps/flipcash/shared/router/src/main/kotlin/com/flipcash/app/router/internal/AppRouter.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import com.flipcash.app.core.navigation.fragments
1010
import com.flipcash.app.router.Router
1111
import com.flipcash.services.user.AuthState
1212
import com.flipcash.services.user.UserManager
13-
import com.getcode.vendor.Base58
1413
import dev.theolm.rinku.DeepLink
1514
import kotlinx.coroutines.CoroutineScope
1615
import kotlinx.coroutines.Dispatchers
@@ -29,22 +28,22 @@ internal class AppRouter(
2928
val type = processType(deeplink) ?: return emptyList()
3029
when (type) {
3130
is DeeplinkType.Login -> {
32-
if (userManager.authState is AuthState.LoggedIn) {
31+
if (userManager.authState is AuthState.LoggedInWithUser) {
3332
listOf(ScreenRegistry.get(NavScreenProvider.HomeScreen.Scanner(type)))
3433
} else {
3534
listOf(ScreenRegistry.get(NavScreenProvider.Login.Home(type.entropy, true)))
3635
}
3736
}
3837
is DeeplinkType.CashLink -> {
39-
if (userManager.authState is AuthState.LoggedIn) {
38+
if (userManager.authState is AuthState.LoggedInWithUser) {
4039
listOf(ScreenRegistry.get(NavScreenProvider.HomeScreen.Scanner(type)))
4140
} else {
4241
listOf(ScreenRegistry.get(NavScreenProvider.Login.Home()))
4342
}
4443
}
4544

4645
is DeeplinkType.Pool -> {
47-
if (userManager.authState is AuthState.LoggedIn) {
46+
if (userManager.authState is AuthState.LoggedInWithUser) {
4847
listOf(ScreenRegistry.get(NavScreenProvider.HomeScreen.Scanner(type)))
4948
} else {
5049
listOf(ScreenRegistry.get(NavScreenProvider.Login.Home()))
@@ -79,7 +78,6 @@ internal class AppRouter(
7978

8079
pool.contains(deeplink.pathSegments[0]) -> {
8180
val seed = deeplink.data.toUri().fragments[Key.entropy] ?: return null
82-
println("seed=$seed")
8381
DeeplinkType.Pool(seed)
8482
}
8583
else -> null

apps/flipcash/shared/session/src/main/kotlin/com/flipcash/app/session/SessionController.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ interface SessionController {
3434
data class SessionState(
3535
val isCameraPermissionGranted: Boolean? = null,
3636
val vibrateOnScan: Boolean = false,
37-
val poolsOpen: Boolean = false,
3837
val balance: Fiat? = null,
3938
val logScanTimes: Boolean = false,
4039
val showNetworkOffline: Boolean = false,

apps/flipcash/shared/session/src/main/kotlin/com/flipcash/app/session/internal/RealSessionController.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ class RealSessionController @Inject constructor(
154154
.onEach { enabled -> _state.update { it.copy(vibrateOnScan = enabled) } }
155155
.launchIn(scope)
156156

157-
featureFlagController.observe(FeatureFlag.Pools)
158-
.onEach { enabled -> _state.update { it.copy(poolsOpen = enabled) } }
159-
.launchIn(scope)
160-
161157
poolsCoordinator.openPool
162158
.onEach { id ->
163159
if (id == null) {

services/flipcash/src/main/kotlin/com/flipcash/services/user/UserManager.kt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import com.flipcash.services.internal.model.account.UserFlags
55
import com.getcode.crypt.DerivePath
66
import com.getcode.crypt.DerivedKey
77
import com.getcode.crypt.MnemonicPhrase
8-
import com.getcode.opencode.controllers.AccountController
98
import com.getcode.opencode.controllers.BalanceController
109
import com.getcode.opencode.events.Events
1110
import com.getcode.opencode.model.accounts.AccountCluster
1211
import com.getcode.opencode.managers.MnemonicManager
13-
import com.getcode.opencode.model.accounts.AccountInfo
1412
import com.getcode.opencode.model.accounts.PoolAccount
1513
import com.getcode.opencode.model.core.ID
1614
import com.getcode.opencode.model.core.NoId
@@ -31,23 +29,25 @@ import javax.inject.Singleton
3129
sealed interface AuthState {
3230
// still to determine
3331
data object Unknown : AuthState
34-
// account has been created but not yet paid for
32+
// account has been created but not yet paid for (if required)
3533
// seenAccessKey used as a flag whether to land them back on
3634
// access key screen or purchase
3735
data class Registered(val seenAccessKey: Boolean = true) : AuthState
38-
// account has been created and paid for
36+
37+
sealed interface LoggedIn
38+
// account has been created and paid for (if required)
3939
// and we are waiting for metadata to be pulled from storage
40-
data object LoggedInAwaitingUser : AuthState
41-
// account is paid for and we ready for use in app
42-
data object LoggedIn : AuthState
40+
data object LoggedInAwaitingUser : AuthState, LoggedIn
41+
// account is paid for (if required) and is ready for use in app
42+
data object LoggedInWithUser : AuthState, LoggedIn
4343
// logged out
4444
data object LoggedOut : AuthState
4545

4646
val canAccessAuthenticatedApis: Boolean
47-
get() = this is LoggedIn
47+
get() = this is LoggedInWithUser
4848

4949
val isAtLeastRegistered: Boolean
50-
get() = this is LoggedIn || this is Registered
50+
get() = this is LoggedInWithUser || this is Registered
5151
}
5252

5353
@Singleton
@@ -79,9 +79,6 @@ class UserManager @Inject constructor(
7979
val authState: AuthState
8080
get() = _state.value.authState
8181

82-
val isRegistered: Boolean
83-
get() = _state.value.flags?.isRegistered == true
84-
8582
val nextPoolIndex: Long
8683
get() = _state.value.nextPoolIndex
8784

@@ -135,8 +132,7 @@ class UserManager @Inject constructor(
135132
_state.update { it.copy(authState = authState) }
136133

137134
when (authState) {
138-
AuthState.LoggedIn,
139-
AuthState.LoggedInAwaitingUser -> {
135+
is AuthState.LoggedIn -> {
140136
accountCluster?.let { owner ->
141137
eventBus.send(Events.UpdateLimits(owner = owner, force = true))
142138
}

0 commit comments

Comments
 (0)