Skip to content

Commit dd08bf7

Browse files
committed
chore(tokens): update activity feed post buy/sell; add proper loading states before transition to processing
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 2c9585e commit dd08bf7

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@ class TokenBuySellEntryScreen(
4343

4444
@Composable
4545
override fun ModalContent() {
46-
val context = LocalContext.current
4746
val navigator = LocalCodeNavigator.current
4847
val viewModel = getStackScopedViewModel<BuySellSwapTokenViewModel>(BuySellFlow.key)
4948
val state by viewModel.stateFlow.collectAsStateWithLifecycle()
5049
val externalWalletOnRamp = LocalExternalWalletState.current
51-
val permissions = LocalPermissionChecker.current
52-
val composeScope = rememberCoroutineScope()
5350

5451
Column(
5552
modifier = Modifier.fillMaxSize(),

apps/flipcash/shared/tokens/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dependencies {
5555
implementation(Libs.androidx_datastore)
5656

5757
implementation(project(":apps:flipcash:core"))
58+
implementation(project(":apps:flipcash:shared:activityfeed"))
5859
implementation(project(":apps:flipcash:shared:featureflags"))
5960
implementation(project(":apps:flipcash:shared:onramp:deeplinks"))
6061
implementation(project(":apps:flipcash:shared:shareable"))

apps/flipcash/shared/tokens/src/main/kotlin/BuySellSwapTokenViewModel.kt

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

33
import androidx.lifecycle.viewModelScope
4+
import com.flipcash.app.activityfeed.ActivityFeedCoordinator
45
import com.flipcash.app.core.extensions.onResult
56
import com.flipcash.app.core.extensions.to
67
import com.flipcash.app.core.tokens.TokenSwapPurpose
78
import com.flipcash.app.core.ui.CurrencyHolder
9+
import com.flipcash.services.controllers.ActivityFeedController
810
import com.flipcash.services.user.UserManager
911
import com.flipcash.shared.tokens.R
1012
import com.getcode.manager.BottomBarManager
@@ -65,11 +67,11 @@ class BuySellSwapTokenViewModel @Inject constructor(
6567
transactionController: TransactionController,
6668
resources: ResourceHelper,
6769
tokenController: TokenController,
70+
feedCoordinator: ActivityFeedCoordinator,
6871
) : BaseViewModel2<BuySellSwapTokenViewModel.State, BuySellSwapTokenViewModel.Event>(
6972
initialState = State(),
7073
updateStateForEvent = updateStateForEvent,
7174
) {
72-
7375
private val numberInputHelper = NumberInputHelper()
7476

7577
data class State(
@@ -93,7 +95,7 @@ class BuySellSwapTokenViewModel @Inject constructor(
9395
val tokenName: String
9496
get() = tokenWithBalance?.token?.name.orEmpty()
9597
val canTransact: Boolean
96-
get() = (amountEntryState.amountAnimatedModel.amountData.amount) > 0.00
98+
get() = (amountEntryState.amountAnimatedModel.amountData.amount) > 0.00 && buyProgress.isIdle && sellProgress.isIdle && processingProgress.isIdle
9799

98100
val maxAvailableToSwap: String
99101
get() = when (purpose) {
@@ -475,6 +477,7 @@ class BuySellSwapTokenViewModel @Inject constructor(
475477
)
476478

477479
dispatchEvent(Event.OnAmountAccepted(amountFiat))
480+
dispatchEvent(Event.UpdateBuyState(loading = true))
478481
dispatchEvent(
479482
Event.CreateAndSendTransactionToWallet(
480483
token = stateFlow.value.tokenWithBalance!!.token,
@@ -509,6 +512,7 @@ class BuySellSwapTokenViewModel @Inject constructor(
509512

510513
eventFlow
511514
.filterIsInstance<Event.ProceedWithPurchase>()
515+
.onEach { dispatchEvent(Event.UpdateBuyState(loading = true)) }
512516
.map { it.amount }
513517
.mapNotNull { amount ->
514518
val owner = userManager.accountCluster ?: return@mapNotNull null
@@ -537,6 +541,7 @@ class BuySellSwapTokenViewModel @Inject constructor(
537541

538542
eventFlow
539543
.filterIsInstance<Event.ProceedWithSale>()
544+
.onEach { dispatchEvent(Event.UpdateSellState(loading = true)) }
540545
.map { it.amount }
541546
.mapNotNull { amount ->
542547
val owner = userManager.accountCluster ?: return@mapNotNull null
@@ -581,6 +586,10 @@ class BuySellSwapTokenViewModel @Inject constructor(
581586
onSuccess = {
582587
val token = stateFlow.value.tokenWithBalance!!.token
583588
viewModelScope.launch { tokenController.updateTokenAccount(token) }
589+
viewModelScope.launch {
590+
// update activity feed to grab the tx as a result of this buy/sell
591+
feedCoordinator.fetchSinceLatest()
592+
}
584593
dispatchEvent(Event.OnTransactionSuccessful)
585594
dispatchEvent(Event.UpdateProcessingState(loading = false, success = true))
586595
},

0 commit comments

Comments
 (0)