Skip to content

Commit 80917c9

Browse files
committed
fix: remove dedupe window and consolidate auth state change handling to better coalesce log out operations
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent e051ab0 commit 80917c9

2 files changed

Lines changed: 13 additions & 28 deletions

File tree

  • apps/flipcash

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ internal fun App(
166166
transitionSpec = {
167167
val shouldCrossfade = initialState.key == AppRoute.Loading.toString() ||
168168
targetState.key == AppRoute.Loading.toString() ||
169-
initialState.key.toString().startsWith("Login") ||
170169
targetState.key.toString().startsWith("Login")
171170
when {
172171
shouldCrossfade -> fadeIn(tween(300)) togetherWith fadeOut(tween(300))
@@ -179,7 +178,6 @@ internal fun App(
179178
popTransitionSpec = {
180179
val shouldCrossfade = initialState.key == AppRoute.Loading.toString() ||
181180
targetState.key == AppRoute.Loading.toString() ||
182-
initialState.key.toString().startsWith("Login") ||
183181
targetState.key.toString().startsWith("Login")
184182
when {
185183
shouldCrossfade -> fadeIn(tween(300)) togetherWith fadeOut(tween(300))
@@ -192,7 +190,6 @@ internal fun App(
192190
predictivePopTransitionSpec = {
193191
val shouldCrossfade = initialState.key == AppRoute.Loading.toString() ||
194192
targetState.key == AppRoute.Loading.toString() ||
195-
initialState.key.toString().startsWith("Login") ||
196193
targetState.key.toString().startsWith("Login")
197194
when {
198195
shouldCrossfade -> fadeIn(tween(300)) togetherWith fadeOut(tween(300))

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

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import kotlinx.coroutines.flow.StateFlow
6565
import kotlinx.coroutines.flow.asStateFlow
6666
import kotlinx.coroutines.flow.distinctUntilChanged
6767
import kotlinx.coroutines.flow.filter
68-
import kotlinx.coroutines.flow.filterIsInstance
6968
import kotlinx.coroutines.flow.launchIn
7069
import kotlinx.coroutines.flow.map
7170
import kotlinx.coroutines.flow.mapNotNull
@@ -136,33 +135,30 @@ class RealSessionController @Inject constructor(
136135

137136
private val scannedRendezvous = mutableMapOf<String, Long>()
138137

139-
@Volatile
140-
private var lastForegroundTimestamp = 0L
141-
142138
private val giftCardClaimInProgress = MutableStateFlow<String?>(null)
143139

144140
init {
145-
// reset state on logouts
141+
// handle auth state transitions: cleanup on logout, start polling on login
146142
userManager.state
147143
.map { it.authState }
148-
.filterIsInstance<AuthState.LoggedOut>()
149-
.onEach {
150-
_state.update { SessionState() }
151-
lastForegroundTimestamp = 0L
144+
.distinctUntilChanged()
145+
.onEach { authState ->
146+
when {
147+
authState is AuthState.LoggedOut -> {
148+
stopPolling()
149+
_state.update { SessionState() }
150+
}
151+
authState.canAccessAuthenticatedApis -> {
152+
onAppInForeground()
153+
}
154+
}
152155
}.launchIn(scope)
153156

154157
userManager.state
155158
.map { it.isTimelockUnlocked }
156159
.onEach { _state.update { it.copy(restrictionType = RestrictionType.TIMELOCK_UNLOCKED) } }
157160
.launchIn(scope)
158161

159-
userManager.state
160-
.mapNotNull { it.authState }
161-
.filter { it.canAccessAuthenticatedApis }
162-
.distinctUntilChanged()
163-
.onEach { onAppInForeground() }
164-
.launchIn(scope)
165-
166162
userManager.state
167163
.mapNotNull { it.authState }
168164
.filter { it.isAtLeastRegistered }
@@ -204,13 +200,6 @@ class RealSessionController @Inject constructor(
204200
* 7. If the user is registered, connects to the billing client.
205201
*/
206202
override fun onAppInForeground() {
207-
val now = Clock.System.now().toEpochMilliseconds()
208-
if (now - lastForegroundTimestamp < FOREGROUND_DEDUP_WINDOW_MS) {
209-
trace(tag = "Session", message = "onAppInForeground skipped (dedup)", type = TraceType.Process)
210-
return
211-
}
212-
lastForegroundTimestamp = now
213-
214203
trace(
215204
tag = "Session",
216205
message = "onAppInForeground",
@@ -868,5 +857,4 @@ class RealSessionController @Inject constructor(
868857
}
869858

870859
private val AIRDROP_INITIAL_DELAY = 1.seconds
871-
private val CASH_LINK_CONFIRMATION_DELAY = 500.milliseconds
872-
private const val FOREGROUND_DEDUP_WINDOW_MS = 2_000L
860+
private val CASH_LINK_CONFIRMATION_DELAY = 500.milliseconds

0 commit comments

Comments
 (0)