Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-02 19:26:30 +03:00
parent a08b715f36
commit 2d1f7a0cd2
18 changed files with 193 additions and 8 deletions

View file

@ -270,9 +270,7 @@ private fun sendTransaction(
dispatch(NavigationAction.PopBackTo())
}
scope.launch(Dispatchers.IO) {
updateWallet(walletManager)
delay(timeMillis = 11000) // more than 10000 to avoid throttling
updateWallet(walletManager)
updateAfterTransaction(walletManager)
}
}
is SimpleResult.Failure -> {
@ -414,6 +412,19 @@ private fun updateWarnings(dispatch: (Action) -> Unit) {
dispatch(SendAction.Warnings.Set(warnings))
}
private suspend fun updateAfterTransaction(walletManager: WalletManager) {
val walletFeatureToggles = store.state.daggerGraphState.get(DaggerGraphState::walletFeatureToggles)
if (!walletFeatureToggles.isRedesignedScreenEnabled) {
updateWalletsLegacy(walletManager)
}
}
private suspend fun updateWalletsLegacy(walletManager: WalletManager) {
updateWallet(walletManager)
delay(timeMillis = 11000) // more than 10000 to avoid throttling
updateWallet(walletManager)
}
private suspend fun updateWallet(walletManager: WalletManager) {
val selectedUserWallet = userWalletsListManager.selectedUserWalletSync.guard {
Timber.e("Unable to update wallet, no user wallet selected")

View file

@ -53,6 +53,7 @@ private class SendReducer : SendInternalReducer {
is SendAction.Dialog.Hide -> sendState.copy(dialog = null)
is SendAction.Warnings.Set -> sendState.copy(sendWarningsList = action.warningList)
is SendAction.SendSpecificTransaction -> handleSendSpecificTransactionAction(action, sendState)
is SendAction.SendSuccess -> sendState.copy(isSuccessSend = true)
else -> return sendState
}

View file

@ -43,6 +43,7 @@ data class SendState(
val sendButtonState: IndeterminateProgressButton = IndeterminateProgressButton(ButtonState.DISABLED),
val dialog: StateDialog? = null,
val externalTransactionData: ExternalTransactionData? = null,
val isSuccessSend: Boolean = false,
) : SendScreenState {
override val stateId: StateId = StateId.SEND_SCREEN

View file

@ -76,6 +76,7 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycle.addObserver(viewModel)
sendSubscriber.initViewModel(viewModel)
Analytics.send(Token.Send.ScreenOpened())
}

View file

@ -3,23 +3,39 @@ package com.tangem.tap.features.send.ui
import androidx.lifecycle.*
import com.tangem.domain.balancehiding.IsBalanceHiddenUseCase
import com.tangem.domain.balancehiding.ListenToFlipsUseCase
import com.tangem.domain.tokens.UpdateDelayedNetworkStatusUseCase
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.wallets.usecase.GetSelectedWalletUseCase
import com.tangem.features.send.navigation.SendRouter
import com.tangem.tap.di.DelayedWork
import com.tangem.tap.features.send.redux.AmountAction
import com.tangem.tap.proxy.AppStateHolder
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber
import javax.inject.Inject
@Suppress("LongParameterList")
@HiltViewModel
internal class SendViewModel @Inject constructor(
private val dispatchers: CoroutineDispatcherProvider,
private val appStateHolder: AppStateHolder,
private val isBalanceHiddenUseCase: IsBalanceHiddenUseCase,
private val listenToFlipsUseCase: ListenToFlipsUseCase,
private val updateDelayedCurrencyStatusUseCase: UpdateDelayedNetworkStatusUseCase,
private val getSelectedWalletUseCase: GetSelectedWalletUseCase,
@DelayedWork private val coroutineScope: CoroutineScope,
savedStateHandle: SavedStateHandle,
) : ViewModel(), DefaultLifecycleObserver {
private val cryptoCurrency: CryptoCurrency? = savedStateHandle[SendRouter.CRYPTO_CURRENCY_KEY]
override fun onCreate(owner: LifecycleOwner) {
isBalanceHiddenUseCase()
.flowWithLifecycle(owner.lifecycle)
@ -36,4 +52,24 @@ internal class SendViewModel @Inject constructor(
.collect()
}
}
fun updateCurrencyDelayed() {
if (cryptoCurrency != null) {
coroutineScope.launch {
getSelectedWalletUseCase()
.fold(
ifLeft = { Timber.e(it.toString()) },
ifRight = { wallet ->
updateDelayedCurrencyStatusUseCase(wallet.walletId, cryptoCurrency.network, true)
},
)
}
} else {
Timber.w("$TAG: cryptoCurrency is null, legacy flow")
}
}
companion object {
private const val TAG = "SendViewModel"
}
}

View file

@ -18,6 +18,7 @@ import com.tangem.tap.features.send.redux.SendAction
import com.tangem.tap.features.send.redux.states.*
import com.tangem.tap.features.send.ui.FeeUiHelper
import com.tangem.tap.features.send.ui.SendFragment
import com.tangem.tap.features.send.ui.SendViewModel
import com.tangem.tap.features.send.ui.dialogs.*
import com.tangem.tap.features.wallet.redux.ProgressState
import com.tangem.tap.features.wallet.redux.utils.ROUGH_SIGN
@ -29,13 +30,23 @@ import com.tangem.wallet.R
[REDACTED_AUTHOR]
*/
@Suppress("LargeClass")
class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber<SendState>(fragment) {
internal class SendStateSubscriber(
fragment: BaseStoreFragment,
) : FragmentStateSubscriber<SendState>(fragment) {
private var dialog: Dialog? = null
private var sendViewModel: SendViewModel? = null
fun initViewModel(viewModel: SendViewModel) {
sendViewModel = viewModel
}
override fun updateWithNewState(fg: BaseStoreFragment, state: SendState) {
fg.view ?: return
if (fg !is SendFragment) return
if (state.isSuccessSend) {
sendViewModel?.updateCurrencyDelayed()
return
}
val lastChangedStates = state.lastChangedStates.toList()
state.lastChangedStates.clear()