Skip to content

Commit b774c59

Browse files
committed
fix(flipcash): reset bill and share confirmation when background app when applicable
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent accc332 commit b774c59

5 files changed

Lines changed: 52 additions & 11 deletions

File tree

apps/flipcash/features/scanner/src/main/kotlin/com/flipcash/app/scanner/internal/bills/BillContainerView.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import android.app.Activity
55
import androidx.activity.compose.BackHandler
66
import androidx.compose.animation.AnimatedVisibility
77
import androidx.compose.animation.EnterExitState
8+
import androidx.compose.animation.EnterTransition
9+
import androidx.compose.animation.ExitTransition
810
import androidx.compose.animation.core.tween
911
import androidx.compose.animation.fadeIn
1012
import androidx.compose.animation.fadeOut
@@ -195,14 +197,14 @@ internal fun BillContainer(
195197
contentPadding = PaddingValues(bottom = managementHeight),
196198
bill = updatedBillState.bill,
197199
transitionSpec = {
198-
if (updatedState.presentationStyle is PresentationStyle.Slide) {
199-
AnimationUtils.animationBillEnterGive
200-
} else {
201-
AnimationUtils.animationBillEnterGrabbed
202-
} togetherWith if (updatedState.presentationStyle is PresentationStyle.Slide) {
203-
AnimationUtils.animationBillExitReturned
204-
} else {
205-
AnimationUtils.animationBillExitGrabbed
200+
when (updatedState.presentationStyle) {
201+
PresentationStyle.Hidden -> EnterTransition.None
202+
PresentationStyle.Pop -> AnimationUtils.animationBillEnterGrabbed
203+
PresentationStyle.Slide -> AnimationUtils.animationBillEnterGive
204+
} togetherWith when (updatedState.presentationStyle) {
205+
PresentationStyle.Hidden -> ExitTransition.None
206+
PresentationStyle.Pop -> AnimationUtils.animationBillExitGrabbed
207+
PresentationStyle.Slide -> AnimationUtils.animationBillExitReturned
206208
}
207209
}
208210
)

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ class RealSessionController @Inject constructor(
131131
.launchIn(scope)
132132
}
133133

134+
/**
135+
* Called when the app enters the foreground.
136+
*
137+
* This function performs several actions to ensure the app is up-to-date and ready for user interaction:
138+
* 1. Starts polling for updates (e.g., balance, exchange rates, activity feed).
139+
* 2. Updates user flags.
140+
* 3. Requests an airdrop if applicable.
141+
* 4. Checks for pending items in the activity feed.
142+
* 5. Brings the activity feed to the current state.
143+
* 6. Checks for any pending share actions via the share sheet.
144+
* 7. If the user is registered, connects to the billing client.
145+
*/
134146
override fun onAppInForeground() {
135147
trace(
136148
tag = "Session",
@@ -143,11 +155,32 @@ class RealSessionController @Inject constructor(
143155
checkPendingItemsInFeed()
144156
bringActivityFeedCurrent()
145157
shareSheetController.checkForShare()
158+
if (userManager.authState.isAtLeastRegistered) {
159+
billingClient.connect()
160+
}
146161
}
147162

163+
/**
164+
* Called when the application enters the background.
165+
* This function stops polling for updates, disconnects the billing client,
166+
* and clears any pending UI elements related to bills or sharing if certain conditions are met.
167+
*
168+
* Specifically, it clears the bottom bar, cancels any pending bill grab actions, and cancels
169+
* any ongoing send operations if:
170+
* - The share sheet is not currently checking for a share action, OR
171+
* - There is an active bill and it has not yet been received.
172+
*/
148173
override fun onAppInBackground() {
149174
stopPolling()
150175
billingClient.disconnect()
176+
177+
val bill = billController.state.value.bill
178+
//
179+
if (!shareSheetController.isCheckingForShare || (bill != null && !bill.didReceive)) {
180+
BottomBarManager.clear()
181+
billController.cancelAwaitForGrab()
182+
cancelSend()
183+
}
151184
}
152185

153186
private fun startPolling() {
@@ -471,6 +504,8 @@ class RealSessionController @Inject constructor(
471504
}
472505

473506
override fun openCashLink(cashLink: String?) {
507+
BottomBarManager.clear()
508+
474509
val entropy = cashLink?.trim()?.replace("\n", "") ?: return
475510
val owner = userManager.accountCluster ?: return
476511

@@ -489,7 +524,6 @@ class RealSessionController @Inject constructor(
489524
entropy = entropy,
490525
owner = owner,
491526
onReceived = {
492-
BottomBarManager.clear()
493527
showBill(
494528
bill = Bill.Cash(amount = it, didReceive = true),
495529
vibrate = true
@@ -519,7 +553,6 @@ class RealSessionController @Inject constructor(
519553
resources.getString(R.string.error_description_failedToCollect)
520554
)
521555
}
522-
523556
}
524557
}
525558
)
@@ -594,6 +627,7 @@ class RealSessionController @Inject constructor(
594627
}
595628
}
596629

630+
597631
override fun cancelSend(style: PresentationStyle, overrideToast: Boolean) {
598632
scope.launch {
599633
val shown = toastController.showIfNeeded(style, overrideToast)

apps/flipcash/shared/shareable/src/main/kotlin/com/flipcash/app/shareable/ShareableConfirmationController.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ interface ShareableConfirmationController {
1313
shareable: Shareable,
1414
shareResult: ShareResult.ActionTaken
1515
): ShareConfirmationResult
16+
17+
fun reset()
1618
}

apps/flipcash/shared/shareable/src/main/kotlin/com/flipcash/app/shareable/internal/InternalShareConfirmationController.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ internal class InternalShareConfirmationController(
2929
}
3030
}
3131

32+
override fun reset() {
33+
BottomBarManager.clearByType(BottomBarManager.BottomBarMessageType.REMOTE_SEND)
34+
}
35+
3236
private suspend fun confirmCashLink(
3337
shareResult: ShareResult.ActionTaken,
3438
timeout: Duration

libs/messaging/src/main/kotlin/com/getcode/manager/BottomBarManager.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ object BottomBarManager {
102102
enum class BottomBarMessageType {
103103
DESTRUCTIVE,
104104
WARNING,
105-
@Deprecated("This is no longer necessary with the VM and balance deductions are handled intelligently")
106105
REMOTE_SEND,
107106
THEMED,
108107
SUCCESS,

0 commit comments

Comments
 (0)