Skip to content

Commit 632ebee

Browse files
committed
chore(flipcash): handle withdrawal being too small
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 6a13d08 commit 632ebee

3 files changed

Lines changed: 43 additions & 18 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
<string name="prompt_description_confirmWithdrawal">Withdrawals are irreversible and cannot be undone once initiated</string>
119119
<string name="prompt_title_learnAboutWithdrawalFee">What Is This Fee?</string>
120120
<string name="prompt_description_learnAboutWithdrawalFee">The account you’re trying to withdraw to requires a one time account creation fee. This fee will be deducted from the amount you’re withdrawing</string>
121-
121+
<string name="error_title_withdrawalTooSmall">Withdrawal Amount Too Small</string>
122+
<string name="error_description_withdrawalTooSmall">Your withdrawal amount is too small to cover the one time fee. Please try a different amount</string>
122123
<string name="success_description_withdrawalComplete">Your withdrawal has been processed. It may take a few minutes for your funds to show up in your destination wallet</string>
123124

124125
<string name="title_requireBiometrics">Require Biometrics</string>

apps/flipcash/features/withdrawal/src/main/kotlin/com/flipcash/app/withdrawal/WithdrawalViewModel.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.getcode.opencode.model.financial.CurrencyCode
2121
import com.getcode.opencode.model.financial.Fiat
2222
import com.getcode.opencode.model.financial.LocalFiat
2323
import com.getcode.opencode.model.financial.Rate
24+
import com.getcode.opencode.model.financial.minus
2425
import com.getcode.opencode.model.transactions.WithdrawalAvailability
2526
import com.getcode.ui.components.text.AmountAnimatedInputUiModel
2627
import com.getcode.ui.components.text.NumberInputHelper
@@ -132,11 +133,13 @@ internal class WithdrawalViewModel @Inject constructor(
132133
val success: Boolean = false
133134
) : Event
134135

135-
data object OnLearnAboutFee: Event
136+
data object OnLearnAboutFee : Event
137+
138+
data object OnWithdrawalTooSmall : Event
136139

137140
data object OnWithdraw : Event
138141
data object OnWithdrawalConfirmed : Event
139-
data object OnWithdrawSuccessful: Event
142+
data object OnWithdrawSuccessful : Event
140143
}
141144

