diff --git a/apps/flipcash/app/src/main/kotlin/com/flipcash/app/internal/ui/navigation/AppScreenContent.kt b/apps/flipcash/app/src/main/kotlin/com/flipcash/app/internal/ui/navigation/AppScreenContent.kt index 7fa93a3982..41a7429817 100644 --- a/apps/flipcash/app/src/main/kotlin/com/flipcash/app/internal/ui/navigation/AppScreenContent.kt +++ b/apps/flipcash/app/src/main/kotlin/com/flipcash/app/internal/ui/navigation/AppScreenContent.kt @@ -126,7 +126,7 @@ fun appEntryProvider( // Tokens annotatedEntry(testTag = "token_info_screen") { key -> - TokenInfoScreen(key.mint, key.shortfall, key.fromDeeplink, key.asPush) + TokenInfoScreen(key.mint, key.shortfall, key.fromDeeplink, key.asPush, key.returnAfterBuy) } annotatedEntry(testTag = "transaction_history_screen") { key -> TransactionHistoryScreen(key.mint) diff --git a/apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/AppRoute.kt b/apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/AppRoute.kt index b8333ed820..4cbeca5a4c 100644 --- a/apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/AppRoute.kt +++ b/apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/AppRoute.kt @@ -216,6 +216,10 @@ sealed interface AppRoute : NavKey, Parcelable { // (fade-in-place, ✕ dismiss). Set when the screen is reached by drilling in from a list — e.g. // token discovery — where a back arrow that slides back is the expected navigation. val asPush: Boolean = false, + // Pop back to whatever opened this screen once a buy of [mint] succeeds, rather than + // staying here. Set by a chat's gate: the reader came to buy their way into the group, + // so the purchase finishing is the moment to put them back in front of Join. + val returnAfterBuy: Boolean = false, ) : Token @Serializable diff --git a/apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/MessengerScreen.kt b/apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/MessengerScreen.kt index 7163403c5f..45fa0c2baf 100644 --- a/apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/MessengerScreen.kt +++ b/apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/MessengerScreen.kt @@ -73,7 +73,11 @@ internal fun MessengerScreen(viewModel: ChatViewModel) { // A drill-in from the transcript, so push it: the fade-in-place // expand is the wallet card growing into its own detail, and there // is no card here for it to grow from. - AppRoute.Token.Info(action.mint, asPush = true) + AppRoute.Token.Info( + action.mint, + asPush = true, + returnAfterBuy = action.returnAfterBuy, + ) ) ) } diff --git a/apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/components/GroupGateBar.kt b/apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/components/GroupGateBar.kt index 710ce0558d..eca2aa2a4e 100644 --- a/apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/components/GroupGateBar.kt +++ b/apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/components/GroupGateBar.kt @@ -121,7 +121,7 @@ internal fun GroupGateBar( enabled = currency != null, onClick = { unmetBalance.mints.firstOrNull() - ?.let { onAction(ChatAction.ViewToken(Mint(it.bytes))) } + ?.let { onAction(ChatAction.ViewToken(Mint(it.bytes), returnAfterBuy = true)) } }, ) } else { diff --git a/apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/TokenInfoScreen.kt b/apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/TokenInfoScreen.kt index c5ec4ec0ff..44734d4fc2 100644 --- a/apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/TokenInfoScreen.kt +++ b/apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/TokenInfoScreen.kt @@ -35,6 +35,7 @@ import com.flipcash.app.analytics.Analytics import com.flipcash.app.analytics.Button import com.flipcash.app.analytics.rememberAnalytics import com.flipcash.app.core.AppRoute +import com.flipcash.app.core.tokens.SwapPurpose import com.flipcash.app.core.tokens.SwapResult import com.flipcash.app.tokens.internal.TokenInfoScreen import com.flipcash.app.tokens.internal.components.info.CurrencyInfoTitlePill @@ -66,6 +67,7 @@ fun TokenInfoScreen( shortFall: Fiat?, fromDeeplink: Boolean, asPush: Boolean = false, + returnAfterBuy: Boolean = false, ) { val navigator = LocalCodeNavigator.current val analytics = rememberAnalytics() @@ -198,9 +200,18 @@ fun TokenInfoScreen( when (screen) { is AppRoute.Token.Swap -> { navigator.navigateForResult(screen) { result -> - if (result is NavResultOrCanceled.ReturnValue && - result.value is SwapResult.OpenDeposit) { - navigator.push(AppRoute.Transfers.Deposit(showOtherOptions = false)) + if (result !is NavResultOrCanceled.ReturnValue) return@navigateForResult + when (result.value) { + is SwapResult.OpenDeposit -> + navigator.push(AppRoute.Transfers.Deposit(showOtherOptions = false)) + // Only a buy of this currency. Add Money from here also ends in a + // successful Buy, but of USDF to fund this one, and the reader + // still has this purchase to make. + is SwapResult.Success -> { + val bought = (screen.purpose as? SwapPurpose.Buy)?.mint + if (returnAfterBuy && bought == mint) navigator.pop() + } + else -> Unit } } } diff --git a/apps/flipcash/shared/chat-ui/src/main/kotlin/com/flipcash/shared/chat/models/ChatAction.kt b/apps/flipcash/shared/chat-ui/src/main/kotlin/com/flipcash/shared/chat/models/ChatAction.kt index 9492f5fa82..27f68e5018 100644 --- a/apps/flipcash/shared/chat-ui/src/main/kotlin/com/flipcash/shared/chat/models/ChatAction.kt +++ b/apps/flipcash/shared/chat-ui/src/main/kotlin/com/flipcash/shared/chat/models/ChatAction.kt @@ -9,7 +9,11 @@ sealed interface ChatAction { data class RetryMessage(val bubble: ChatListItem.ContentBubble) : ChatAction data class AdvanceReadPointer(val messageId: Long) : ChatAction object RefreshContact : ChatAction - data class ViewToken(val mint: Mint) : ChatAction + /** + * Opens a currency's info screen. [returnAfterBuy] brings the reader back here once they buy + * it — set by the group gate, where buying is how they get in. + */ + data class ViewToken(val mint: Mint, val returnAfterBuy: Boolean = false) : ChatAction /** * Opens the group a link card names, pushed over this chat so Back returns here. The pushed