Skip to content

Commit bd359e5

Browse files
committed
fix(flipcash/session): correct airdrop timing and park a welcome bonus for presentation
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 3912d88 commit bd359e5

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ data object PutInWallet : BillDeterminationResult, ActedUpon
2121
interface SessionController {
2222
val state: StateFlow<SessionState>
2323
val billState: StateFlow<BillState>
24-
fun onAppInForeground(checkForAirdrops: Boolean = true)
24+
fun onAppInForeground()
2525
fun onAppInBackground()
2626
fun onCameraVisible()
2727
fun onCameraScanning(scanning: Boolean)

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class RealSessionController @Inject constructor(
108108

109109
private val scannedRendezvous = mutableListOf<String>()
110110

111+
private var welcomeBonus: LocalFiat? = null
112+
111113
init {
112114
userManager.state
113115
.map { it.isTimelockUnlocked }
@@ -118,7 +120,7 @@ class RealSessionController @Inject constructor(
118120
.mapNotNull { it.authState }
119121
.filter { it.canAccessAuthenticatedApis }
120122
.distinctUntilChanged()
121-
.onEach { onAppInForeground(false) }
123+
.onEach { onAppInForeground() }
122124
.launchIn(scope)
123125

124126
userManager.state
@@ -150,17 +152,15 @@ class RealSessionController @Inject constructor(
150152
* 6. Checks for any pending share actions via the share sheet.
151153
* 7. If the user is registered, connects to the billing client.
152154
*/
153-
override fun onAppInForeground(checkForAirdrops: Boolean) {
155+
override fun onAppInForeground() {
154156
trace(
155157
tag = "Session",
156158
message = "onAppInForeground",
157159
type = TraceType.Process,
158160
)
159161
startPolling()
160162
updateUserFlags()
161-
if (checkForAirdrops) {
162-
checkForAirdrops()
163-
}
163+
checkForAirdrops()
164164
checkPendingItemsInFeed()
165165
bringActivityFeedCurrent()
166166
shareSheetController.checkForShare()
@@ -215,15 +215,16 @@ class RealSessionController @Inject constructor(
215215
}
216216
}
217217

218-
private fun checkForAirdrops() {
218+
private fun checkForAirdrops(onAirdropReceived: (LocalFiat) -> Unit = {}) {
219219
if (userManager.authState.canAccessAuthenticatedApis) {
220220
scope.launch {
221221
userManager.accountCluster?.let {
222222
transactionController.airdrop(
223223
type = AirdropType.WelcomeBonus,
224224
destination = it.authority.keyPair
225225
).onSuccess { amount ->
226-
presentWelcomeBonus(amount)
226+
welcomeBonus = amount
227+
onAirdropReceived(amount)
227228
}
228229
}
229230
}
@@ -280,7 +281,14 @@ class RealSessionController @Inject constructor(
280281
}
281282

282283
override fun onCameraVisible() {
283-
checkForAirdrops()
284+
if (welcomeBonus != null) {
285+
presentWelcomeBonus(welcomeBonus!!)
286+
welcomeBonus = null
287+
} else {
288+
checkForAirdrops {
289+
presentWelcomeBonus(it)
290+
}
291+
}
284292
}
285293

286294
override fun onCameraScanning(scanning: Boolean) {

0 commit comments

Comments
 (0)