142145
val checkBalanceLimit: () -> Boolean = {
@@ -206,7 +209,8 @@ internal class WithdrawalViewModel @Inject constructor(
206209
.filterIsInstance<Event.OnNumberPressed>()
207210
.map { it.number }
208211
.onEach { number ->
209-
numberInputHelper.fractionUnits = stateFlow.value.amountEntryState.currencyModel.fractionUnits
212+
numberInputHelper.fractionUnits =
213+
stateFlow.value.amountEntryState.currencyModel.fractionUnits
210214
numberInputHelper.maxLength = 10 // 1 billion dollars
211215
numberInputHelper.onNumber(number)
212216
dispatchEvent(Event.OnEnteredNumberChanged())
@@ -277,9 +281,10 @@ internal class WithdrawalViewModel @Inject constructor(
277281
}
278282
clipboard
279283
}
280-
.mapNotNull { text -> runCatching { Base58.decode(text) }
281-
.onFailure { dispatchEvent(Event.UpdateClipboardCheckState(loading = false)) }
282-
.getOrNull()
284+
.mapNotNull { text ->
285+
runCatching { Base58.decode(text) }
286+
.onFailure { dispatchEvent(Event.UpdateClipboardCheckState(loading = false)) }
287+
.getOrNull()
283288
}.filter { address ->
284289
val length = address.size
285290
if (length != 32) {
@@ -416,6 +421,7 @@ internal class WithdrawalViewModel @Inject constructor(
416421
}
417422

418423
Event.OnLearnAboutFee,
424+
Event.OnWithdrawalTooSmall,
419425
Event.OnWithdrawalConfirmed,
420426
Event.OnWithdrawSuccessful,
421427
Event.PasteFromClipboard,

apps/flipcash/features/withdrawal/src/main/kotlin/com/flipcash/app/withdrawal/internal/confirmation/WithdrawalConfirmationScreen.kt

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,38 @@ package com.flipcash.app.withdrawal.internal.confirmation
22

33

44
import androidx.compose.foundation.Image
5-
import androidx.compose.foundation.background
6-
import androidx.compose.foundation.border
75
import androidx.compose.foundation.layout.Arrangement
8-
import androidx.compose.foundation.layout.Box
96
import androidx.compose.foundation.layout.Column
107
import androidx.compose.foundation.layout.fillMaxSize
118
import androidx.compose.foundation.layout.fillMaxWidth
129
import androidx.compose.foundation.layout.imePadding
1310
import androidx.compose.foundation.layout.navigationBarsPadding
1411
import androidx.compose.foundation.layout.padding
15-
import androidx.compose.material.Text
1612
import androidx.compose.material.icons.Icons
1713
import androidx.compose.material.icons.filled.ArrowDownward
1814
import androidx.compose.runtime.Composable
1915
import androidx.compose.runtime.LaunchedEffect
2016
import androidx.compose.runtime.getValue
2117
import androidx.compose.ui.Alignment
2218
import androidx.compose.ui.Modifier
23-
import androidx.compose.ui.graphics.Color
2419
import androidx.compose.ui.graphics.ColorFilter
2520
import androidx.compose.ui.res.stringResource
26-
import androidx.compose.ui.text.style.TextAlign
2721
import androidx.lifecycle.compose.collectAsStateWithLifecycle
2822
import cafe.adriel.voyager.core.registry.ScreenRegistry
2923
import com.flipcash.app.core.NavScreenProvider
30-
import com.flipcash.app.core.money.formatted
24+
import com.flipcash.app.withdrawal.WithdrawalEntryScreen
25+
import com.flipcash.app.withdrawal.WithdrawalFlow
3126
import com.flipcash.app.withdrawal.WithdrawalViewModel
3227
import com.flipcash.app.withdrawal.internal.components.DestinationBox
3328
import com.flipcash.app.withdrawal.internal.components.TransactionReceipt
3429
import com.flipcash.features.withdrawal.R
3530
import com.getcode.manager.BottomBarAction
3631
import com.getcode.manager.BottomBarManager
3732
import com.getcode.navigation.core.LocalCodeNavigator
38-
import com.getcode.opencode.compose.LocalExchange
3933
import com.getcode.opencode.model.financial.Fiat
4034
import com.getcode.opencode.model.financial.LocalFiat
41-
import com.getcode.opencode.model.financial.toFiat
35+
import com.getcode.opencode.model.financial.minus
4236
import com.getcode.theme.CodeTheme
43-
import com.getcode.ui.components.text.AmountArea
4437
import com.getcode.ui.theme.ButtonState
4538
import com.getcode.ui.theme.CodeButton
4639
import com.getcode.ui.theme.CodeScaffold
@@ -70,7 +63,6 @@ internal fun WithdrawalConfirmationScreen(viewModel: WithdrawalViewModel) {
7063
actions = listOf(
7164
BottomBarAction(
7265
text = resources.getString(R.string.action_ok),
73-
onClick = {}
7466
)
7567
),
7668
onClose = {
@@ -80,6 +72,32 @@ internal fun WithdrawalConfirmationScreen(viewModel: WithdrawalViewModel) {
8072
)
8173
}.launchIn(this)
8274
}
75+
76+
LaunchedEffect(state.amountEntryState, state.destinationState) {
77+
val amount = state.amountEntryState.selectedAmount
78+
val fee = state.destinationState.availability?.feeAmount
79+
if (amount.usdc - (fee ?: Fiat.Zero) < Fiat.Zero) {
80+
BottomBarManager.showMessage(
81+
BottomBarManager.BottomBarMessage(
82+
title = resources.getString(R.string.error_title_withdrawalTooSmall),
83+
subtitle = resources.getString(R.string.error_description_withdrawalTooSmall),
84+
showScrim = false,
85+
showCancel = false,
86+
actions = buildList {
87+
add(
88+
BottomBarAction(
89+
text = resources.getString(R.string.action_ok),
90+
)
91+
)
92+
},
93+
onClose = {
94+
WithdrawalFlow.start()
95+
navigator.popUntil { it is WithdrawalEntryScreen }
96+
}
97+
)
98+
)
99+
}
100+
}
83101
}
84102

85103
@Composable

0 commit comments

Comments
 (0)