Updated on 2026-08-14

This commit is contained in:
Tangem 2023-07-04 15:05:31 +03:00
commit f0ed44d3ed
5 changed files with 44 additions and 23 deletions

View file

@ -1,6 +1,7 @@
package com.tangem.tap.domain.walletconnect2.data
import android.app.Application
import arrow.core.flatten
import com.tangem.tap.domain.walletconnect2.domain.WalletConnectRepository
import com.tangem.tap.domain.walletconnect2.domain.WcJrpcRequestsDeserializer
import com.tangem.tap.domain.walletconnect2.domain.models.*
@ -97,6 +98,7 @@ class WalletConnectRepositoryImpl @Inject constructor(
sessionProposal.url,
sessionProposal.icons,
sessionProposal.requiredNamespaces.values.flatMap { it.chains ?: emptyList() },
sessionProposal.optionalNamespaces.values.flatMap { it.chains ?: emptyList() },
),
)
}
@ -187,6 +189,7 @@ class WalletConnectRepositoryImpl @Inject constructor(
namespaces = sessionProposal.requiredNamespaces,
userNamespaces = userNamespaces,
)
if (missingNetworks.isNotEmpty()) {
Timber.e("Not added blockchains: $missingNetworks")
scope.launch {
@ -204,17 +207,26 @@ class WalletConnectRepositoryImpl @Inject constructor(
}.groupBy { pair -> pair.first }
.mapValues { entry -> entry.value.map { pair -> pair.second }.toSet() }
val preparedNamespaces = sessionProposal.requiredNamespaces.map { requiredNamespace ->
val accounts = requiredNamespace.value.chains?.mapNotNull { userChains[it] }?.flatten() ?: emptyList()
val preparedNamespaces = sessionProposal.requiredNamespaces
.map { requiredNamespace ->
val accountsRequired = requiredNamespace.value.chains
?.mapNotNull { chain -> userChains[chain] }
?.flatten() ?: emptyList()
val accountsOptional = sessionProposal.optionalNamespaces[requiredNamespace.key]?.chains
?.mapNotNull { chain -> userChains[chain] }
?.flatten() ?: emptyList()
requiredNamespace.key to Wallet.Model.Namespace.Session(
accounts = accounts,
methods = requiredNamespace.value.methods,
events = requiredNamespace.value.events,
)
}.toMap()
requiredNamespace.key to Wallet.Model.Namespace.Session(
accounts = accountsRequired + accountsOptional,
methods = requiredNamespace.value.methods,
events = requiredNamespace.value.events,
)
}.toMap()
val sessionApproval = Wallet.Params.SessionApprove(sessionProposal.proposerPublicKey, preparedNamespaces)
val sessionApproval = Wallet.Params.SessionApprove(
proposerPublicKey = sessionProposal.proposerPublicKey,
namespaces = preparedNamespaces,
)
Timber.d("Session approval is prepared for sending: $sessionApproval")

View file

@ -50,15 +50,15 @@ class WalletConnectInteractor(
when (wcEvent) {
is WalletConnectEvents.SessionProposal -> {
Timber.d("WC session proposal event received")
val unsupportedNetworks = wcEvent.chainIds
val unsupportedNetworks = wcEvent.requiredChainIds
.filter { blockchainHelper.chainIdToNetworkIdOrNull(it) == null }
if (unsupportedNetworks.isNotEmpty()) {
val error = WalletConnectError.ApprovalErrorUnsupportedNetwork(unsupportedNetworks)
handler.onSessionRejected(error)
return@onEach
}
val networksFormatted = wcEvent.chainIds
val networksFormatted = (wcEvent.requiredChainIds + wcEvent.optionalChainIds)
.distinct()
.mapNotNull { blockchainHelper.chainIdToFullNameOrNull(it) }
.toString()
handler.onProposalReceived(proposal = wcEvent, networksFormatted = networksFormatted)

View file

@ -9,7 +9,8 @@ sealed interface WalletConnectEvents {
val description: String,
val url: String,
val icons: List<URI>,
val chainIds: List<String>,
val requiredChainIds: List<String>,
val optionalChainIds: List<String>,
) : WalletConnectEvents
data class SessionApprovalError(val error: WalletConnectError) : WalletConnectEvents

View file

@ -27,6 +27,7 @@ import com.tangem.tap.domain.model.TotalFiatBalance
import com.tangem.tap.features.wallet.redux.utils.UNKNOWN_AMOUNT_SIGN
import com.tangem.wallet.R
import com.valentinilk.shimmer.shimmer
import timber.log.Timber
import java.math.BigDecimal
import java.math.RoundingMode
import java.text.DecimalFormat
@ -227,14 +228,21 @@ private fun buildAmountString(amount: BigDecimal?, fiatCurrency: FiatCurrency):
?: return AnnotatedString("${amount.toPlainString()} ${fiatCurrency.symbol}")
val currencyToShow = "${fiatCurrency.symbol}"
val scaledAmount = Currency.getInstance(fiatCurrency.code)?.let { currency ->
formatter.currency = currency
formatter.maximumFractionDigits = fractionDigits
formatter.minimumFractionDigits = fractionDigits
formatter.isGroupingUsed = true
formatter.roundingMode = RoundingMode.HALF_UP
formatter.format(amount).replace(currency.symbol, currencyToShow)
} ?: formatter.format(amount)
val scaledAmount = try {
Currency.getInstance(fiatCurrency.code)?.let { currency ->
formatter.currency = currency
formatter.maximumFractionDigits = fractionDigits
formatter.minimumFractionDigits = fractionDigits
formatter.isGroupingUsed = true
formatter.roundingMode = RoundingMode.HALF_UP
formatter.format(amount).replace(currency.symbol, currencyToShow)
} ?: formatter.format(amount)
} catch (e: IllegalArgumentException) {
Timber.e("TotalBalanceCard buildAmountString currencyCode is not a supported ISO 4217 code: $e")
formatter.currency?.let {
formatter.format(amount).replace(it.symbol, currencyToShow)
} ?: formatter.format(amount)
}
val integer = scaledAmount.substringBefore(formatter.decimalFormatSymbols.decimalSeparator)
var reminder = scaledAmount.substringAfter(formatter.decimalFormatSymbols.decimalSeparator)

View file

@ -72,8 +72,8 @@ mviCore = "1.3.1"
kotlinSerialization = "1.4.1"
arrow = "1.2.0-RC"
reactiveNetwork = "3.0.8"
walletConnectCore = "1.15.0"
walletConnectWeb3 = "1.8.0"
walletConnectCore = "1.17.0"
walletConnectWeb3 = "1.10.0"
# endregion Other libraries
# region Tangem