Skip to content

Commit cfe9329

Browse files
authored
fix(chat): return to the group after buying in from its gate (#1532)
Buy More on a group's gate opens Token Info over the chat, and buying from there only closed the swap, leaving the reader on Token Info with no way back to Join except the back arrow. Token.Info now takes returnAfterBuy, which the gate sets. When a buy of that currency succeeds, Token Info closes too and the chat is back on top. Add Money from Token Info also ends in a successful buy, but of USDF, so it only counts when USDF is the gate's currency. Token taps in the transcript open Token Info as before.
1 parent 9a6d8bb commit cfe9329

6 files changed

Lines changed: 30 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fun appEntryProvider(
126126

127127
// Tokens
128128
annotatedEntry<AppRoute.Token.Info>(testTag = "token_info_screen") { key ->
129-
TokenInfoScreen(key.mint, key.shortfall, key.fromDeeplink, key.asPush)
129+
TokenInfoScreen(key.mint, key.shortfall, key.fromDeeplink, key.asPush, key.returnAfterBuy)
130130
}
131131
annotatedEntry<AppRoute.Token.Transactions>(testTag = "transaction_history_screen") { key ->
132132
TransactionHistoryScreen(key.mint)

‎apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/AppRoute.kt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ sealed interface AppRoute : NavKey, Parcelable {
216216
// (fade-in-place, ✕ dismiss). Set when the screen is reached by drilling in from a list — e.g.
217217
// token discovery — where a back arrow that slides back is the expected navigation.
218218
val asPush: Boolean = false,
219+
// Pop back to whatever opened this screen once a buy of [mint] succeeds, rather than
220+
// staying here. Set by a chat's gate: the reader came to buy their way into the group,
221+
// so the purchase finishing is the moment to put them back in front of Join.
222+
val returnAfterBuy: Boolean = false,
219223
) : Token
220224

221225
@Serializable

‎apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/MessengerScreen.kt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ internal fun MessengerScreen(viewModel: ChatViewModel) {
7373
// A drill-in from the transcript, so push it: the fade-in-place
7474
// expand is the wallet card growing into its own detail, and there
7575
// is no card here for it to grow from.
76-
AppRoute.Token.Info(action.mint, asPush = true)
76+
AppRoute.Token.Info(
77+
action.mint,
78+
asPush = true,
79+
returnAfterBuy = action.returnAfterBuy,
80+
)
7781
)
7882
)
7983
}

‎apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/components/GroupGateBar.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ internal fun GroupGateBar(
121121
enabled = currency != null,
122122
onClick = {
123123
unmetBalance.mints.firstOrNull()
124-
?.let { onAction(ChatAction.ViewToken(Mint(it.bytes))) }
124+
?.let { onAction(ChatAction.ViewToken(Mint(it.bytes), returnAfterBuy = true)) }
125125
},
126126
)
127127
} else {

‎apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/TokenInfoScreen.kt‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import com.flipcash.app.analytics.Analytics
3535
import com.flipcash.app.analytics.Button
3636
import com.flipcash.app.analytics.rememberAnalytics
3737
import com.flipcash.app.core.AppRoute
38+
import com.flipcash.app.core.tokens.SwapPurpose
3839
import com.flipcash.app.core.tokens.SwapResult
3940
import com.flipcash.app.tokens.internal.TokenInfoScreen
4041
import com.flipcash.app.tokens.internal.components.info.CurrencyInfoTitlePill
@@ -66,6 +67,7 @@ fun TokenInfoScreen(
6667
shortFall: Fiat?,
6768
fromDeeplink: Boolean,
6869
asPush: Boolean = false,
70+
returnAfterBuy: Boolean = false,
6971
) {
7072
val navigator = LocalCodeNavigator.current
7173
val analytics = rememberAnalytics()
@@ -198,9 +200,18 @@ fun TokenInfoScreen(
198200
when (screen) {
199201
is AppRoute.Token.Swap -> {
200202
navigator.navigateForResult<SwapResult>(screen) { result ->
201-
if (result is NavResultOrCanceled.ReturnValue &&
202-
result.value is SwapResult.OpenDeposit) {
203-
navigator.push(AppRoute.Transfers.Deposit(showOtherOptions = false))
203+
if (result !is NavResultOrCanceled.ReturnValue) return@navigateForResult
204+
when (result.value) {
205+
is SwapResult.OpenDeposit ->
206+
navigator.push(AppRoute.Transfers.Deposit(showOtherOptions = false))
207+
// Only a buy of this currency. Add Money from here also ends in a
208+
// successful Buy, but of USDF to fund this one, and the reader
209+
// still has this purchase to make.
210+
is SwapResult.Success -> {
211+
val bought = (screen.purpose as? SwapPurpose.Buy)?.mint
212+
if (returnAfterBuy && bought == mint) navigator.pop()
213+
}
214+
else -> Unit
204215
}
205216
}
206217
}

‎apps/flipcash/shared/chat-ui/src/main/kotlin/com/flipcash/shared/chat/models/ChatAction.kt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ sealed interface ChatAction {
99
data class RetryMessage(val bubble: ChatListItem.ContentBubble) : ChatAction
1010
data class AdvanceReadPointer(val messageId: Long) : ChatAction
1111
object RefreshContact : ChatAction
12-
data class ViewToken(val mint: Mint) : ChatAction
12+
/**
13+
* Opens a currency's info screen. [returnAfterBuy] brings the reader back here once they buy
14+
* it — set by the group gate, where buying is how they get in.
15+
*/
16+
data class ViewToken(val mint: Mint, val returnAfterBuy: Boolean = false) : ChatAction
1317

1418
/**
1519
* Opens the group a link card names, pushed over this chat so Back returns here. The pushed

0 commit comments

Comments
 (0)