Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-10 22:14:03 +03:00
parent 8027be74aa
commit a730af0f1f
9 changed files with 174 additions and 35 deletions

View file

@ -28,6 +28,14 @@ internal object TokensDomainModule {
return FetchTokenListUseCase(currenciesRepository, networksRepository, quotesRepository)
}
@Provides
@ViewModelScoped
fun provideFetchPendingTransactionsUseCase(
networksRepository: NetworksRepository,
): FetchPendingTransactionsUseCase {
return FetchPendingTransactionsUseCase(networksRepository)
}
@Provides
@ViewModelScoped
fun provideGetTokenListUseCase(

View file

@ -12,7 +12,6 @@ import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.extensions.SimpleResult
import com.tangem.common.core.TangemSdkError
import com.tangem.common.extensions.guard
import com.tangem.common.services.Result
import com.tangem.core.analytics.Analytics
import com.tangem.core.navigation.NavigationAction
import com.tangem.domain.common.TapWorkarounds.isStart2Coin
@ -174,33 +173,35 @@ private fun sendTransaction(
transactionExtras.tonMemoState?.memo?.let { txData = txData.copy(extras = TonTransactionExtras(it)) }
scope.launch {
val updateWalletResult = walletManager.safeUpdate()
if (updateWalletResult is Result.Failure) {
withMainContext {
when (val error = updateWalletResult.error) {
is TapError -> store.dispatchErrorNotification(error)
is BlockchainSdkError -> {
updateFeedbackManagerInfo(
walletManager = walletManager,
amountToSend = amountToSend,
feeAmount = fee.amount,
destinationAddress = destinationAddress,
)
dispatch(SendAction.Dialog.SendTransactionFails.BlockchainSdkError(error = error))
}
else -> {
val tapError = if (error.message == null) {
TapError.UnknownError
} else {
TapError.CustomError(error.message!!)
}
store.dispatchErrorNotification(tapError)
}
}
dispatch(SendAction.ChangeSendButtonState(ButtonState.ENABLED))
}
return@launch
}
// TODO: Risky commented this part, unknown logic, need to test if removed
// TODO: [REDACTED_JIRA]
// val updateWalletResult = walletManager.safeUpdate()
// if (updateWalletResult is Result.Failure) {
// withMainContext {
// when (val error = updateWalletResult.error) {
// is TapError -> store.dispatchErrorNotification(error)
// is BlockchainSdkError -> {
// updateFeedbackManagerInfo(
// walletManager = walletManager,
// amountToSend = amountToSend,
// feeAmount = fee.amount,
// destinationAddress = destinationAddress,
// )
// dispatch(SendAction.Dialog.SendTransactionFails.BlockchainSdkError(error = error))
// }
// else -> {
// val tapError = if (error.message == null) {
// TapError.UnknownError
// } else {
// TapError.CustomError(error.message!!)
// }
// store.dispatchErrorNotification(tapError)
// }
// }
// dispatch(SendAction.ChangeSendButtonState(ButtonState.ENABLED))
// }
// return@launch
// }
val tangemSdk = store.state.daggerGraphState.get(DaggerGraphState::cardSdkConfigRepository).sdk
val linkedTerminalState = tangemSdk.config.linkedTerminal

View file

@ -3,6 +3,7 @@ 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.FetchPendingTransactionsUseCase
import com.tangem.domain.tokens.UpdateDelayedNetworkStatusUseCase
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.Network
@ -32,6 +33,7 @@ internal class SendViewModel @Inject constructor(
private val listenToFlipsUseCase: ListenToFlipsUseCase,
private val updateDelayedCurrencyStatusUseCase: UpdateDelayedNetworkStatusUseCase,
private val getSelectedWalletUseCase: GetSelectedWalletUseCase,
private val fetchPendingTransactionsUseCase: FetchPendingTransactionsUseCase,
@DelayedWork private val coroutineScope: CoroutineScope,
savedStateHandle: SavedStateHandle,
) : ViewModel(), DefaultLifecycleObserver {
@ -75,12 +77,7 @@ internal class SendViewModel @Inject constructor(
}
private suspend fun updateForPendingTx(userWallet: UserWallet, network: Network) {
updateDelayedCurrencyStatusUseCase(
userWalletId = userWallet.walletId,
network = network,
delayMillis = UPDATE_PENDING_TX_DELAY_MILLIS,
refresh = true,
)
fetchPendingTransactionsUseCase(userWallet.walletId, setOf(network))
}
private suspend fun updateForBalance(userWallet: UserWallet, network: Network) {
@ -94,7 +91,6 @@ internal class SendViewModel @Inject constructor(
companion object {
private const val UPDATE_BALANCE_DELAY_MILLIS = 11000L
private const val UPDATE_PENDING_TX_DELAY_MILLIS = 1000L
private const val TAG = "SendViewModel"
}
}