Skip to content

Commit bff27dc

Browse files
authored
chore(tips): filter token select by min tip only (#1149)
1 parent 17aaa54 commit bff27dc

8 files changed

Lines changed: 32 additions & 20 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ data class TipSelectionState(
4747
val canTip: Boolean = false,
4848
/** Suggested tip presets in the sender's preferred currency; updates when the region changes. */
4949
val presets: List<Fiat> = emptyList(),
50+
val minimum: Fiat? = null,
5051
) {
5152
/** A positive amount is chosen and no submission is currently in flight. */
5253
val canConfirm: Boolean get() = amount != null && sendState.isIdle

‎apps/flipcash/core/src/main/res/values/strings.xml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,10 @@
845845
<string name="prompt_title_cancelCashLinkPostShare">Are You Sure?</string>
846846
<string name="prompt_description_cancelCashLinkPostShare">Anyone you sent the link to won\'t be able to collect the cash</string>
847847

848+
<string name="subtitle_youTipped">You tipped</string>
849+
<string name="subtitle_youReceived">You received</string>
850+
<string name="subtitle_youSent">You sent</string>
851+
<string name="subtitle_youReceivedTip">You received a tip</string>
848852
<string name="label_chat_preview_cash_suffix">%1$s of %2$s</string>
849853
<string name="label_chat_preview_sentCash">You sent %1$s</string>
850854
<string name="label_chat_preview_receivedCash">You received %1$s</string>

‎apps/flipcash/features/scanner/src/main/kotlin/com/flipcash/app/scanner/internal/bills/decor/TipCardDecorator.kt‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ internal data class TipCardDecorator(private val tipCard: Scannable.TipCard) : S
5757
// the UI, so we route directly rather than plumbing a callback through the session.
5858
LaunchedEffect(tipPresented, selection.canTip) {
5959
if (tipPresented && !selection.canTip) {
60-
session?.presentDepositOptions { route ->
61-
navigator.openAsSheet(route)
60+
session?.presentDepositOptions(
6261
// No giveable balance to tip with → steer to add-money / discover, and dismiss the
6362
// tip card so we don't leave it stranded behind the prompt.
64-
context.onDismiss()
63+
onDismiss = { context.onDismiss() }
64+
) { route ->
65+
navigator.openAsSheet(route)
6566
}
6667
}
6768
}

‎apps/flipcash/features/scanner/src/main/kotlin/com/flipcash/app/scanner/internal/ui/modals/TipUserModal.kt‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ internal fun TipUserModal(
8181
token = selection.token,
8282
modifier = Modifier.fillMaxWidth(),
8383
onSelectToken = {
84-
val threshold = selection.amount?.value ?: selection.presets.firstOrNull()
85-
navigator.openAsSheet(AppRoute.Sheets.TokenSelection(TokenPurpose.Tip(threshold)))
84+
navigator.openAsSheet(AppRoute.Sheets.TokenSelection(TokenPurpose.Tip( selection.minimum)))
8685
},
8786
)
8887

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import com.getcode.opencode.model.financial.Fiat
5555
import com.getcode.theme.CodeTheme
5656
import com.getcode.ui.components.PriceWithFlag
5757
import com.getcode.ui.core.addIf
58-
import com.getcode.util.resources.R
5958

6059
enum class BubblePosition { Solo, First, Middle, Last }
6160

@@ -212,7 +211,7 @@ private fun CashBubble(
212211
) {
213212
val subtitleRes = when (action) {
214213
MessageContent.Cash.Action.TIPPED ->
215-
if (isFromSelf) R.string.subtitle_youTipped else R.string.subtitle_someoneTippedYou
214+
if (isFromSelf) R.string.subtitle_youTipped else R.string.subtitle_youReceivedTip
216215
MessageContent.Cash.Action.SENT ->
217216
if (isFromSelf) R.string.subtitle_youSent else R.string.subtitle_youReceived
218217
}

‎apps/flipcash/shared/session/src/main/kotlin/com/flipcash/app/session/SessionController.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ interface DepositOperations {
4444
* an add-money prompt when the wallet is empty, or a discover-currencies prompt when
4545
* the user has funds (e.g. reserves) but nothing giveable.
4646
*/
47-
fun presentDepositOptions(onRoute: ((AppRoute) -> Unit)? = null)
47+
fun presentDepositOptions(onDismiss: (() -> Unit)? = null, onRoute: ((AppRoute) -> Unit)? = null)
4848
}
4949

5050
interface SessionController : BillOperations, CodeScanOperations, CashLinkOperations, DepositOperations, TipCardOperations {

‎apps/flipcash/shared/session/src/main/kotlin/com/flipcash/app/session/internal/delegates/DepositDelegate.kt‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,25 @@ class DepositDelegate @Inject constructor(
5353
.launchIn(scope)
5454
}
5555

56-
override fun presentDepositOptions(onRoute: ((AppRoute) -> Unit)?) {
56+
override fun presentDepositOptions(onDismiss: (() -> Unit)?, onRoute: ((AppRoute) -> Unit)?) {
5757
// Prompt to add money only when the wallet is empty and add-money is available.
5858
// Otherwise the user has funds (e.g. reserves) but nothing giveable — or can't
5959
// add money at all — so steer them to discover/buy a currency.
6060
val addMoneyEnabled = stateHolder.current.addMoneyUx
6161
val hasBalance = stateHolder.current.hasBalance
6262

6363
if (!hasBalance) {
64-
presentAddMoney(addMoneyEnabled, onRoute)
64+
presentAddMoney(addMoneyEnabled, onRoute, onDismiss)
6565
} else {
66-
presentDiscoverCurrencies(onRoute)
66+
presentDiscoverCurrencies(onRoute, onDismiss)
6767
}
6868
}
6969

70-
private fun presentAddMoney(addMoneyEnabled: Boolean, onRoute: ((AppRoute) -> Unit)?) {
70+
private fun presentAddMoney(
71+
addMoneyEnabled: Boolean,
72+
onRoute: ((AppRoute) -> Unit)?,
73+
onDismiss: (() -> Unit)?
74+
) {
7175
BottomBarManager.showInfo(
7276
title = resources.getString(R.string.title_noBalanceYet),
7377
message = if (addMoneyEnabled) {
@@ -90,10 +94,11 @@ class DepositDelegate @Inject constructor(
9094
},
9195
),
9296
showCancel = true,
97+
onDismiss = { onDismiss?.invoke() }
9398
)
9499
}
95100

96-
private fun presentDiscoverCurrencies(onRoute: ((AppRoute) -> Unit)?) {
101+
private fun presentDiscoverCurrencies(onRoute: ((AppRoute) -> Unit)?, onDismiss: (() -> Unit)?) {
97102
BottomBarManager.showInfo(
98103
title = resources.getString(R.string.title_noCommunityCurrenciesYet),
99104
message = resources.getString(R.string.description_noCommunityCurrenciesYet),
@@ -105,6 +110,7 @@ class DepositDelegate @Inject constructor(
105110
},
106111
),
107112
showCancel = true,
113+
onDismiss = { onDismiss?.invoke() }
108114
)
109115
}
110116

‎apps/flipcash/shared/tipping/src/main/kotlin/com/flipcash/shared/tipping/TippingCoordinator.kt‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.getcode.opencode.exchange.VerifiedFiatCalculator
2626
import com.getcode.opencode.model.core.errors.ComputeVerifiedFiatError
2727
import com.getcode.opencode.model.financial.Fiat
2828
import com.getcode.opencode.model.financial.Token
29+
import com.getcode.opencode.utils.combine
2930
import com.getcode.util.resources.ResourceHelper
3031
import com.getcode.view.LoadingSuccessState
3132
import kotlinx.coroutines.CoroutineScope
@@ -101,16 +102,23 @@ class TippingCoordinator @Inject constructor(
101102
tokenCoordinator.tokens.map { tokens -> tokens.find { it.address == mint } }
102103
}
103104

105+
/** The largest tippable amount (send-limit ∧ balance), surfaced by the amount entry. */
106+
val maxTipAmount: StateFlow<Fiat?> get() = tipPaymentDelegate.maxTipAmount
107+
108+
/** The smallest tippable amount (lowest preset tier), surfaced by the amount entry. */
109+
val minTipAmount: StateFlow<Fiat?> get() = tipPaymentDelegate.minTipAmount
110+
104111
/** The combined tip selection (amount chosen in the modal + app-global token + send state). */
105112
override val selection: StateFlow<TipSelectionState> =
106113
combine(
107-
combine(_amount, selectedToken, _sendState, _userId, _canTip) { amount, token, sendState, userId, canTip ->
114+
combine(_amount, selectedToken, _sendState, _userId, _canTip, minTipAmount) { amount, token, sendState, userId, canTip, min ->
108115
TipSelectionState(
109116
amount = amount,
110117
token = token,
111118
sendState = sendState,
112119
userId = userId,
113120
canTip = canTip,
121+
minimum = min
114122
)
115123
},
116124
tipPaymentDelegate.tipPresets,
@@ -128,12 +136,6 @@ class TippingCoordinator @Inject constructor(
128136
.launchIn(scope)
129137
}
130138

131-
/** The largest tippable amount (send-limit ∧ balance), surfaced by the amount entry. */
132-
val maxTipAmount: StateFlow<Fiat?> get() = tipPaymentDelegate.maxTipAmount
133-
134-
/** The smallest tippable amount (lowest preset tier), surfaced by the amount entry. */
135-
val minTipAmount: StateFlow<Fiat?> get() = tipPaymentDelegate.minTipAmount
136-
137139
/** Whether [amount] exceeds the per-transaction send limit for its currency. */
138140
fun exceedsSendLimit(amount: Fiat): Boolean = tipPaymentDelegate.exceedsSendLimit(amount)
139141

0 commit comments

Comments
 (0)