From 136b6e7eb31464b61239da680bea2f152c3b0271 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 23 Mar 2021 20:24:55 +0300 Subject: [PATCH] Updated on 2026-08-14 --- app/build.gradle | 2 +- .../com/tangem/tap/common/redux/AppReducer.kt | 2 +- .../com/tangem/tap/domain/TapWalletManager.kt | 17 ++++++------- .../com/tangem/tap/domain/TapWorkarounds.kt | 12 ++++++++-- .../tangem/tap/domain/tasks/ScanNoteTask.kt | 17 +------------ .../tap/features/wallet/redux/WalletAction.kt | 1 + .../middlewares/MultiWalletMiddleware.kt | 24 +++++++++++++++++-- .../redux/middlewares/WarningsMiddleware.kt | 4 ++-- .../redux/reducers/MultiWalletReducer.kt | 1 + .../redux/{ => reducers}/WalletReducer.kt | 6 ++--- .../wallet/ui/WalletDetailsFragment.kt | 1 - 11 files changed, 50 insertions(+), 37 deletions(-) rename app/src/main/java/com/tangem/tap/features/wallet/redux/{ => reducers}/WalletReducer.kt (98%) diff --git a/app/build.gradle b/app/build.gradle index 73344a3d04..5d5b80fc3f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -77,7 +77,7 @@ dependencies { // implementation 'com.tangem:blockchain:1.141.0' - implementation 'blockchain-sdk-kotlin:blockchain:tangem-20210302.084810-3' + implementation 'blockchain-sdk-kotlin:blockchain:tangem-20210322.144347-8' implementation 'com.tangem:core:1.101.0' implementation 'com.tangem:sdk:1.101.0' diff --git a/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt b/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt index c60bdaa8f1..03dcb4a441 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt @@ -7,7 +7,7 @@ import com.tangem.tap.features.disclaimer.redux.DisclaimerReducer import com.tangem.tap.features.home.redux.HomeReducer import com.tangem.tap.features.send.redux.reducers.SendScreenReducer import com.tangem.tap.features.tokens.redux.TokensReducer -import com.tangem.tap.features.wallet.redux.WalletReducer +import com.tangem.tap.features.wallet.redux.reducers.WalletReducer import org.rekotlin.Action fun appReducer(action: Action, state: AppState?): AppState { diff --git a/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt b/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt index 3456649d7f..0d6662d4f0 100644 --- a/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt @@ -13,7 +13,6 @@ import com.tangem.tap.domain.configurable.config.ConfigManager import com.tangem.tap.domain.extensions.amountToCreateAccount import com.tangem.tap.domain.extensions.isNoAccountError import com.tangem.tap.domain.tasks.ScanNoteResponse -import com.tangem.tap.domain.tasks.isMultiwalletAllowed import com.tangem.tap.domain.twins.TwinsHelper import com.tangem.tap.domain.twins.isTwinCard import com.tangem.tap.features.tokens.redux.TokensAction @@ -151,20 +150,17 @@ class TapWalletManager { val primaryWalletManager = data.walletManager val primaryBlockchain = listOf(data.walletManager.wallet.blockchain) + val primaryTokenSymbol = data.card.cardData?.tokenSymbol val primaryToken = primaryWalletManager.presetTokens.toList() + .firstOrNull { it.symbol == primaryTokenSymbol } store.dispatch(WalletAction.MultiWallet.SetPrimaryBlockchain(primaryBlockchain[0])) - if (primaryWalletManager.presetTokens.isNotEmpty()) { - store.dispatch(WalletAction.MultiWallet.SetPrimaryToken(primaryToken.first())) + if (primaryToken != null) { + store.dispatch(WalletAction.MultiWallet.SetPrimaryToken(primaryToken)) } if (data.card.isMultiwalletAllowed) { val savedCurrencies = currenciesRepository.loadCardCurrencies(data.card.cardId) - val tokens = if (savedCurrencies.tokens.isNotEmpty()) { - primaryToken + savedCurrencies.tokens - } else { - primaryToken - } val walletManagers = listOf(primaryWalletManager) + currenciesRepository.getBlockchains() @@ -172,9 +168,14 @@ class TapWalletManager { .mapNotNull { walletManagerFactory.makeWalletManager(data.card, it) } val otherBlockhains = savedCurrencies.blockchains + val activeTokens = walletManagers.first { it.wallet.blockchain == Blockchain.Ethereum} + .presetTokens.toList() + val tokens = activeTokens + savedCurrencies.tokens + store.dispatch(WalletAction.MultiWallet.AddWalletManagers(walletManagers)) store.dispatch(WalletAction.MultiWallet.AddBlockchains(primaryBlockchain + otherBlockhains)) store.dispatch(WalletAction.MultiWallet.AddTokens(tokens)) + store.dispatch(WalletAction.MultiWallet.FindTokensInUse) } else { store.dispatch(WalletAction.MultiWallet.AddWalletManagers(listOf(primaryWalletManager))) store.dispatch(WalletAction.MultiWallet.AddBlockchains(primaryBlockchain)) diff --git a/app/src/main/java/com/tangem/tap/domain/TapWorkarounds.kt b/app/src/main/java/com/tangem/tap/domain/TapWorkarounds.kt index d0cc8b64b2..48526204e8 100644 --- a/app/src/main/java/com/tangem/tap/domain/TapWorkarounds.kt +++ b/app/src/main/java/com/tangem/tap/domain/TapWorkarounds.kt @@ -1,6 +1,7 @@ package com.tangem.tap.domain import com.tangem.commands.common.card.Card +import com.tangem.commands.common.card.EllipticCurve import com.tangem.commands.common.card.masks.Product import java.util.* @@ -17,7 +18,7 @@ object TapWorkarounds { val cardData = this.cardData ?: return false val productMask = cardData.productMask val excludedBatch = excludedBatches.contains(cardData.batchId) - val excludedIssuerName = excludedIssuers.contains(cardData.issuerName?.capitalize(Locale.US)) + val excludedIssuerName = excludedIssuers.contains(cardData.issuerName?.toUpperCase(Locale.US)) val excludedProductMask = (productMask != null && // product mask is on cards v2.30 and later !productMask.contains(Product.Note) && !productMask.contains(Product.TwinCard)) return excludedBatch || excludedIssuerName || excludedProductMask @@ -35,4 +36,11 @@ object TapWorkarounds { private val excludedIssuers = listOf( "TTM BANK" ) -} \ No newline at end of file +} + +val Card.isMultiwalletAllowed: Boolean + get() { + return cardData?.productMask?.contains(Product.TwinCard) != true + && !TapWorkarounds.isStart2Coin + && this.curve == EllipticCurve.Secp256k1 + } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt b/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt index 5fd45114d2..e2ae2aef19 100644 --- a/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt +++ b/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt @@ -11,14 +11,11 @@ import com.tangem.commands.CommandResponse import com.tangem.commands.ReadIssuerDataCommand import com.tangem.commands.common.card.Card import com.tangem.commands.common.card.CardStatus -import com.tangem.commands.common.card.EllipticCurve -import com.tangem.commands.common.card.masks.Product import com.tangem.commands.verifycard.VerifyCardCommand import com.tangem.commands.verifycard.VerifyCardResponse import com.tangem.common.CompletionResult import com.tangem.common.extensions.toHexString import com.tangem.tap.domain.TapSdkError -import com.tangem.tap.domain.TapWorkarounds import com.tangem.tap.domain.TapWorkarounds.isExcluded import com.tangem.tap.domain.twins.TwinCardsManager import com.tangem.tap.domain.twins.isTwinCard @@ -30,7 +27,6 @@ data class ScanNoteResponse( val card: Card, val verifyResponse: VerifyCardResponse? = null, val secondTwinPublicKey: String? = null, - val multiwalletCard: Boolean = false, ) : CommandResponse class ScanNoteTask(val card: Card? = null) : CardSessionRunnable { @@ -82,9 +78,7 @@ class ScanNoteTask(val card: Card? = null) : CardSessionRunnable { callback(CompletionResult.Success(ScanNoteResponse( - walletManager, card, verifyResult.data, publicKey, - batchesAllowingMultiwallet.contains(card.cardData?.batchId) - ))) + walletManager, card, verifyResult.data, publicKey))) } is CompletionResult.Failure -> { callback(CompletionResult.Failure(TangemSdkError.CardVerificationFailed())) @@ -132,12 +126,3 @@ class ScanNoteTask(val card: Card? = null) : CardSessionRunnable) : MultiWallet() data class AddTokens(val tokens: List) : MultiWallet() data class AddToken(val token: Token) : MultiWallet() + object FindTokensInUse : MultiWallet() data class TokenLoaded(val amount: Amount) : MultiWallet() data class SelectWallet(val walletData: WalletData?) : MultiWallet() data class RemoveWallet(val walletData: WalletData) : MultiWallet() diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/MultiWalletMiddleware.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/MultiWalletMiddleware.kt index bf1cceeed7..7625586f61 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/MultiWalletMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/MultiWalletMiddleware.kt @@ -49,6 +49,28 @@ class MultiWalletMiddleware { cardId?.let { currenciesRepository.removeBlockchain(it, action.walletData.blockchain) } } } + is WalletAction.MultiWallet.FindTokensInUse -> { + val walletManager = walletState?.getWalletManager(Blockchain.Ethereum.currency) + ?: return + val alreadyAddedTokens = walletManager.presetTokens + val tokenManager = walletManager as TokenManager + scope.launch { + val result = tokenManager.findTokens() + withContext(Dispatchers.Main) { + when (result) { + is Result.Success -> { + if (result.data.isNotEmpty()) { + store.dispatch(WalletAction.MultiWallet.AddTokens( + walletManager.presetTokens + .filterNot { presetToken -> alreadyAddedTokens.any { it.symbol == presetToken.symbol } } + .toList() + )) + } + } + } + } + } + } } } @@ -63,8 +85,6 @@ class MultiWalletMiddleware { store.dispatch(WalletAction.LoadFiatRate(currency = token.symbol)) store.dispatch(WalletAction.MultiWallet.TokenLoaded(result.data)) } - is Result.Failure -> null - null -> null } } } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WarningsMiddleware.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WarningsMiddleware.kt index 9be3da6c55..347dce4c7f 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WarningsMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WarningsMiddleware.kt @@ -13,7 +13,7 @@ import com.tangem.tap.common.extensions.isGreaterThan import com.tangem.tap.common.redux.global.GlobalState import com.tangem.tap.domain.configurable.warningMessage.WarningMessage import com.tangem.tap.domain.configurable.warningMessage.WarningMessagesManager -import com.tangem.tap.domain.tasks.isMultiwalletAllowed +import com.tangem.tap.domain.isMultiwalletAllowed import com.tangem.tap.domain.twins.isTwinCard import com.tangem.tap.features.wallet.redux.WalletAction import com.tangem.tap.network.NetworkConnectivity @@ -55,7 +55,7 @@ class WarningsMiddleware { } } - public fun tryToShowAppRatingWarning(wallet: Wallet) { + fun tryToShowAppRatingWarning(wallet: Wallet) { val nonZeroWalletsCount = wallet.amounts.filter { it.value.value?.isGreaterThan(BigDecimal.ZERO) ?: false }.size diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt index b88adcb40d..0ce62a948d 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt @@ -155,6 +155,7 @@ class MultiWalletReducer { is WalletAction.MultiWallet.SetPrimaryToken -> state.copy(primaryToken = action.token) + is WalletAction.MultiWallet.FindTokensInUse -> state } } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt similarity index 98% rename from app/src/main/java/com/tangem/tap/features/wallet/redux/WalletReducer.kt rename to app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt index 2ced6e5201..f70ba93b11 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt @@ -1,4 +1,4 @@ -package com.tangem.tap.features.wallet.redux +package com.tangem.tap.features.wallet.redux.reducers import com.tangem.blockchain.common.AmountType import com.tangem.blockchain.common.Blockchain @@ -14,9 +14,7 @@ import com.tangem.tap.common.redux.global.FiatCurrencyName import com.tangem.tap.domain.TapError import com.tangem.tap.domain.getFirstToken import com.tangem.tap.domain.twins.TwinCardNumber -import com.tangem.tap.features.wallet.redux.reducers.MultiWalletReducer -import com.tangem.tap.features.wallet.redux.reducers.OnWalletLoadedReducer -import com.tangem.tap.features.wallet.redux.reducers.TwinsReducer +import com.tangem.tap.features.wallet.redux.* import com.tangem.tap.features.wallet.ui.BalanceStatus import com.tangem.tap.features.wallet.ui.BalanceWidgetData import org.rekotlin.Action diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt index 8b98eba79d..0cfff7bb46 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt @@ -58,7 +58,6 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), StoreS oldState.walletState == newState.walletState }.select { it.walletState } } - store.dispatch(WalletAction.UpdateWallet()) } override fun onStop() {