Skip to content

Commit e3a1819

Browse files
committed
feat: build out remainder of onramp flow and swap to USDF
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 2402a47 commit e3a1819

21 files changed

Lines changed: 529 additions & 338 deletions

File tree

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
@@ -136,7 +136,7 @@ sealed interface AppRoute : NavKey, Parcelable {
136136
) : OnRamp
137137

138138
@Serializable
139-
data class AmountEntry(val mint: Mint? = null) : OnRamp
139+
data class AmountEntry(val mint: Mint) : OnRamp
140140
}
141141

142142
@Serializable

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/extensions/Result.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ fun <T, R> Flow<Result<T>>.mapResult(block: (T) -> R): Flow<Result<R>> {
2020
}
2121
}
2222

23+
fun <T, R> Flow<Result<T>>.flatMapResult(block: suspend (T) -> Result<R>): Flow<Result<R>> {
24+
return this.map {
25+
it.fold(
26+
onSuccess = { value -> block(value) },
27+
onFailure = { error -> Result.failure(error) }
28+
)
29+
}
30+
}
31+
2332
fun <T> Flow<Result<T>>.onError(block: (Throwable) -> Unit): Flow<Result<T>> {
2433
return this.map {
2534
it.onFailure(block)

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/verification/email/EmailDeeplinkOrigin.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ sealed class EmailDeeplinkOrigin {
2525
val amountString = amount?.let { Json.encodeToString(Fiat.Companion.serializer(), it) }
2626
when (source) {
2727
is AppRoute.Sheets.Menu -> "onramp|menu|$amountString"
28-
is AppRoute.OnRamp.AmountEntry -> "onramp|amountentry|${source.mint?.base58()}"
28+
is AppRoute.OnRamp.AmountEntry -> "onramp|amountentry|${source.mint.base58()}"
2929

3030
else -> "onramp|null|$amountString"
3131
}
@@ -60,6 +60,12 @@ sealed class EmailDeeplinkOrigin {
6060
println("deeplink mint = $it")
6161
Mint(it)
6262
}
63+
64+
if (mint == null) {
65+
println("deeplink mint is null")
66+
return null
67+
}
68+
6369
AppRoute.OnRamp.AmountEntry(mint)
6470
}
6571
else -> null

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

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<string name="action_createNewAccount">Create a New Account</string>
44
<string name="title_enterAccessKeyWords">Enter Access Key</string>
55
<string name="error_title_timelockUnlocked">Access Key No Longer Usable in Flipcash</string>
6-
<string name="title_cantFindYourAccessKey">Can\t Find Your Access Key?</string>
6+
<string name="title_cantFindYourAccessKey">Can\'t Find Your Access Key?</string>
77
<string name="action_openPhotos">Open Photos</string>
8-
<string name="description_cantFindYourAccessKey">Go to your photos app and search Flipcash</string>
8+
<string name="description_cantFindYourAccessKey">Go to your photos app and search \'Flipcash\'</string>
99
<string name="error_description_timelockUnlocked">Your Access Key has initiated an unlock. As a result, you will no longer be able to use this Access Key in Flipcash</string>
1010
<string name="prompt_title_notFlipcashAccount">Not a Flipcash Account</string>
1111
<string name="prompt_description_notFlipcashAccount">Only accounts created through Flipcash are currently supported</string>
@@ -145,7 +145,7 @@
145145
<string name="title_enterAddress">Enter address</string>
146146
<string name="subtitle_whereWithdrawTo">Where would you like to withdraw your %1$s to?</string>
147147

148-
<string name="error_title_destinationAccountNotInitialized">Destination Account Not Initialized\nPlease make sure the address youre withdrawing to has been initialized by your wallet provider. A quick way to do this is to make sure there is already some USDC in the address youre trying to withdraw to</string>
148+
<string name="error_title_destinationAccountNotInitialized">Destination Account Not Initialized\nPlease make sure the address you\'re withdrawing to has been initialized by your wallet provider. A quick way to do this is to make sure there is already some USDC in the address you\'re trying to withdraw to</string>
149149
<string name="error_title_invalidAddress">Invalid address</string>
150150

151151
<string name="action_withdraw">Withdraw</string>
@@ -154,7 +154,7 @@
154154

155155
<string name="prompt_description_confirmWithdrawal">Withdrawals are irreversible and cannot be undone once initiated</string>
156156
<string name="prompt_title_learnAboutWithdrawalFee">What Is This Fee?</string>
157-
<string name="prompt_description_learnAboutWithdrawalFee">The account youre trying to withdraw to requires a one time account creation fee. This fee will be deducted from the amount youre withdrawing</string>
157+
<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>
158158
<string name="error_title_withdrawalTooSmall">Withdrawal Amount Too Small</string>
159159
<string name="error_description_withdrawalTooSmall">Your withdrawal amount is too small to cover the one time fee. Please try a different amount</string>
160160
<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>
@@ -193,7 +193,7 @@
193193
<string name="error_description_paymentFailed">This payment request could not be paid at this time. Please try again later.</string>
194194

195195
<string name="error_title_paymentFailedDueToInsufficientFunds">Insufficient Balance</string>
196-
<string name="error_description_paymentFailedDueToInsufficientFunds">You don\t have enough funds to complete this payment</string>
196+
<string name="error_description_paymentFailedDueToInsufficientFunds">You don\'t have enough funds to complete this payment</string>
197197

198198
<plurals name="subtitle_personCount">
199199
<item quantity="zero">0 people</item>
@@ -214,7 +214,7 @@
214214
<string name="title_addCashToWallet">Add cash to your Flipcash wallet</string>
215215
<string name="action_addMoreCash">Add More Cash</string>
216216
<string name="title_tapAboveToAddCashToWallet">Tap above to Add Cash to your wallet</string>
217-
<string name="title_tapBelowToAddCashWallet">You dont have any cash yet.\nTap below to add cash to your wallet</string>
217+
<string name="title_tapBelowToAddCashWallet">You don\'t have any cash yet.\nTap below to add cash to your wallet</string>
218218
<string name="title_noBalanceYet">No Balance Yet</string>
219219
<string name="description_noBalanceYet">Get another Flipcash user to give you some cash to get a balance</string>
220220
<string name="description_noBalanceYetDiscover">Buy your first currency to get started</string>
@@ -299,7 +299,8 @@
299299
<string name="action_unlinkEmail">Unlink Email</string>
300300

301301
<string name="title_verificationFlow">Verify Your Phone Number And Email To Continue</string>
302-
<string name="subtitle_verificationFlowForOnramp">This will allow you to add funds from your debit card</string>"
302+
<string name="subtitle_verificationFlowForOnramp">This will allow you to add funds from your debit card</string>
303+
"
303304

304305
<string name="title_email">Email</string>
305306
<string name="action_openMail">Open Mail</string>
@@ -462,4 +463,62 @@
462463
<string name="subtitle_settingsUserFlags">User Flags</string>
463464
<string name="title_settingsSectionAccount">Account</string>
464465
<string name="title_userFlags">User Flags</string>
466+
467+
<string name="error_title_onrampInvalidCard">Debit Cards Only</string>
468+
<string name="error_description_onrampInvalidCard">The transaction was declined. Please make sure you are using a debit card and the billing address is correct</string>
469+
470+
<string name="error_title_onrampTransactionLimit">Weekly Limit Exceeded</string>
471+
<string name="error_description_onrampTransactionLimit">You can only add up to $1,000 per week</string>
472+
473+
<string name="error_title_onrampTransactionCount">Maximum Purchases Reached</string>
474+
<string name="error_description_onrampTransactionCount">Each user is limited to 15 purchases total. To add more funds, you will need to purchase USDC on an exchange and deposit it into Flipcash</string>
475+
476+
<string name="error_title_onrampCardRiskDeclined">Something Went Wrong</string>
477+
<string name="error_description_onrampCardRiskDeclined">Please contact support@flipcash.com</string>
478+
479+
<string name="error_title_onrampCardPermissionDenied">Something Went Wrong</string>
480+
<string name="error_description_onrampCardPermissionDenied">Please contact support@flipcash.com</string>
481+
482+
<string name="error_title_onrampRegionMismatch">Your Region Isn\'t Supported</string>
483+
<string name="error_description_onrampRegionMismatch">This feature isn\'t currently available in your region</string>
484+
485+
<string name="error_title_onrampNetworkNotTradable">Your Region Isn\'t Supported</string>
486+
<string name="error_description_onrampNetworkNotTradable">This feature isn\'t currently available in your region</string>
487+
488+
<string name="error_title_onrampRegionForbidden">Your Region Isn\'t Supported</string>
489+
<string name="error_description_onrampRegionForbidden">This feature isn\'t currently available in your region</string>
490+
491+
<string name="error_title_onrampCardSoftDeclined">Card Declined</string>
492+
<string name="error_description_onrampCardSoftDeclined">Your purchase was declined by your bank. Please contact your bank or try again with a different card</string>
493+
494+
<string name="error_title_onrampCardHardDeclined">Card Declined</string>
495+
<string name="error_description_onrampCardHardDeclined">Your purchase was declined by your bank. Please contact your bank or try again with a different card</string>
496+
497+
<string name="error_title_onrampTransactionBuyFailed">Card Declined</string>
498+
<string name="error_description_onrampTransactionBuyFailed">Your purchase was declined by your bank. Please contact your bank or try again with a different card</string>
499+
500+
<string name="error_title_onrampCardInsufficientBalance">Insufficient Funds</string>
501+
<string name="error_description_onrampCardInsufficientBalance">Please make sure you have enough funds in the account tied to your debit card and try again</string>
502+
503+
<string name="error_title_onrampCardPrepaidDeclined">Card Not Supported</string>
504+
<string name="error_description_onrampCardPrepaidDeclined">Prepaid debit cards are not supported. Please try again with another debit card</string>
505+
506+
<string name="error_title_onrampTransactionAvsValidationFailed">Billing Address Invalid</string>
507+
<string name="error_description_onrampTransactionAvsValidationFailed">Please check that your billing address is correct and try again</string>
508+
509+
<string name="error_title_onrampTransactionFailed">Something Went Wrong</string>
510+
<string name="error_description_onrampTransactionFailed">The Coinbase team has been notified and is investigating the issue. Your funds will arrive once resolved. We appreciate your patience</string>
511+
512+
<string name="error_title_onrampInternal">Something Went Wrong</string>
513+
<string name="error_description_onrampInternal">The Coinbase team has been notified and is investigating the issue. Your funds will arrive once resolved. We appreciate your patience</string>
514+
515+
<string name="error_title_onrampTransactionSendFailed">Something Went Wrong</string>
516+
<string name="error_description_onrampTransactionSendFailed">We are working with the Coinbase team to resolve the issue. Your card will be refunded in the meantime. Please try again later</string>
517+
518+
<string name="error_title_onrampInvalidRequest">Something Went Wrong</string>
519+
<string name="error_description_onrampInvalidRequest">We are working with the Coinbase team to resolve the issue. Your card will be refunded in the meantime. Please try again later</string>
520+
521+
<string name="error_title_onrampUnknownFailure">Something Went Wrong</string>
522+
<string name="error_description_onrampUnknownFailure">Please contact support@flipcash.com</string>
523+
465524
</resources>

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

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
package com.flipcash.app.cash.internal
22

33
import androidx.lifecycle.viewModelScope
4-
import com.flipcash.app.analytics.Analytics
5-
import com.flipcash.app.analytics.FlipcashAnalyticsService
64
import com.flipcash.app.core.AppRoute
75
import com.flipcash.app.core.bill.Bill
86
import com.flipcash.app.core.ui.CurrencyHolder
9-
import com.flipcash.app.onramp.ConfirmationEvent
10-
import com.flipcash.app.onramp.OnRampAmount
11-
import com.flipcash.app.onramp.OnRampAmountController
127
import com.flipcash.app.tokens.TokenCoordinator
138
import com.flipcash.features.cash.R
14-
import com.flipcash.services.internal.model.thirdparty.OnRampProvider
15-
import com.flipcash.services.internal.model.thirdparty.OnRampType
9+
import com.flipcash.libs.coroutines.DispatcherProvider
1610
import com.getcode.manager.BottomBarAction
1711
import com.getcode.manager.BottomBarManager
1812
import com.getcode.opencode.controllers.TransactionOperations
@@ -29,7 +23,6 @@ import com.getcode.solana.keys.Mint
2923
import com.getcode.ui.components.text.AmountAnimatedInputUiModel
3024
import com.getcode.ui.components.text.NumberInputHelper
3125
import com.getcode.util.resources.ResourceHelper
32-
import com.flipcash.libs.coroutines.DispatcherProvider
3326
import com.getcode.view.BaseViewModel2
3427
import com.getcode.view.LoadingSuccessState
3528
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -56,8 +49,6 @@ internal class CashScreenViewModel @Inject constructor(
5649
private val exchange: Exchange,
5750
tokenCoordinator: TokenCoordinator,
5851
transactionController: TransactionOperations,
59-
onrampController: OnRampAmountController,
60-
analytics: FlipcashAnalyticsService,
6152
dispatchers: DispatcherProvider,
6253
) : BaseViewModel2<CashScreenViewModel.State, CashScreenViewModel.Event>(
6354
initialState = State(),
@@ -76,7 +67,6 @@ internal class CashScreenViewModel @Inject constructor(
7667
val limits: Limits? = null,
7768
val maxForGive: Pair<Double, CurrencyCode>? = null,
7869
val generatingBill: LoadingSuccessState = LoadingSuccessState(),
79-
val preferredOnRampProvider: OnRampProvider? = null,
8070
) {
8171
val canGive: Boolean
8272
get() = (amountAnimatedModel.amountData.amount) > 0.00
@@ -118,10 +108,8 @@ internal class CashScreenViewModel @Inject constructor(
118108
data object OnGive : Event
119109
data class PresentBill(val bill: Bill.Cash) : Event
120110

121-
data class OnPreferredOnRampProviderChanged(val provider: OnRampProvider?) : Event
122111

123112
data class AddCashToWallet(val amount: Fiat) : Event
124-
data class OpenOnRampAmountModal(val amount: Fiat) : Event
125113
data class UpdateLoadingState(val loading: Boolean = false, val success: Boolean = false) :
126114
Event
127115

@@ -334,41 +322,16 @@ internal class CashScreenViewModel @Inject constructor(
334322
eventFlow
335323
.filterIsInstance<Event.AddCashToWallet>()
336324
.map { it.amount }
337-
.onEach { amount ->
338-
val provider = stateFlow.value.preferredOnRampProvider
339-
if (provider is OnRampProvider.Coinbase && provider.type == OnRampType.Virtual) {
340-
analytics.openOnramp(Analytics.OnrampSource.Give)
341-
// has coinbase provider supporting google pay - pop selection for quick add
342-
dispatchEvent(Event.OpenOnRampAmountModal(amount))
343-
} else {
344-
// route to buy the token
345-
dispatchEvent(
346-
Event.OpenScreen(
347-
AppRoute.Token.Info(
348-
mint = stateFlow.value.selectedTokenAddress!!,
349-
forNeededFunds = true
350-
),
351-
)
325+
.onEach {
326+
// route to buy the token
327+
dispatchEvent(
328+
Event.OpenScreen(
329+
AppRoute.Token.Info(
330+
mint = stateFlow.value.selectedTokenAddress!!,
331+
forNeededFunds = true
332+
),
352333
)
353-
}
354-
}.launchIn(viewModelScope)
355-
356-
eventFlow
357-
.filterIsInstance<Event.OpenOnRampAmountModal>()
358-
.map { onrampController.requestAmountSelection(OnRampProvider.Coinbase(OnRampType.Virtual)) }
359-
.flatMapLatest {
360-
onrampController.confirmationEvents.take(1)
361-
}.onEach { event ->
362-
when (event) {
363-
is ConfirmationEvent.OnConfirmationSuccess -> {
364-
when (event.amount) {
365-
OnRampAmount.Custom -> dispatchEvent(Event.OpenScreen(AppRoute.OnRamp.AmountEntry()))
366-
is OnRampAmount.Predefined -> Unit
367-
}
368-
}
369-
370-
ConfirmationEvent.Cancelled -> Unit
371-
}
334+
)
372335
}.launchIn(viewModelScope)
373336
}
374337

@@ -389,14 +352,8 @@ internal class CashScreenViewModel @Inject constructor(
389352
)
390353
}
391354

392-
is Event.OnPreferredOnRampProviderChanged -> { state ->
393-
state.copy(preferredOnRampProvider = event.provider)
394-
}
395-
396355
is Event.InitializeToken -> { state -> state }
397356

398-
is Event.OpenOnRampAmountModal -> { state -> state }
399-
400357
is Event.OpenScreen -> { state -> state }
401358

402359
Event.OnBackspace,

apps/flipcash/features/menu/src/main/kotlin/com/flipcash/app/menu/internal/MenuScreenContent.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,6 @@ internal fun MenuScreenContent(viewModel: MenuScreenViewModel) {
9595
modifier = Modifier
9696
.fillMaxSize()
9797
.padding(padding),
98-
header = if (state.showQuickActions) {
99-
{
100-
AddCashRow(
101-
modifier = Modifier
102-
.fillMaxWidth()
103-
.padding(
104-
horizontal = CodeTheme.dimens.inset,
105-
vertical = CodeTheme.dimens.grid.x4,
106-
),
107-
onAddCash = { viewModel.dispatchEvent(MenuScreenViewModel.Event.OnAddCashClicked) },
108-
onWithdraw = { viewModel.dispatchEvent(MenuScreenViewModel.Event.OnWithdrawClicked) },
109-
)
110-
}
111-
} else null,
11298
items = state.items,
11399
contentPadding = PaddingValues(top = CodeTheme.dimens.grid.x6),
114100
onItemClick = {

0 commit comments

Comments
 (0)