From 7925f2d66c3e82a6160328e72e2037b9883b9a37 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 27 May 2025 23:14:13 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../connections/entity/WcConnectionsState.kt | 2 +- .../model/WcConnectedAppInfoModel.kt | 1 - .../transformers/WcSessionsTransformer.kt | 3 ++- .../ui/preview/WcConnectionsPreviewData.kt | 16 +++++++----- .../transaction/model/WcAddNetworkModel.kt | 7 +++++ .../model/WcSignTransactionModel.kt | 26 ++----------------- .../send/WcSendTransactionModalBottomSheet.kt | 5 ++-- .../transaction/utils/WcTransactionUtils.kt | 13 +++++----- 8 files changed, 32 insertions(+), 41 deletions(-) diff --git a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/entity/WcConnectionsState.kt b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/entity/WcConnectionsState.kt index 0eb7c4e19b..89f1496048 100644 --- a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/entity/WcConnectionsState.kt +++ b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/entity/WcConnectionsState.kt @@ -26,7 +26,7 @@ internal data class WcConnectionsUM( internal data class WcConnectedAppInfo( val name: String, val iconUrl: String, + val verifiedState: VerifiedDAppState, val subtitle: TextReference = stringReference("Connected App"), - val isVerified: Boolean = false, val onClick: () -> Unit, ) \ No newline at end of file diff --git a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/model/WcConnectedAppInfoModel.kt b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/model/WcConnectedAppInfoModel.kt index 3d6a535f18..f415b0b68e 100644 --- a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/model/WcConnectedAppInfoModel.kt +++ b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/model/WcConnectedAppInfoModel.kt @@ -82,7 +82,6 @@ internal class WcConnectedAppInfoModel @Inject constructor( } private fun extractVerifiedState(session: WcSession): VerifiedDAppState { - return VerifiedDAppState.Verified(onVerifiedClick = {}) return if (session.securityStatus == CheckDAppResult.SAFE) { VerifiedDAppState.Verified(onVerifiedClick = {}) } else { diff --git a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/model/transformers/WcSessionsTransformer.kt b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/model/transformers/WcSessionsTransformer.kt index 1f3b8a9ebc..b71e892c4e 100644 --- a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/model/transformers/WcSessionsTransformer.kt +++ b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/model/transformers/WcSessionsTransformer.kt @@ -26,7 +26,8 @@ internal class WcSessionsTransformer( name = appMetaData.name, iconUrl = appMetaData.icons.firstOrNull().orEmpty(), subtitle = stringReference(appMetaData.description), - isVerified = false, + verifiedState = WcDAppVerifiedStateConverter {} + .convert(session.securityStatus to appMetaData.name), onClick = { openAppInfoModal(session) }, ) } diff --git a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/ui/preview/WcConnectionsPreviewData.kt b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/ui/preview/WcConnectionsPreviewData.kt index 31759bb4d4..279c79a78c 100644 --- a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/ui/preview/WcConnectionsPreviewData.kt +++ b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/connections/ui/preview/WcConnectionsPreviewData.kt @@ -4,6 +4,7 @@ import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM import com.tangem.core.ui.components.dropdownmenu.TangemDropdownMenuItem import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.res.TangemTheme +import com.tangem.features.walletconnect.connections.entity.VerifiedDAppState import com.tangem.features.walletconnect.connections.entity.WcConnectedAppInfo import com.tangem.features.walletconnect.connections.entity.WcConnectionsState import com.tangem.features.walletconnect.connections.entity.WcConnectionsTopAppBarConfig @@ -22,13 +23,14 @@ internal object WcConnectionsPreviewData { WcConnectedAppInfo( name = "Moralis", iconUrl = "$BASE_URL/satoshi.png", - isVerified = true, + verifiedState = VerifiedDAppState.Verified {}, onClick = { Timber.d("Moralis clicked") }, ), WcConnectedAppInfo( name = "website.com", iconUrl = "$BASE_URL/doge_again_lol.jpg", onClick = { Timber.d("website.com clicked") }, + verifiedState = VerifiedDAppState.Unknown, ), ), ), @@ -39,7 +41,7 @@ internal object WcConnectionsPreviewData { WcConnectedAppInfo( name = "React app", iconUrl = "$BASE_URL/LiteCoin.png", - isVerified = true, + verifiedState = VerifiedDAppState.Verified {}, onClick = { Timber.d("React app clicked") }, ), ), @@ -51,12 +53,13 @@ internal object WcConnectionsPreviewData { WcConnectedAppInfo( name = "Moralis", iconUrl = "$BASE_URL/satoshi.png", - isVerified = true, + verifiedState = VerifiedDAppState.Verified {}, onClick = { Timber.d("Moralis clicked") }, ), WcConnectedAppInfo( name = "website.com", iconUrl = "$BASE_URL/doge_again_lol.jpg", + verifiedState = VerifiedDAppState.Unknown, onClick = { Timber.d("website.com clicked") }, ), ), @@ -68,8 +71,8 @@ internal object WcConnectionsPreviewData { WcConnectedAppInfo( name = "React app", iconUrl = "$BASE_URL/LiteCoin.png", - isVerified = true, onClick = { Timber.d("React app clicked") }, + verifiedState = VerifiedDAppState.Verified {}, ), ), ), @@ -80,13 +83,14 @@ internal object WcConnectionsPreviewData { WcConnectedAppInfo( name = "Moralis", iconUrl = "$BASE_URL/satoshi.png", - isVerified = true, + verifiedState = VerifiedDAppState.Verified {}, onClick = { Timber.d("Moralis clicked") }, ), WcConnectedAppInfo( name = "website.com", iconUrl = "$BASE_URL/doge_again_lol.jpg", onClick = { Timber.d("website.com clicked") }, + verifiedState = VerifiedDAppState.Unknown, ), ), ), @@ -97,7 +101,7 @@ internal object WcConnectionsPreviewData { WcConnectedAppInfo( name = "React app", iconUrl = "$BASE_URL/LiteCoin.png", - isVerified = true, + verifiedState = VerifiedDAppState.Verified {}, onClick = { Timber.d("React app clicked") }, ), ), diff --git a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/model/WcAddNetworkModel.kt b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/model/WcAddNetworkModel.kt index 171a7f09a6..46d3faf1d4 100644 --- a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/model/WcAddNetworkModel.kt +++ b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/model/WcAddNetworkModel.kt @@ -40,6 +40,7 @@ internal class WcAddNetworkModel @Inject constructor( val useCase: WcMethodUseCase = useCaseFactory.createUseCase(params.rawRequest) val transactionUM = (useCase as? WcAddNetworkUseCase)?.toUM( actions = WcTransactionActionsUM( + onShowVerifiedAlert = ::showVerifiedAlert, onDismiss = { cancel(useCase) }, onSign = { sign(useCase) }, onCopy = { copyData(useCase.rawSdkRequest.request.params) }, @@ -53,6 +54,12 @@ internal class WcAddNetworkModel @Inject constructor( _uiState.value?.transaction?.onDismiss?.invoke() ?: router.pop() } + @Suppress("UnusedPrivateMember") + private fun showVerifiedAlert(appName: String) { + // TODO(wc): Nastya [REDACTED_JIRA] // see WcPairComponent and WcPairModel + // router.push(WcAppInfoRoutes.Alert(elements = message.elements)) + } + private fun sign(useCase: WcAddNetworkUseCase) { modelScope.launch { _uiState.update { it?.copy(transaction = it.transaction.copy(isLoading = true)) } diff --git a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/model/WcSignTransactionModel.kt b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/model/WcSignTransactionModel.kt index 8385ffb643..3c13437599 100644 --- a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/model/WcSignTransactionModel.kt +++ b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/model/WcSignTransactionModel.kt @@ -5,16 +5,7 @@ import com.tangem.core.decompose.di.ModelScoped import com.tangem.core.decompose.model.Model import com.tangem.core.decompose.model.ParamsContainer import com.tangem.core.decompose.navigation.Router -import com.tangem.core.ui.R import com.tangem.core.ui.clipboard.ClipboardManager -import com.tangem.core.ui.components.bottomsheets.message.MessageBottomSheetUMV2 -import com.tangem.core.ui.components.bottomsheets.message.icon -import com.tangem.core.ui.components.bottomsheets.message.infoBlock -import com.tangem.core.ui.components.bottomsheets.message.messageBottomSheetUM -import com.tangem.core.ui.components.bottomsheets.message.onClick -import com.tangem.core.ui.components.bottomsheets.message.secondaryButton -import com.tangem.core.ui.extensions.resourceReference -import com.tangem.core.ui.extensions.wrappedList import com.tangem.domain.walletconnect.WcRequestUseCaseFactory import com.tangem.domain.walletconnect.usecase.method.WcSignState import com.tangem.domain.walletconnect.usecase.method.WcSignStep @@ -71,22 +62,9 @@ internal class WcSignTransactionModel @Inject constructor( _uiState.value?.transaction?.onDismiss?.invoke() ?: router.pop() } + @Suppress("UnusedPrivateMember") private fun showVerifiedAlert(appName: String) { - val message = messageBottomSheetUM { - infoBlock { - icon(R.drawable.img_approvale2_20) { - type = MessageBottomSheetUMV2.Icon.Type.Accent - backgroundType = MessageBottomSheetUMV2.Icon.BackgroundType.Unspecified - } - title = resourceReference(R.string.wc_alert_verified_domain_title) - body = resourceReference(R.string.wc_alert_verified_domain_description, wrappedList(appName)) - } - secondaryButton { - text = resourceReference(R.string.common_done) - onClick { closeBs() } - } - } - // TODO(wc): Nastya [REDACTED_JIRA] + // TODO(wc): Nastya [REDACTED_JIRA] // see WcPairComponent and WcPairModel // router.push(WcAppInfoRoutes.Alert(elements = message.elements)) } diff --git a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/ui/send/WcSendTransactionModalBottomSheet.kt b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/ui/send/WcSendTransactionModalBottomSheet.kt index 9c22bc1ddb..a27a8a17a5 100644 --- a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/ui/send/WcSendTransactionModalBottomSheet.kt +++ b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/ui/send/WcSendTransactionModalBottomSheet.kt @@ -23,6 +23,7 @@ import com.tangem.core.ui.components.divider.DividerWithPadding import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.features.walletconnect.connections.entity.VerifiedDAppState import com.tangem.features.walletconnect.connections.ui.WcAppInfoItem import com.tangem.features.walletconnect.impl.R import com.tangem.features.walletconnect.transaction.entity.blockaid.WcEstimatedWalletChangeUM @@ -74,7 +75,7 @@ internal fun WcSendTransactionModalBottomSheet( iconUrl = state.appInfo.appIcon, title = state.appInfo.appName, subtitle = state.appInfo.appSubtitle, - isVerified = state.appInfo.isVerified, + verifiedDAppState = state.appInfo.verifiedState, ) DividerWithPadding(start = 0.dp, end = 0.dp) WcTransactionRequestItem( @@ -147,7 +148,7 @@ private class WcSendTransactionStateProvider : CollectionPreviewParameterProvide appInfo = WcTransactionAppInfoContentUM( appName = "React App", appIcon = "", - isVerified = true, + verifiedState = VerifiedDAppState.Verified {}, appSubtitle = "react-app.walletconnect.com", ), estimatedWalletChanges = WcEstimatedWalletChangesUM( diff --git a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/utils/WcTransactionUtils.kt b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/utils/WcTransactionUtils.kt index e031ea0a21..21933394fd 100644 --- a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/utils/WcTransactionUtils.kt +++ b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/utils/WcTransactionUtils.kt @@ -1,12 +1,13 @@ package com.tangem.features.walletconnect.transaction.utils -import com.domain.blockaid.models.dapp.CheckDAppResult import com.tangem.core.ui.extensions.getActiveIconRes import com.tangem.core.ui.extensions.resourceReference import com.tangem.domain.walletconnect.model.WcEthMethod import com.tangem.domain.walletconnect.model.WcSolanaMethod import com.tangem.domain.walletconnect.model.sdkcopy.WcSdkSessionRequest +import com.tangem.domain.walletconnect.usecase.method.WcAddNetworkUseCase import com.tangem.domain.walletconnect.usecase.method.WcMessageSignUseCase +import com.tangem.domain.walletconnect.usecase.method.WcMethodContext import com.tangem.domain.walletconnect.usecase.method.WcSignState import com.tangem.domain.walletconnect.usecase.method.WcSignStep import com.tangem.domain.walletconnect.usecase.method.WcSignUseCase @@ -25,7 +26,7 @@ internal fun WcAddNetworkUseCase.toUM(actions: WcTransactionActionsUM): WcAddEth transaction = WcAddEthereumChainItemUM( onDismiss = actions.onDismiss, onSign = actions.onSign, - appInfo = appInfo(), + appInfo = appInfo(onShowVerifiedAlert = actions.onShowVerifiedAlert), walletName = session.wallet.name, isLoading = false, ), @@ -65,7 +66,7 @@ private fun WcMessageSignUseCase.signTypedDataToUM( transaction = WcSignTransactionItemUM( onDismiss = actions.onDismiss, onSign = actions.onSign, - appInfo = appInfo(), + appInfo = appInfo(onShowVerifiedAlert = actions.onShowVerifiedAlert), walletName = session.wallet.name, networkInfo = networkInfo(), addressText = walletAddress.toShortAddressText(), @@ -106,7 +107,7 @@ private fun WcMessageSignUseCase.messageSignToUM( transaction = WcSignTransactionItemUM( onDismiss = actions.onDismiss, onSign = actions.onSign, - appInfo = appInfo(), + appInfo = appInfo(onShowVerifiedAlert = actions.onShowVerifiedAlert), walletName = session.wallet.name, networkInfo = networkInfo(), isLoading = signState.domainStep == WcSignStep.Signing, @@ -150,10 +151,10 @@ private fun WcMethodContext.basicTransactionRequestInfoBlocks() = persistentList ), ) -private fun WcMethodContext.appInfo() = WcTransactionAppInfoContentUM( +private fun WcMethodContext.appInfo(onShowVerifiedAlert: (String) -> Unit) = WcTransactionAppInfoContentUM( appName = session.sdkModel.appMetaData.name, appIcon = session.sdkModel.appMetaData.url, - verifiedState = WcDAppVerifiedStateConverter(onVerifiedClick = actions.onShowVerifiedAlert).convert( + verifiedState = WcDAppVerifiedStateConverter(onVerifiedClick = onShowVerifiedAlert).convert( session.securityStatus to session.sdkModel.appMetaData.name, ), appSubtitle = session.sdkModel.appMetaData.description,