Updated on 2026-08-14

This commit is contained in:
Tangem 2023-04-21 13:56:37 +03:00
commit 8f2be76adf
3 changed files with 69 additions and 28 deletions

View file

@ -205,16 +205,7 @@ internal fun List<WalletDataModel>.updateSelectedAddress(
if (index == -1) return this
val oldWalletData = this[index]
val addresses = oldWalletData.walletAddresses
?: return this
val selectedAddress = addresses.list
.firstOrNull { it.type == addressType }
?: addresses.selectedAddress
val updatedWalletData = oldWalletData.copy(
walletAddresses = addresses.copy(
selectedAddress = selectedAddress,
),
)
val updatedWalletData = oldWalletData.updateSelectedAddress(addressType)
if (oldWalletData == updatedWalletData) return this
return this.toMutableList().apply {
@ -222,6 +213,21 @@ internal fun List<WalletDataModel>.updateSelectedAddress(
}
}
internal fun WalletDataModel.updateSelectedAddress(
addressType: AddressType,
): WalletDataModel {
val addresses = walletAddresses ?: return this
val selectedAddress = addresses.list
.firstOrNull { it.type == addressType }
?: addresses.selectedAddress
return this.copy(
walletAddresses = addresses.copy(
selectedAddress = selectedAddress,
),
)
}
internal fun WalletDataModel.isSameWalletData(other: WalletDataModel): Boolean {
return this.currency == other.currency
}

View file

@ -176,18 +176,29 @@ private fun sendTransaction(
scope.launch {
val updateWalletResult = walletManager.safeUpdate()
if (updateWalletResult is Result.Failure) {
when (val error = updateWalletResult.error) {
is TapError -> store.dispatchErrorNotification(error)
else -> {
val tapError = if (error.message == null) {
TapError.UnknownError
} else {
TapError.CustomError(error.message!!)
withMainContext {
when (val error = updateWalletResult.error) {
is TapError -> store.dispatchErrorNotification(error)
is BlockchainSdkError -> {
updateFeedbackManagerInfo(
walletManager = walletManager,
amountToSend = amountToSend,
feeAmount = feeAmount,
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)
}
store.dispatchErrorNotification(tapError)
}
dispatch(SendAction.ChangeSendButtonState(ButtonState.ENABLED))
}
withMainContext { dispatch(SendAction.ChangeSendButtonState(ButtonState.ENABLED)) }
return@launch
}
@ -250,7 +261,7 @@ private fun sendTransaction(
}
}
is SimpleResult.Failure -> {
store.state.globalState.feedbackManager?.infoHolder?.updateOnSendError(
updateFeedbackManagerInfo(
walletManager = walletManager,
amountToSend = amountToSend,
feeAmount = feeAmount,
@ -306,6 +317,20 @@ private fun sendTransaction(
}
}
private fun updateFeedbackManagerInfo(
walletManager: WalletManager,
amountToSend: Amount,
feeAmount: Amount,
destinationAddress: String,
) {
store.state.globalState.feedbackManager?.infoHolder?.updateOnSendError(
walletManager = walletManager,
amountToSend = amountToSend,
feeAmount = feeAmount,
destinationAddress = destinationAddress,
)
}
fun createValidateTransactionError(
errorList: EnumSet<TransactionError>,
walletManager: WalletManager,

View file

@ -19,15 +19,15 @@ import com.tangem.tap.features.wallet.models.PendingTransactionType
import com.tangem.tap.features.wallet.redux.WalletAction
import com.tangem.tap.features.wallet.redux.WalletMainButton
import com.tangem.tap.features.wallet.redux.WalletState
import com.tangem.tap.features.wallet.ui.BalanceWidget
import com.tangem.tap.features.wallet.ui.MultipleAddressUiHelper
import com.tangem.tap.features.wallet.ui.WalletFragment
import com.tangem.tap.features.wallet.ui.adapters.PendingTransactionsAdapter
import com.tangem.tap.features.wallet.ui.utils.getAvailableActions
import com.tangem.tap.features.wallet.ui.utils.isAvailableToBuy
import com.tangem.tap.features.wallet.ui.utils.isAvailableToSell
import com.tangem.tap.features.wallet.ui.utils.mainButton
import com.tangem.tap.features.wallet.ui.utils.shouldShowMultipleAddress
import com.tangem.tap.features.wallet.ui.BalanceWidget
import com.tangem.tap.features.wallet.ui.MultipleAddressUiHelper
import com.tangem.tap.features.wallet.ui.WalletFragment
import com.tangem.tap.features.wallet.ui.adapters.PendingTransactionsAdapter
import com.tangem.tap.features.wallet.ui.view.WalletDetailsButtonsRow
import com.tangem.tap.store
import com.tangem.wallet.R
@ -88,7 +88,12 @@ class SingleWalletView : WalletView() {
binding?.rvPendingTransaction?.show(knownTransactions.isNotEmpty())
}
// FIXME: Move to model watcher
private var watchedPrimaryWallet: WalletDataModel? = null
private fun setupBalance(state: WalletState, primaryWallet: WalletDataModel) {
if (watchedPrimaryWallet == primaryWallet) return
watchedPrimaryWallet = primaryWallet
val fragment = fragment ?: return
binding?.apply {
lCardBalance.lBalance.root.show()
@ -178,8 +183,13 @@ class SingleWalletView : WalletView() {
}
}
// FIXME: Move to model watcher
private var watchedPrimaryWallet: WalletDataModel? = null
private fun setupAddressCard(state: WalletState, binding: FragmentWalletBinding) = with(binding.lAddress) {
val primaryWallet = state.primaryWalletData
if (primaryWallet == watchedPrimaryWallet) return@with
watchedPrimaryWallet = primaryWallet
if (primaryWallet?.walletAddresses != null && primaryWallet.currency is Currency.Blockchain) {
binding.lAddress.root.show()
if (primaryWallet.shouldShowMultipleAddress()) {
@ -206,16 +216,16 @@ class SingleWalletView : WalletView() {
),
)
}
setupCardInfo(state)
setupCardInfo(primaryWallet)
} else {
binding.lAddress.root.hide()
}
}
private fun setupCardInfo(state: WalletState) {
private fun setupCardInfo(walletData: WalletDataModel) {
val textView = binding?.lAddress?.tvInfo
val blockchain = state.primaryWalletData?.currency?.blockchain
if (textView != null && blockchain != null) {
val blockchain = walletData.currency.blockchain
if (textView != null) {
textView.text = textView.getString(
id = R.string.address_qr_code_message_format,
blockchain.fullName,