Skip to content

Commit d86c22b

Browse files
committed
feat: add buys with purpose; return to Give when adding cash via a buy
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent bcf117e commit d86c22b

13 files changed

Lines changed: 71 additions & 47 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ internal fun AppScreenContent(content: @Composable () -> Unit) {
8181
}
8282

8383
register<AppRoute.Token.Info> {
84-
TokenInfoScreen(it.mint)
84+
TokenInfoScreen(it.mint, it.forNeededFunds)
8585
}
8686

8787
register<AppRoute.Token.Transactions> {
8888
TransactionHistoryScreen(it.mint)
8989
}
9090

9191
register<AppRoute.Token.SwapTransact> {
92-
BuySellFlow.start()
92+
BuySellFlow.start(it.forNeededFunds)
9393
TokenBuySellEntryScreen(it.purpose)
9494
}
9595

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ sealed interface AppRoute : ScreenProvider, Parcelable {
6565

6666
@Parcelize
6767
sealed interface Token: AppRoute {
68-
data class Info(val mint: Mint): Token
68+
data class Info(val mint: Mint, val forNeededFunds: Boolean = false): Token
6969
data class Transactions(val mint: Mint): Token
70-
data class SwapTransact(val purpose: TokenSwapPurpose): Token
70+
data class SwapTransact(val purpose: TokenSwapPurpose, val forNeededFunds: Boolean = false): Token
7171
data class TxProcessing(val swapId: SwapId): Token
7272
data object SellReceipt: Token
7373
}

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/ui/NotifyButtonLabel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fun buildNotifyButtonLabel(): AnnotatedButtonLabel {
4444
end = CodeTheme.dimens.staticGrid.x1
4545
),
4646
painter = painterResource(R.drawable.ic_check),
47-
colorFilter = ColorFilter.tint(Color.White),
47+
colorFilter = ColorFilter.tint(CodeTheme.colors.textSecondary),
4848
contentDescription = null
4949
)
5050
}

