diff --git a/app/src/main/java/com/tangem/tap/domain/walletconnect2/data/WalletConnectRepositoryImpl.kt b/app/src/main/java/com/tangem/tap/domain/walletconnect2/data/WalletConnectRepositoryImpl.kt index 01e3803798..12c5510122 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletconnect2/data/WalletConnectRepositoryImpl.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletconnect2/data/WalletConnectRepositoryImpl.kt @@ -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,29 @@ 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 optionalNamespace = sessionProposal.optionalNamespaces[requiredNamespace.key] + val accountsOptional = optionalNamespace?.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() + val methods = (requiredNamespace.value.methods + (optionalNamespace?.methods ?: emptyList())) + .distinct() + requiredNamespace.key to Wallet.Model.Namespace.Session( + accounts = (accountsRequired + accountsOptional).distinct(), + methods = 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") diff --git a/app/src/main/java/com/tangem/tap/domain/walletconnect2/domain/WalletConnectInteractor.kt b/app/src/main/java/com/tangem/tap/domain/walletconnect2/domain/WalletConnectInteractor.kt index ef202cd085..7d929df9fc 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletconnect2/domain/WalletConnectInteractor.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletconnect2/domain/WalletConnectInteractor.kt @@ -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) diff --git a/app/src/main/java/com/tangem/tap/domain/walletconnect2/domain/models/WalletConnectEvents.kt b/app/src/main/java/com/tangem/tap/domain/walletconnect2/domain/models/WalletConnectEvents.kt index bec06dd554..e481daa22d 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletconnect2/domain/models/WalletConnectEvents.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletconnect2/domain/models/WalletConnectEvents.kt @@ -9,7 +9,8 @@ sealed interface WalletConnectEvents { val description: String, val url: String, val icons: List, - val chainIds: List, + val requiredChainIds: List, + val optionalChainIds: List, ) : WalletConnectEvents data class SessionApprovalError(val error: WalletConnectError) : WalletConnectEvents diff --git a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListScreen.kt b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListScreen.kt index 44e620b8ac..6896480058 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListScreen.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListScreen.kt @@ -25,9 +25,6 @@ import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.AnnotatedString -import androidx.compose.ui.text.SpanStyle -import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp @@ -155,18 +152,8 @@ private fun DifferentAddressesWarning() { contentAlignment = Alignment.Center, ) { val text = stringResource(id = R.string.alert_manage_tokens_addresses_message) - val firstSpaceIndex = text.indexOf(" ") Text( - text = AnnotatedString( - text = text, - spanStyles = listOf( - AnnotatedString.Range( - SpanStyle(fontWeight = FontWeight.Bold), - start = 0, - end = firstSpaceIndex, - ), - ), - ), + text = text, modifier = Modifier.padding( horizontal = TangemTheme.dimens.spacing16, vertical = TangemTheme.dimens.spacing8, diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/utils/WalletDataOperations.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/utils/WalletDataOperations.kt index 3f72a34acb..4f9f9d5453 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/utils/WalletDataOperations.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/utils/WalletDataOperations.kt @@ -12,7 +12,6 @@ import com.tangem.tap.common.extensions.toFormattedCurrencyString import com.tangem.tap.common.extensions.toFormattedFiatValue import com.tangem.tap.domain.model.WalletDataModel import com.tangem.tap.domain.model.WalletStoreModel -import com.tangem.tap.features.wallet.models.PendingTransactionType import com.tangem.tap.features.wallet.models.WalletWarning import com.tangem.tap.features.wallet.redux.WalletMainButton import com.tangem.tap.features.wallet.redux.utils.UNKNOWN_AMOUNT_SIGN @@ -27,14 +26,15 @@ internal fun WalletDataModel.mainButton(blockchainAmount: BigDecimal): WalletMai internal fun WalletDataModel.hasPendingTransactions(): Boolean { // for now check pending ongoing only just for BTC, later test and add other utxo networks - val isBitcoinBlockchain = - currency.blockchain == Blockchain.Bitcoin || currency.blockchain == Blockchain.BitcoinTestnet - if (currency.isBlockchain() && isBitcoinBlockchain) { - val outgoingTransactions = status.pendingTransactions.filter { - it.type == PendingTransactionType.Outgoing - } - return outgoingTransactions.isEmpty() - } + // disabled for release 4.8, test and enable in 4.9 + // val isBitcoinBlockchain = + // currency.blockchain == Blockchain.Bitcoin || currency.blockchain == Blockchain.BitcoinTestnet + // if (currency.isBlockchain() && isBitcoinBlockchain) { + // val outgoingTransactions = status.pendingTransactions.filter { + // it.type == PendingTransactionType.Outgoing + // } + // return outgoingTransactions.isEmpty() + // } return status.pendingTransactions.isEmpty() } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/view/TotalBalanceCard.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/view/TotalBalanceCard.kt index d89d245766..fdfadc43e1 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/view/TotalBalanceCard.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/view/TotalBalanceCard.kt @@ -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) diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index b39d1e0b90..042782007e 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -73,8 +73,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