From d02dac09ecb1bba6b01701125b3864c34c36c9f5 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 22 Sep 2022 17:07:13 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../java/com/tangem/tap/domain/TapErrors.kt | 8 +++- .../walletconnect/WalletConnectManager.kt | 33 ++++++++++----- .../walletconnect/extensions/WcPeerMeta.kt | 9 ++++ .../walletconnect/WalletConnectAction.kt | 3 +- .../walletconnect/WalletConnectMiddleware.kt | 41 ++++++++++++------- app/src/main/res/values-de/strings_final.xml | 2 + app/src/main/res/values-fr/strings_final.xml | 2 + app/src/main/res/values-it/strings_final.xml | 2 + app/src/main/res/values-ru/strings_final.xml | 2 + app/src/main/res/values/strings_final.xml | 2 + 10 files changed, 75 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/com/tangem/tap/domain/walletconnect/extensions/WcPeerMeta.kt diff --git a/app/src/main/java/com/tangem/tap/domain/TapErrors.kt b/app/src/main/java/com/tangem/tap/domain/TapErrors.kt index 9d3cc79eee..03dc7f645b 100644 --- a/app/src/main/java/com/tangem/tap/domain/TapErrors.kt +++ b/app/src/main/java/com/tangem/tap/domain/TapErrors.kt @@ -41,7 +41,7 @@ sealed class TapError( data class UnsupportedState( val stateError: String, - val customMessage: String = "Unsupported state:" + val customMessage: String = "Unsupported state:", ) : TapError(R.string.common_custom_string, listOf("$customMessage $stateError")) sealed class WalletManager { @@ -52,9 +52,13 @@ sealed class TapError( object BlockchainIsUnreachableTryLater : TapError(R.string.wallet_balance_blockchain_unreachable_try_later) } + sealed class WalletConnect { + object UnsupportedDapp : TapError(R.string.wallet_connect_error_unsupported_dapp) + } + data class ValidateTransactionErrors( override val errorList: List, - override val builder: (List) -> String + override val builder: (List) -> String, ) : TapError(-1), MultiMessageError } diff --git a/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectManager.kt b/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectManager.kt index 7e4fae297a..064c3b180b 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectManager.kt @@ -5,6 +5,8 @@ import com.tangem.common.extensions.guard import com.tangem.tap.common.analytics.Analytics import com.tangem.tap.common.extensions.dispatchOnMain import com.tangem.tap.common.redux.global.GlobalAction +import com.tangem.tap.domain.TapError +import com.tangem.tap.domain.walletconnect.extensions.isDappSupported import com.tangem.tap.features.details.redux.walletconnect.WalletConnectAction import com.tangem.tap.features.details.redux.walletconnect.WalletConnectDialog import com.tangem.tap.features.details.redux.walletconnect.WalletConnectSession @@ -325,21 +327,30 @@ class WalletConnectManager { val session = client.session val data = sessions[session]?.copy(peerMeta = peer, remotePeerId = client.remotePeerId) if (data != null && session != null) { - sessions[session] = data - val sessionData = data.toWalletConnectSession() - sessionData?.let { + if (!peer.isDappSupported()) { store.dispatchOnMain( - WalletConnectAction.ScanCard( - session = sessionData, - chainId = client.chainId?.toIntOrNull() + WalletConnectAction.FailureEstablishingSession( + session = session, + error = TapError.WalletConnect.UnsupportedDapp, + ), + ) + } else { + sessions[session] = data + val sessionData = data.toWalletConnectSession() + sessionData?.let { + store.dispatchOnMain( + WalletConnectAction.ScanCard( + session = sessionData, + chainId = client.chainId?.toIntOrNull(), + ), ) + } + store.state.globalState.analyticsHandlers?.logWcEvent( + Analytics.WcAnalyticsEvent.Session( + Analytics.WcSessionEvent.Connect, peer.url, + ), ) } - store.state.globalState.analyticsHandlers?.logWcEvent( - Analytics.WcAnalyticsEvent.Session( - Analytics.WcSessionEvent.Connect, peer.url - ) - ) } } client.onSessionUpdate = { id: Long, update: WCSessionUpdate -> diff --git a/app/src/main/java/com/tangem/tap/domain/walletconnect/extensions/WcPeerMeta.kt b/app/src/main/java/com/tangem/tap/domain/walletconnect/extensions/WcPeerMeta.kt new file mode 100644 index 0000000000..057caf7bd2 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/domain/walletconnect/extensions/WcPeerMeta.kt @@ -0,0 +1,9 @@ +package com.tangem.tap.domain.walletconnect.extensions + +import com.trustwallet.walletconnect.models.WCPeerMeta + +fun WCPeerMeta.isDappSupported(): Boolean { + return !unsupportedDappsList.any { this.url.contains(it) } +} + +private val unsupportedDappsList: List = listOf("dydx.exchange") \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectAction.kt b/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectAction.kt index 14a871fbd9..9106094b1a 100644 --- a/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectAction.kt +++ b/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectAction.kt @@ -2,6 +2,7 @@ package com.tangem.tap.features.details.redux.walletconnect import com.tangem.blockchain.common.Blockchain import com.tangem.tap.common.redux.NotificationAction +import com.tangem.tap.domain.TapError import com.tangem.wallet.R import com.trustwallet.walletconnect.models.binance.WCBinanceTradeOrder import com.trustwallet.walletconnect.models.binance.WCBinanceTransferOrder @@ -53,7 +54,7 @@ sealed class WalletConnectAction : Action { val updatedSession: WalletConnectSession, ) : WalletConnectAction() - data class FailureEstablishingSession(val session: WCSession?) : WalletConnectAction() + data class FailureEstablishingSession(val session: WCSession?, val error: TapError? = null) : WalletConnectAction() data class SetSessionsRestored(val sessions: List) : WalletConnectAction() diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt b/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt index d98fb0b0f5..faf6594595 100644 --- a/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt @@ -8,6 +8,7 @@ import com.tangem.domain.common.ScanResponse import com.tangem.domain.common.TapWorkarounds.derivationStyle import com.tangem.domain.common.extensions.withMainContext import com.tangem.tap.common.extensions.dispatchOnMain +import com.tangem.tap.common.redux.AppDialog import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.common.redux.navigation.AppScreen @@ -90,6 +91,16 @@ class WalletConnectMiddleware { store.dispatchOnMain(GlobalAction.ShowDialog(WalletConnectDialog.SessionTimeout)) } is WalletConnectAction.FailureEstablishingSession -> { + if (action.error != null) { + store.dispatch( + GlobalAction.ShowDialog( + AppDialog.SimpleOkDialogRes( + headerId = R.string.common_warning, + messageId = action.error.messageResource, + ), + ), + ) + } if (action.session != null) { walletConnectManager.disconnect(action.session) } @@ -273,21 +284,21 @@ class WalletConnectMiddleware { ) return } - val wallet = walletManager.wallet - val derivedKey = - if (wallet.publicKey.blockchainKey.contentEquals(wallet.publicKey.seedKey)) { - null - } else { - walletManager.wallet.publicKey.blockchainKey - } - val walletForSession = WalletForSession( - cardId = scanResponse.card.cardId, - walletPublicKey = wallet.publicKey.seedKey, - derivedPublicKey = derivedKey, - derivationPath = wallet.publicKey.derivationPath, - derivationStyle = scanResponse.card.derivationStyle, - blockchain = wallet.blockchain, - ) + val wallet = walletManager.wallet + val derivedKey = + if (wallet.publicKey.blockchainKey.contentEquals(wallet.publicKey.seedKey)) { + null + } else { + walletManager.wallet.publicKey.blockchainKey + } + val walletForSession = WalletForSession( + cardId = scanResponse.card.cardId, + walletPublicKey = wallet.publicKey.seedKey, + derivedPublicKey = derivedKey, + derivationPath = wallet.publicKey.derivationPath, + derivationStyle = scanResponse.card.derivationStyle, + blockchain = wallet.blockchain, + ) withMainContext { val updatedSession = session.copy(wallet = walletForSession) diff --git a/app/src/main/res/values-de/strings_final.xml b/app/src/main/res/values-de/strings_final.xml index a2c94fc2da..042969a1b3 100644 --- a/app/src/main/res/values-de/strings_final.xml +++ b/app/src/main/res/values-de/strings_final.xml @@ -99,4 +99,6 @@ Tag Invalid Memo. It won\'t be added to the transaction Invalid Tag. It won\'t be added to the transaction + + Connection with this Dapp cannot be established due to its technical implementation. \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings_final.xml b/app/src/main/res/values-fr/strings_final.xml index 01b15baa13..44cf70e8a4 100644 --- a/app/src/main/res/values-fr/strings_final.xml +++ b/app/src/main/res/values-fr/strings_final.xml @@ -99,4 +99,6 @@ Tag Invalid Memo. It won\'t be added to the transaction Invalid Tag. It won\'t be added to the transaction + + Connection with this Dapp cannot be established due to its technical implementation. \ No newline at end of file diff --git a/app/src/main/res/values-it/strings_final.xml b/app/src/main/res/values-it/strings_final.xml index f6b98a333f..8052503722 100644 --- a/app/src/main/res/values-it/strings_final.xml +++ b/app/src/main/res/values-it/strings_final.xml @@ -100,4 +100,6 @@ Tag Invalid Memo. It won\'t be added to the transaction Invalid Tag. It won\'t be added to the transaction + + Connection with this Dapp cannot be established due to its technical implementation. \ No newline at end of file diff --git a/app/src/main/res/values-ru/strings_final.xml b/app/src/main/res/values-ru/strings_final.xml index 3ccd9d13aa..22f9894ae8 100644 --- a/app/src/main/res/values-ru/strings_final.xml +++ b/app/src/main/res/values-ru/strings_final.xml @@ -116,4 +116,6 @@ Tag Недопустимый Memo. Он не будет добавлен в транзакцию. Недопустимый Tag. Он не будет добавлен в транзакцию. + + Cоединение с этим Dapp сервисом не может быть установлено из-за его технической реализации. diff --git a/app/src/main/res/values/strings_final.xml b/app/src/main/res/values/strings_final.xml index 0e11c29566..bd35c99d4e 100644 --- a/app/src/main/res/values/strings_final.xml +++ b/app/src/main/res/values/strings_final.xml @@ -118,4 +118,6 @@ Tag Invalid Memo. It won\'t be added to the transaction Invalid Tag. It won\'t be added to the transaction + + Connection with this Dapp cannot be established due to its technical implementation.