Skip to content

Commit d355e74

Browse files
authored
feat: return SwapResult.OpenDeposit to Token Info and push Deposit in-stack (#761)
Instead of hiding the sheet and opening a new sheet for deposit when the user selects "other wallet" during swap, deliver the result back to Token Info via navigateForResult and push the deposit screen in-stack. Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 84abe6b commit d355e74

2 files changed

Lines changed: 24 additions & 25 deletions

File tree

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

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.flipcash.app.tokens
22

33
import androidx.compose.runtime.Composable
4-
import androidx.compose.runtime.snapshots.Snapshot
54
import androidx.navigation3.runtime.NavEntry
65
import androidx.navigation3.runtime.NavKey
76
import androidx.navigation3.runtime.entryProvider
87
import com.flipcash.app.core.AppRoute
9-
import com.flipcash.app.core.extensions.openAsSheet
108
import com.flipcash.app.core.tokens.SwapResult
119
import com.flipcash.app.core.tokens.SwapStep
1210
import com.getcode.navigation.annotatedEntry
@@ -18,15 +16,13 @@ import com.getcode.navigation.flow.FlowHost
1816
import com.getcode.navigation.flow.deliverFlowResult
1917
import com.getcode.navigation.results.NavResultOrCanceled
2018
import com.getcode.navigation.results.NavResultStateRegistry
21-
import com.getcode.navigation.scenes.LocalSheetNavigator
2219

2320
@Composable
2421
fun SwapFlowScreen(
2522
route: AppRoute.Token.Swap,
2623
resultStateRegistry: NavResultStateRegistry,
2724
) {
2825
val outerNavigator = LocalCodeNavigator.current
29-
val rootNavigator = LocalSheetNavigator.current
3026
val initialStack = route.rememberInitialStack<SwapStep>()
3127

3228
FlowHost<SwapStep, SwapResult>(
@@ -38,27 +34,17 @@ fun SwapFlowScreen(
3834
FlowExitReason.Canceled,
3935
FlowExitReason.BackedOutOfRoot -> SwapResult.Canceled
4036
}
37+
outerNavigator.deliverFlowResult(
38+
route = route,
39+
value = NavResultOrCanceled.ReturnValue(result),
40+
)
4141
when (result) {
42-
is SwapResult.OpenDeposit -> {
43-
Snapshot.withMutableSnapshot {
44-
rootNavigator?.hide()
45-
// can only deposit USDC from this flow
46-
rootNavigator?.openAsSheet(AppRoute.Transfers.Deposit(showOtherOptions = false))
47-
}
48-
}
49-
else -> {
50-
outerNavigator.deliverFlowResult(
51-
route = route,
52-
value = NavResultOrCanceled.ReturnValue(result),
53-
)
54-
when (result) {
55-
SwapResult.Success -> {
56-
if (route.shortfall != null) outerNavigator.popAll()
57-
else outerNavigator.popUntil { it is AppRoute.Token.Info }
58-
}
59-
SwapResult.Canceled -> outerNavigator.pop()
60-
}
42+
SwapResult.Success -> {
43+
if (route.shortfall != null) outerNavigator.popAll()
44+
else outerNavigator.popUntil { it is AppRoute.Token.Info }
6145
}
46+
SwapResult.OpenDeposit,
47+
SwapResult.Canceled -> outerNavigator.pop()
6248
}
6349
},
6450
entryProvider = swapEntryProvider(),

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ import com.flipcash.app.analytics.Analytics
1414
import com.flipcash.app.analytics.Button
1515
import com.flipcash.app.analytics.rememberAnalytics
1616
import com.flipcash.app.core.AppRoute
17+
import com.flipcash.app.core.tokens.SwapResult
1718
import com.flipcash.app.core.ui.TokenIconWithName
1819
import com.flipcash.app.tokens.internal.TokenInfoScreen
1920
import com.flipcash.app.tokens.ui.TokenInfoViewModel
2021
import com.flipcash.features.tokens.R
2122
import com.flipcash.services.internal.model.thirdparty.OnRampProvider
2223
import com.getcode.navigation.core.LocalCodeNavigator
24+
import com.getcode.navigation.results.NavResultOrCanceled
25+
import com.getcode.navigation.results.navigateForResult
2326
import com.getcode.opencode.model.financial.Fiat
2427
import com.getcode.solana.keys.Mint
2528
import com.getcode.theme.CodeTheme
@@ -105,8 +108,18 @@ fun TokenInfoScreen(
105108
viewModel.eventFlow
106109
.filterIsInstance<TokenInfoViewModel.Event.OpenScreen>()
107110
.map { it.screen }
108-
.onEach {
109-
navigator.push(it)
111+
.onEach { screen ->
112+
when (screen) {
113+
is AppRoute.Token.Swap -> {
114+
navigator.navigateForResult<SwapResult>(screen) { result ->
115+
if (result is NavResultOrCanceled.ReturnValue &&
116+
result.value is SwapResult.OpenDeposit) {
117+
navigator.push(AppRoute.Transfers.Deposit(showOtherOptions = false))
118+
}
119+
}
120+
}
121+
else -> navigator.push(screen)
122+
}
110123
}.launchIn(this)
111124
}
112125
}

0 commit comments

Comments
 (0)