apps/flipcash/features/cash/src/main/kotlin/com/flipcash/app/cash/internal/CashScreenViewModel.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,13 @@ internal class CashScreenViewModel @Inject constructor(
323323
// has coinbase provider supporting google pay - pop selection for quick add
324324
dispatchEvent(Event.OpenOnRampAmountModal(amount))
325325
} else {
326-
// route to provider list
326+
// route to buy the token
327327
dispatchEvent(
328328
Event.OpenScreen(
329-
AppRoute.Menu.Deposit(mint = stateFlow.value.selectedTokenAddress!!),
329+
AppRoute.Token.Info(
330+
mint = stateFlow.value.selectedTokenAddress!!,
331+
forNeededFunds = true
332+
),
330333
)
331334
)
332335
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ object BuySellFlow {
88
internal var key: String = ""
99
private set
1010

11+
var isForNeededFunds: Boolean = false
12+
private set
13+
1114
@OptIn(ExperimentalUuidApi::class)
12-
fun start() {
15+
fun start(forNeededFunds: Boolean) {
1316
key = Uuid.random().toString()
17+
isForNeededFunds = forNeededFunds
1418
}
1519
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import cafe.adriel.voyager.core.registry.ScreenRegistry
1414
import cafe.adriel.voyager.core.screen.ScreenKey
1515
import cafe.adriel.voyager.core.screen.uniqueScreenKey
1616
import cafe.adriel.voyager.hilt.getViewModel
17-
import com.flipcash.app.core.AppRoute
1817
import com.flipcash.app.core.ui.TokenIconWithName
1918
import com.flipcash.app.onramp.LocalExternalWalletState
2019
import com.flipcash.app.onramp.OnRampFlowTracker
@@ -24,7 +23,6 @@ import com.flipcash.services.internal.model.thirdparty.OnRampProvider
2423
import com.getcode.navigation.core.LocalCodeNavigator
2524
import com.getcode.navigation.modal.ModalScreen
2625
import com.getcode.navigation.screens.AppScreen
27-
import com.getcode.navigation.screens.OnScreenResult
2826
import com.getcode.solana.keys.Mint
2927
import com.getcode.theme.CodeTheme
3028
import com.getcode.ui.components.AppBarDefaults
@@ -40,7 +38,10 @@ import kotlinx.parcelize.IgnoredOnParcel
4038
import kotlinx.parcelize.Parcelize
4139

4240
@Parcelize
43-
class TokenInfoScreen(private val mint: Mint) : AppScreen(), ModalScreen, Parcelable {
41+
class TokenInfoScreen(
42+
private val mint: Mint,
43+
private val forNeededFunds: Boolean,
44+
) : AppScreen(), ModalScreen, Parcelable {
4445

4546
@IgnoredOnParcel
4647
override val key: ScreenKey = uniqueScreenKey
@@ -84,10 +85,10 @@ class TokenInfoScreen(private val mint: Mint) : AppScreen(), ModalScreen, Parcel
8485
},
8586
)
8687

87-
TokenInfoScreen(viewModel)
88+
TokenInfoScreen(viewModel, forNeededFunds)
8889

8990
LaunchedEffect(Unit) {
90-
viewModel.dispatchEvent(TokenInfoViewModel.Event.OnMintProvided(mint))
91+
viewModel.dispatchEvent(TokenInfoViewModel.Event.OnMintProvided(mint, forNeededFunds))
9192
}
9293

9394
LaunchedEffect(viewModel) {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ class TokenTxProcessingScreen(val swapId: SwapId) : ModalScreen, NamedScreen, Pa
4040
viewModel.eventFlow
4141
.filterIsInstance<Event.OnTransactionSuccessful>()
4242
.onEach {
43-
navigator.popUntil { it is TokenInfoScreen }
44-
}
43+
if (BuySellFlow.isForNeededFunds) {
44+
navigator.popAll()
45+
} else {
46+
navigator.popUntil { it is TokenInfoScreen }
47+
}
48+
}.launchIn(this)
4549
}
4650

4751
LaunchedEffect(viewModel) {

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,21 @@ import com.getcode.ui.utils.calculateStartPadding
4545
import com.getcode.ui.utils.sheetResignmentBehavior
4646

4747
@Composable
48-
internal fun TokenInfoScreen(viewModel: TokenInfoViewModel) {
48+
internal fun TokenInfoScreen(viewModel: TokenInfoViewModel, isForNeededFunds: Boolean) {
4949
val state by viewModel.stateFlow.collectAsStateWithLifecycle()
50-
TokenInfoScreen(state, viewModel::dispatchEvent)
50+
TokenInfoScreen(isForNeededFunds, state, viewModel::dispatchEvent)
5151
}
5252

5353
@Composable
5454
private fun TokenInfoScreen(
55+
isForNeededFunds: Boolean,
5556
state: TokenInfoViewModel.State,
5657
dispatch: (TokenInfoViewModel.Event) -> Unit
5758
) {
5859
val listState = rememberLazyListState()
5960

6061
CodeScaffold(
61-
bottomBar = { BottomBar(state, dispatch) }
62+
bottomBar = { BottomBar(isForNeededFunds, state, dispatch) }
6263
) { innerPadding ->
6364
Box(
6465
modifier = Modifier.verticalScrollStateGradient(
@@ -172,6 +173,7 @@ private fun TokenInfoScreen(
172173

173174
@Composable
174175
private fun BottomBar(
176+
isForNeededFunds: Boolean,
175177
state: TokenInfoViewModel.State,
176178
dispatch: (TokenInfoViewModel.Event) -> Unit
177179
) {
@@ -197,6 +199,7 @@ private fun BottomBar(
197199
top = CodeTheme.dimens.grid.x9,
198200
bottom = CodeTheme.dimens.grid.x3
199201
),
202+
isForNeededFunds = isForNeededFunds,
200203
state = state,
201204
dispatch = dispatch
202205
)
@@ -205,6 +208,7 @@ private fun BottomBar(
205208

206209
@Composable
207210
private fun BottomBarButtons(
211+
isForNeededFunds: Boolean,
208212
state: TokenInfoViewModel.State,
209213
modifier: Modifier = Modifier,
210214
dispatch: (TokenInfoViewModel.Event) -> Unit
@@ -233,7 +237,7 @@ private fun BottomBarButtons(
233237
buttonState = ButtonState.Filled,
234238
text = stringResource(R.string.action_buy),
235239
) {
236-
dispatch(TokenInfoViewModel.Event.OpenPurchaseMethods)
240+
dispatch(TokenInfoViewModel.Event.OpenPurchaseMethods(forNeededFunds = isForNeededFunds))
237241
}
238242

239243
if (state.canSell) {
@@ -246,7 +250,7 @@ private fun BottomBarButtons(
246250
dispatch(
247251
TokenInfoViewModel.Event.OpenScreen(
248252
AppRoute.Token.SwapTransact(
249-
purpose = TokenSwapPurpose.Sell(state.token!!.address)
253+
purpose = TokenSwapPurpose.Sell(state.token!!.address),
250254
)
251255
)
252256
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private fun TokenTxProcessingScreen(
120120
text = stringResource(R.string.action_ok),
121121
buttonState = ButtonState.Filled,
122122
onClick = {
123-
dispatch(BuySellSwapTokenViewModel.Event.Exit)
123+
dispatch(BuySellSwapTokenViewModel.Event.OnTransactionSuccessful)
124124
}
125125
)
126126
}

apps/flipcash/shared/onramp/deeplinks/src/main/kotlin/com/flipcash/app/onramp/ExternalWalletOnRampHandler.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ fun ExternalWalletOnRampHandler(
200200
navigator.push(
201201
ScreenRegistry.get(
202202
AppRoute.Token.SwapTransact(
203-
TokenSwapPurpose.FundWithWallet(origin.mint)
203+
TokenSwapPurpose.FundWithWallet(origin.mint),
204+
forNeededFunds = origin.forNeededFunds
204205
)
205206
)
206207
)

0 commit comments

Comments
 (0)