Skip to content

Commit cf8a594

Browse files
committed
feat(token/info): Add Give support for tokens that are giveable
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 8685adc commit cf8a594

4 files changed

Lines changed: 44 additions & 38 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
@@ -77,7 +77,7 @@ internal fun AppScreenContent(content: @Composable () -> Unit) {
7777
}
7878

7979
register<AppRoute.Main.Give> {
80-
CashScreen(it.mint)
80+
CashScreen(it.mint, it.fromTokenInfo)
8181
}
8282

8383
register<AppRoute.Token.Info> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ sealed interface AppRoute : ScreenProvider, Parcelable {
4141
// TODO: is there a better place for this to live?
4242
data class RegionSelection(val kind: RegionSelectionKind) : Main
4343

44-
data class Give(val mint: Mint? = null) : Main
44+
data class Give(val mint: Mint? = null, val fromTokenInfo: Boolean = false) : Main
4545
}
4646

4747
@Parcelize

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import kotlinx.parcelize.Parcelize
3434

3535
@Parcelize
3636
class CashScreen(
37-
private val selectedMint: Mint?
37+
private val selectedMint: Mint?,
38+
private val fromTokenInfo: Boolean,
3839
) : ModalScreen, Parcelable {
3940

4041
@IgnoredOnParcel
@@ -80,8 +81,15 @@ class CashScreen(
8081
)
8182
}
8283
},
84+
leftIcon = {
85+
if (fromTokenInfo) {
86+
AppBarDefaults.UpNavigation { navigator.pop() }
87+
}
88+
},
8389
rightContents = {
84-
AppBarDefaults.Close { navigator.hide() }
90+
if (!fromTokenInfo) {
91+
AppBarDefaults.Close { navigator.hide() }
92+
}
8593
}
8694
)
8795
GiveScreenContent(viewModel)

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

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -282,46 +282,44 @@ private fun BottomBarButtons(
282282
verticalAlignment = Alignment.CenterVertically,
283283
horizontalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x2),
284284
) {
285-
if (!state.isCashReserve) {
286-
if (state.cashReservesEnabled) {
287-
CodeButton(
288-
modifier = Modifier.weight(1f),
289-
buttonState = ButtonState.Filled,
290-
text = stringResource(R.string.action_buy),
291-
) {
292-
dispatch(TokenInfoViewModel.Event.OpenPurchaseMethods(forNeededFunds = isForNeededFunds))
293-
}
285+
if (state.isCashReserve) return@Row
286+
val canGive = state.balance.nativeAmount.isPositive
287+
if (canGive) {
288+
CodeButton(
289+
modifier = Modifier.weight(1f),
290+
buttonState = ButtonState.Filled,
291+
text = stringResource(R.string.action_give),
292+
) {
293+
dispatch(
294+
TokenInfoViewModel.Event.OpenScreen(
295+
AppRoute.Main.Give(mint = loadable.data.address, fromTokenInfo = true)
296+
)
297+
)
298+
}
299+
}
294300

295-
if (state.canSell) {
296-
CodeButton(
297-
modifier = Modifier
298-
.weight(1f),
299-
buttonState = ButtonState.Filled20,
300-
text = stringResource(R.string.action_sell),
301-
) {
302-
analytics.buttonTapped(Button.TokenSell)
303-
dispatch(
304-
TokenInfoViewModel.Event.OpenScreen(
305-
AppRoute.Token.SwapTransact(
306-
purpose = TokenSwapPurpose.Sell(loadable.data.address),
307-
)
308-
)
309-
)
310-
}
311-
}
312-
} else {
301+
if (state.cashReservesEnabled) {
302+
CodeButton(
303+
modifier = Modifier.weight(1f),
304+
buttonState = if (canGive) ButtonState.Filled20 else ButtonState.Filled,
305+
text = stringResource(R.string.action_buy),
306+
) {
307+
dispatch(TokenInfoViewModel.Event.OpenPurchaseMethods(forNeededFunds = isForNeededFunds))
308+
}
309+
310+
if (state.canSell) {
313311
CodeButton(
314312
modifier = Modifier
315-
.fillMaxWidth()
316-
.padding(horizontal = CodeTheme.dimens.inset)
317-
.padding(bottom = CodeTheme.dimens.grid.x3)
318-
.navigationBarsPadding(),
319-
buttonState = ButtonState.Filled,
320-
text = stringResource(R.string.action_give),
313+
.weight(1f),
314+
buttonState = ButtonState.Filled20,
315+
text = stringResource(R.string.action_sell),
321316
) {
317+
analytics.buttonTapped(Button.TokenSell)
322318
dispatch(
323319
TokenInfoViewModel.Event.OpenScreen(
324-
AppRoute.Main.Give(mint = loadable.data.address)
320+
AppRoute.Token.SwapTransact(
321+
purpose = TokenSwapPurpose.Sell(loadable.data.address),
322+
)
325323
)
326324
)
327325
}

0 commit comments

Comments
 (0)