Updated on 2026-08-14

This commit is contained in:
Tangem 2022-09-30 11:36:41 +04:00
commit c9c486876b
13 changed files with 83 additions and 33 deletions

View file

@ -57,7 +57,10 @@ class WalletConnectManager {
private var sessions: MutableMap<WCSession, WalletConnectActiveData> = mutableMapOf()
fun connect(wcUri: String) {
val session = WCSession.from(wcUri) ?: return
val session = WCSession.from(wcUri).guard {
store.dispatchOnMain(WalletConnectAction.FailureEstablishingSession(null, true))
return
}
if (sessions[session] != null) {
store.dispatchOnMain(WalletConnectAction.RefuseOpeningSession)
return
@ -65,7 +68,14 @@ class WalletConnectManager {
val client = WCClient(httpClient = okHttpClient)
setListeners(client)
val peerId = UUID.randomUUID().toString()
client.connect(session, tangemPeerMeta, peerId)
try {
client.connect(session, tangemPeerMeta, peerId)
} catch (exception: IllegalArgumentException) {
store.dispatchOnMain(WalletConnectAction.FailureEstablishingSession(null, true))
return
}
sessions[session] = WalletConnectActiveData(
peerId = peerId,
remotePeerId = null,

View file

@ -52,7 +52,11 @@ sealed class WalletConnectAction : Action {
val updatedSession: WalletConnectSession,
) : WalletConnectAction()
data class FailureEstablishingSession(val session: WCSession?) : WalletConnectAction()
data class FailureEstablishingSession(
val session: WCSession?,
val showWarning: Boolean = false,
) : WalletConnectAction()
data class SetSessionsRestored(val sessions: List<WalletConnectSession>) :
WalletConnectAction()
@ -103,6 +107,6 @@ sealed class WalletConnectAction : Action {
data class Sign(
val id: Long, val data: ByteArray, val sessionData: WCSession,
) : WalletConnectAction()
) : WalletConnectAction()
}
}

View file

@ -9,6 +9,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
@ -22,6 +23,7 @@ import com.tangem.tap.features.demo.DemoHelper
import com.tangem.tap.features.wallet.redux.WalletState
import com.tangem.tap.scope
import com.tangem.tap.store
import com.tangem.wallet.R
import kotlinx.coroutines.launch
import org.rekotlin.Action
import org.rekotlin.Middleware
@ -99,6 +101,16 @@ class WalletConnectMiddleware {
if (action.session != null) {
walletConnectManager.disconnect(action.session)
}
if (action.showWarning) {
store.dispatchOnMain(
GlobalAction.ShowDialog(
AppDialog.SimpleOkDialogRes(
headerId = R.string.common_warning,
messageId = R.string.wallet_connect_error_failed_to_connect,
),
),
)
}
}
is WalletConnectAction.UnsupportedCard -> {
store.dispatchOnMain(GlobalAction.ShowDialog(WalletConnectDialog.UnsupportedCard))

View file

@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@ -86,7 +87,7 @@ fun WalletConnectDetailsItem(
) {
Row(
modifier = modifier
.height(84.dp)
.defaultMinSize(minHeight = 84.dp)
.fillMaxWidth()
.clickable { onItemsClick(SettingsElement.WalletConnect) },
horizontalArrangement = Arrangement.Start,
@ -99,7 +100,7 @@ fun WalletConnectDetailsItem(
tint = colorResource(id = R.color.all_colors_azure),
)
Column(
modifier = modifier.height(56.dp),
modifier = modifier.defaultMinSize(minHeight = 56.dp),
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.Center,
) {

View file

@ -1,6 +1,8 @@
package com.tangem.tap.features.details.ui.resetcard
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@ -89,11 +91,14 @@ fun ResetCardView(
color = colorResource(id = R.color.text_secondary),
)
Spacer(modifier = modifier.size(44.dp))
Spacer(modifier = modifier.size(28.dp))
Row(
modifier = modifier
.fillMaxWidth()
.padding(end = 20.dp),
.clickable(
onClick = { state.onAcceptWarningToggleClick(!state.accepted) },
)
.padding(top = 16.dp, bottom = 16.dp),
) {
IconToggleButton(
checked = state.accepted,
@ -120,13 +125,15 @@ fun ResetCardView(
text = stringResource(id = R.string.reset_card_to_factory_warning_message),
style = TangemTypography.body2,
color = colorResource(id = R.color.text_secondary),
modifier = modifier
.padding(end = 20.dp),
)
}
Spacer(modifier = modifier.size(32.dp))
Spacer(modifier = modifier.size(16.dp))
Box(
modifier = modifier
.padding(start = 16.dp, end = 16.dp),
.padding(start = 16.dp, end = 16.dp, bottom = 32.dp),
) {
DetailsMainButton(
title = stringResource(id = R.string.reset_card_to_factory_button_title),

View file

@ -140,13 +140,12 @@ private fun WalletConnectSessions(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Column(modifier = modifier) {
Text(
text = session.description,
style = TangemTypography.subtitle1,
color = colorResource(id = R.color.text_primary_1),
)
}
Text(
text = session.description,
style = TangemTypography.subtitle1,
color = colorResource(id = R.color.text_primary_1),
modifier = modifier.weight(1f),
)
IconButton(
onClick = { state.onRemoveSession(session.sessionId) },
) {

View file

@ -193,21 +193,28 @@ data class WalletState(
fun removeWallet(walletData: WalletData?): WalletState {
if (walletData == null) return this
return if (walletData.currency is Currency.Blockchain) {
val walletStores = wallets.filterNot {
it.blockchainNetwork.blockchain == walletData.currency.blockchain
&& it.blockchainNetwork.derivationPath == walletData.currency.derivationPath
return when (val currency = walletData.currency) {
is Currency.Blockchain -> {
val walletStores = wallets.filterNot {
it.blockchainNetwork.blockchain == currency.blockchain
&& it.blockchainNetwork.derivationPath == currency.derivationPath
}
copy(wallets = walletStores)
.updateTotalBalance()
.updateProgressState()
}
is Currency.Token -> {
val walletStore = getWalletStore(walletData.currency)
val walletDataList = walletStore?.walletsData
?.filterNot { it.currency == walletData.currency }
?: emptyList()
val updatedWalletManager = walletStore?.walletManager?.also { it.removeToken(currency.token) }
val updatedWalletStore = walletStore?.copy(
walletsData = walletDataList,
walletManager = updatedWalletManager,
)
updateWalletStore(updatedWalletStore)
}
copy(wallets = walletStores)
.updateTotalBalance()
.updateProgressState()
} else {
val walletStore = getWalletStore(walletData.currency)
val walletDataList = walletStore?.walletsData
?.filterNot { it.currency == walletData.currency }
?: emptyList()
val updatedWalletStore = walletStore?.copy(walletsData = walletDataList)
updateWalletStore(updatedWalletStore)
}
}

View file

@ -110,8 +110,12 @@ class WalletAdapter
lContent.tvExchangeRate.text = wallet.fiatRateString
?: root.getString(id = R.string.token_item_no_rate)
cardWallet.setOnClickListener {
store.dispatch(WalletAction.MultiWallet.SelectWallet(wallet))
if (wallet.walletAddresses != null) {
cardWallet.setOnClickListener {
store.dispatch(WalletAction.MultiWallet.SelectWallet(wallet))
}
} else {
cardWallet.setOnClickListener(null)
}
}
}

View file

@ -88,6 +88,7 @@
<string name="wallet_connect_select_network">Select network</string>
<string name="main_scan_card_warning_view_title">Scan your card</string>
<string name="main_scan_card_warning_view_subtitle">To access all the networks you need to scan the card</string>
<string name="wallet_connect_error_failed_to_connect">Failed to establish WalletConnect session</string>
<string name="send_extras_hint_memo">Memo</string>
<string name="send_extras_hint_destination_tag">Tag</string>
<string name="send_extras_error_invalid_memo">Invalid Memo. It won\'t be added to the transaction.</string>

View file

@ -88,6 +88,7 @@
<string name="wallet_connect_select_network">Select network</string>
<string name="main_scan_card_warning_view_title">Scan your card</string>
<string name="main_scan_card_warning_view_subtitle">To access all the networks you need to scan the card</string>
<string name="wallet_connect_error_failed_to_connect">Failed to establish WalletConnect session</string>
<string name="send_extras_hint_memo">Memo</string>
<string name="send_extras_hint_destination_tag">Tag</string>
<string name="send_extras_error_invalid_memo">Invalid Memo. It won\'t be added to the transaction.</string>

View file

@ -88,6 +88,7 @@
<string name="wallet_connect_select_network">Select network</string>
<string name="main_scan_card_warning_view_title">Scan your card</string>
<string name="main_scan_card_warning_view_subtitle">To access all the networks you need to scan the card</string>
<string name="wallet_connect_error_failed_to_connect">Failed to establish WalletConnect session</string>
<string name="send_extras_hint_memo">Memo</string>
<string name="send_extras_hint_destination_tag">Tag</string>
<string name="send_extras_error_invalid_memo">Invalid Memo. It won\'t be added to the transaction.</string>

View file

@ -103,4 +103,6 @@
<string name="send_extras_hint_destination_tag">Tag</string>
<string name="send_extras_error_invalid_memo">Недопустимый Memo. Он не будет добавлен в транзакцию.</string>
<string name="send_extras_error_invalid_destination_tag">Недопустимый Tag. Он не будет добавлен в транзакцию.</string>
<string name="warning_existential_deposit_message">Сеть %s использует концепцию экзистенциального депозита. Если баланс вашего счета опустится ниже %s %s, он будет деактивирован, а все оставшиеся средства будут уничтожены.</string>
<string name="wallet_connect_error_failed_to_connect">Не удалось установить сессию WalletConnect</string>
</resources>

View file

@ -101,6 +101,7 @@
<string name="wallet_connect_select_network">Select network</string>
<string name="main_scan_card_warning_view_title">Scan your card</string>
<string name="main_scan_card_warning_view_subtitle">To access all the networks you need to scan the card</string>
<string name="wallet_connect_error_failed_to_connect">Failed to establish WalletConnect session</string>
<string name="send_extras_hint_memo">Memo</string>
<string name="send_extras_hint_destination_tag">Tag</string>
<string name="send_extras_error_invalid_memo">Invalid Memo. It won\'t be added to the transaction.</string>