Updated on 2026-08-14

This commit is contained in:
Tangem 2024-05-23 17:02:50 +08:00
parent e1540e2c5b
commit 99c984bd38
7 changed files with 133 additions and 44 deletions

View file

@ -13,11 +13,12 @@ import com.tangem.domain.balancehiding.BalanceHidingSettings
import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase
import com.tangem.domain.balancehiding.ListenToFlipsUseCase
import com.tangem.domain.balancehiding.UpdateBalanceHidingSettingsUseCase
import com.tangem.domain.feedback.FeedbackManagerFeatureToggles
import com.tangem.domain.settings.DeleteDeprecatedLogsUseCase
import com.tangem.features.send.api.featuretoggles.SendFeatureToggles
import com.tangem.domain.settings.IncrementAppLaunchCounterUseCase
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.wallets.legacy.UserWalletsListManager
import com.tangem.features.send.api.featuretoggles.SendFeatureToggles
import com.tangem.tap.common.extensions.setContext
import com.tangem.tap.features.main.model.MainScreenState
import com.tangem.tap.store
@ -41,6 +42,7 @@ internal class MainViewModel @Inject constructor(
private val userWalletsListManager: UserWalletsListManager,
private val walletManagersFacade: WalletManagersFacade,
private val sendFeatureToggles: SendFeatureToggles,
private val feedbackManagerFeatureToggles: FeedbackManagerFeatureToggles,
private val dispatchers: CoroutineDispatcherProvider,
getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase,
) : ViewModel(), MainIntents {
@ -90,15 +92,17 @@ internal class MainViewModel @Inject constructor(
Analytics.setContext(userWallet.scanResponse)
Analytics.send(Basic.WalletOpened())
store.state.globalState.feedbackManager?.infoHolder?.let { infoHolder ->
infoHolder.setCardInfo(userWallet.scanResponse)
if (!feedbackManagerFeatureToggles.isLocalLogsEnabled) {
store.state.globalState.feedbackManager?.infoHolder?.let { infoHolder ->
infoHolder.setCardInfo(userWallet.scanResponse)
walletManagersFacade
.getAll(userWallet.walletId)
.distinctUntilChanged()
.onEach(infoHolder::setWalletsInfo)
.catch { Timber.e(it) }
.launchIn(viewModelScope)
walletManagersFacade
.getAll(userWallet.walletId)
.distinctUntilChanged()
.onEach(infoHolder::setWalletsInfo)
.catch { Timber.e(it) }
.launchIn(viewModelScope)
}
}
}
.flowOn(dispatchers.io)

View file

@ -1,19 +1,21 @@
package com.tangem.tap.features.send.redux.middlewares
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.BlockchainSdkError
import com.tangem.blockchain.common.TransactionSender
import com.tangem.blockchain.common.*
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.blockchain.extensions.Result
import com.tangem.common.extensions.isZero
import com.tangem.tap.common.redux.AppState
import com.tangem.domain.demo.DemoTransactionSender
import com.tangem.domain.feedback.models.BlockchainErrorInfo
import com.tangem.tap.common.extensions.inject
import com.tangem.tap.common.extensions.stripZeroPlainString
import com.tangem.tap.common.redux.AppState
import com.tangem.tap.features.demo.isDemoCard
import com.tangem.tap.features.send.redux.AmountActionUi
import com.tangem.tap.features.send.redux.FeeAction
import com.tangem.tap.features.send.redux.ReceiptAction
import com.tangem.tap.features.send.redux.SendAction
import com.tangem.tap.features.send.redux.states.SendState
import com.tangem.tap.proxy.redux.DaggerGraphState
import com.tangem.tap.scope
import com.tangem.tap.store
import kotlinx.coroutines.Dispatchers
@ -27,6 +29,7 @@ import java.math.BigDecimal
*/
class RequestFeeMiddleware {
@Suppress("CyclomaticComplexMethod")
fun handle(appState: AppState?, dispatch: DispatchFunction) {
val sendState = appState?.sendState ?: return
val walletManager = sendState.walletManager ?: return
@ -45,7 +48,7 @@ class RequestFeeMiddleware {
val txSender = if (scanResponse.isDemoCard()) {
DemoTransactionSender(walletManager)
} else {
walletManager as TransactionSender
walletManager
}
scope.launch {
val feeResult = txSender.getFee(destinationAmount, destinationAddress)
@ -73,12 +76,17 @@ class RequestFeeMiddleware {
dispatch(FeeAction.FeeCalculation.ClearResult)
dispatch(FeeAction.ChangeLayoutVisibility(main = false))
store.state.globalState.feedbackManager?.infoHolder?.updateOnSendError(
walletManager = walletManager,
amountToSend = destinationAmount,
feeAmount = null,
destinationAddress = destinationAddress,
)
val featureToggles = store.inject(DaggerGraphState::feedbackManagerFeatureToggles)
if (featureToggles.isLocalLogsEnabled) {
saveBlockchainError(feeResult, destinationAddress, destinationAmount, walletManager)
} else {
store.state.globalState.feedbackManager?.infoHolder?.updateOnSendError(
walletManager = walletManager,
amountToSend = destinationAmount,
feeAmount = null,
destinationAddress = destinationAddress,
)
}
val blockchainSdkError = feeResult.error as? BlockchainSdkError ?: return@withContext
dispatch(
@ -93,4 +101,28 @@ class RequestFeeMiddleware {
}
}
}
private fun saveBlockchainError(
feeResult: Result.Failure,
destinationAddress: String,
destinationAmount: Amount,
walletManager: WalletManager,
) {
store.inject(DaggerGraphState::saveBlockchainErrorUseCase).invoke(
error = BlockchainErrorInfo(
errorMessage = (feeResult.error as? BlockchainSdkError)?.customMessage
?: "It isn't BlockchainSdkError",
blockchainId = walletManager.wallet.blockchain.id,
derivationPath = walletManager.wallet.publicKey.derivationPath?.rawPath ?: "",
destinationAddress = destinationAddress,
tokenSymbol = if (destinationAmount.type is AmountType.Token) {
destinationAmount.currencySymbol
} else {
""
},
amount = destinationAmount.value?.stripZeroPlainString() ?: "0",
fee = null,
),
)
}
}

View file

@ -21,6 +21,7 @@ import com.tangem.core.navigation.NavigationAction
import com.tangem.domain.common.TapWorkarounds.isStart2Coin
import com.tangem.domain.common.extensions.withMainContext
import com.tangem.domain.demo.DemoTransactionSender
import com.tangem.domain.feedback.models.BlockchainErrorInfo
import com.tangem.domain.models.scan.CardDTO
import com.tangem.domain.tokens.legacy.TradeCryptoAction
import com.tangem.tap.common.analytics.events.Token
@ -274,6 +275,7 @@ private fun sendTransaction(
}
is SimpleResult.Failure -> {
updateFeedbackManagerInfo(
sendResult = sendResult.error,
walletManager = walletManager,
amountToSend = amountToSend,
feeAmount = fee.amount,
@ -364,13 +366,33 @@ private fun updateFeedbackManagerInfo(
amountToSend: Amount,
feeAmount: Amount,
destinationAddress: String,
sendResult: BlockchainError,
) {
store.state.globalState.feedbackManager?.infoHolder?.updateOnSendError(
walletManager = walletManager,
amountToSend = amountToSend,
feeAmount = feeAmount,
destinationAddress = destinationAddress,
)
val featureToggles = store.inject(DaggerGraphState::feedbackManagerFeatureToggles)
if (featureToggles.isLocalLogsEnabled) {
store.inject(DaggerGraphState::saveBlockchainErrorUseCase).invoke(
error = BlockchainErrorInfo(
errorMessage = (sendResult as? BlockchainSdkError)?.customMessage ?: "It isn't BlockchainSdkError",
blockchainId = walletManager.wallet.blockchain.id,
derivationPath = walletManager.wallet.publicKey.derivationPath?.rawPath ?: "",
destinationAddress = destinationAddress,
tokenSymbol = if (amountToSend.type is AmountType.Token) {
amountToSend.currencySymbol
} else {
""
},
amount = amountToSend.value?.stripZeroPlainString() ?: "0",
fee = feeAmount.value?.stripZeroPlainString() ?: "0",
),
)
} else {
store.state.globalState.feedbackManager?.infoHolder?.updateOnSendError(
walletManager = walletManager,
amountToSend = amountToSend,
feeAmount = feeAmount,
destinationAddress = destinationAddress,
)
}
}
fun createValidateTransactionError(