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 24c1384e66..70a1526ce3 100644 --- a/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt @@ -11,6 +11,7 @@ import com.tangem.common.doOnFailure import com.tangem.common.doOnSuccess import com.tangem.common.services.Result import com.tangem.core.analytics.Analytics +import com.tangem.datasource.config.ConfigManager import com.tangem.domain.common.CardDTO import com.tangem.domain.common.ScanResponse import com.tangem.domain.common.TapWorkarounds.isTestCard @@ -21,7 +22,6 @@ import com.tangem.tap.common.extensions.dispatchOnMain import com.tangem.tap.common.extensions.safeUpdate import com.tangem.tap.common.extensions.setContext import com.tangem.tap.common.redux.global.GlobalAction -import com.tangem.datasource.config.ConfigManager import com.tangem.tap.domain.extensions.makePrimaryWalletManager import com.tangem.tap.domain.extensions.makeWalletManagersForApp import com.tangem.tap.domain.model.UserWallet @@ -29,6 +29,8 @@ import com.tangem.tap.domain.tokens.models.BlockchainNetwork import com.tangem.tap.domain.walletStores.WalletStoresError import com.tangem.tap.features.demo.isDemoCard import com.tangem.tap.features.details.redux.walletconnect.WalletConnectAction +import com.tangem.tap.features.disclaimer.createDisclaimer +import com.tangem.tap.features.disclaimer.redux.DisclaimerAction import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsAction import com.tangem.tap.features.wallet.models.toBlockchainNetworks import com.tangem.tap.features.wallet.redux.WalletAction @@ -110,8 +112,8 @@ class TapWalletManager { tangemSdkManager.changeDisplayedCardIdNumbersCount(scanResponse) store.state.globalState.feedbackManager?.infoHolder?.setCardInfo(scanResponse) updateConfigManager(scanResponse) - withMainContext { + store.dispatch(DisclaimerAction.SetDisclaimer(card.createDisclaimer())) store.dispatch(WalletAction.UserWalletChanged(userWallet)) store.dispatch(TwinCardsAction.IfTwinsPrepareState(scanResponse)) store.dispatch(WalletConnectAction.ResetState) diff --git a/app/src/main/java/com/tangem/tap/domain/scanCard/ScanCardProcessor.kt b/app/src/main/java/com/tangem/tap/domain/scanCard/ScanCardProcessor.kt index 56e9beaf22..facfc3d62e 100644 --- a/app/src/main/java/com/tangem/tap/domain/scanCard/ScanCardProcessor.kt +++ b/app/src/main/java/com/tangem/tap/domain/scanCard/ScanCardProcessor.kt @@ -20,7 +20,6 @@ import com.tangem.tap.common.extensions.setContext import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.common.redux.navigation.AppScreen import com.tangem.tap.common.redux.navigation.NavigationAction -import com.tangem.tap.features.disclaimer.DisclaimerType import com.tangem.tap.features.disclaimer.createDisclaimer import com.tangem.tap.features.disclaimer.redux.DisclaimerAction import com.tangem.tap.features.disclaimer.redux.DisclaimerCallback @@ -150,7 +149,7 @@ object ScanCardProcessor { crossinline nextHandler: suspend (ScanResponse) -> Unit, crossinline onFailure: suspend (error: TangemError) -> Unit, ) { - val disclaimer = DisclaimerType.get(scanResponse.card).createDisclaimer(scanResponse.card) + val disclaimer = scanResponse.card.createDisclaimer() store.dispatchOnMain(DisclaimerAction.SetDisclaimer(disclaimer)) if (disclaimer.isAccepted()) { diff --git a/app/src/main/java/com/tangem/tap/domain/walletCurrencies/implementation/DefaultWalletCurrenciesManager.kt b/app/src/main/java/com/tangem/tap/domain/walletCurrencies/implementation/DefaultWalletCurrenciesManager.kt index b9292c096c..5fe6dd8e22 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletCurrencies/implementation/DefaultWalletCurrenciesManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletCurrencies/implementation/DefaultWalletCurrenciesManager.kt @@ -1,6 +1,5 @@ package com.tangem.tap.domain.walletCurrencies.implementation -import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.DerivationStyle import com.tangem.common.CompletionResult import com.tangem.common.flatMap @@ -69,7 +68,7 @@ internal class DefaultWalletCurrenciesManager( .flatMap { updateWalletStoresAmounts( userWallet = userWallet, - updatedBlockchains = currenciesToAdd.map { it.blockchain }.distinct(), + updatedCurrencies = currenciesToAddWithMissingBlockchains, ) } } @@ -220,11 +219,13 @@ internal class DefaultWalletCurrenciesManager( private suspend fun updateWalletStoresAmounts( userWallet: UserWallet, - updatedBlockchains: List, + updatedCurrencies: List, ): CompletionResult { + val updatedBlockchains = updatedCurrencies + .filterIsInstance() val updatedWalletStores = walletStoresRepository.get(userWallet.walletId) .firstOrNull() - ?.filter { it.blockchain in updatedBlockchains } + ?.filter { it.blockchainWalletData.currency in updatedBlockchains } ?: return CompletionResult.Success(Unit) return walletAmountsRepository.updateAmountsForWalletStores( diff --git a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt index 1080f7529f..dff146b175 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt @@ -142,8 +142,8 @@ internal class DefaultWalletAmountsRepository( Timber.e( error, """ - Unable to fetch fiat rates - |- Coins ids: $coinsIds + Unable to fetch fiat rates + |- Coins ids: $coinsIds """.trimIndent(), ) @@ -278,6 +278,7 @@ internal class DefaultWalletAmountsRepository( Unable to fetch amounts |- User wallet id: ${walletStore.userWalletId} |- Blockchain: ${walletStore.blockchain} + |- Derivation path: ${walletStore.derivationPath?.rawPath} """.trimIndent(), ) @@ -310,6 +311,7 @@ internal class DefaultWalletAmountsRepository( Fetched amounts |- User wallet id: ${walletStore.userWalletId} |- Blockchain: ${walletStore.blockchain} + |- Derivation path: ${walletStore.derivationPath?.rawPath} """.trimIndent(), ) @@ -337,6 +339,7 @@ internal class DefaultWalletAmountsRepository( Missed derivation |- User wallet id: ${walletStore.userWalletId} |- Blockchain: ${walletStore.blockchain} + |- Derivation path: ${walletStore.derivationPath?.rawPath} """.trimIndent(), ) @@ -360,6 +363,7 @@ internal class DefaultWalletAmountsRepository( Wallet manager is null |- User wallet id: ${walletStore.userWalletId} |- Blockchain: ${walletStore.blockchain} + |- Derivation path: ${walletStore.derivationPath?.rawPath} """.trimIndent(), ) @@ -405,6 +409,7 @@ internal class DefaultWalletAmountsRepository( Fetched wallet rent |- User wallet id: ${walletStore.userWalletId} |- Blockchain: ${walletStore.blockchain} + |- Derivation path: ${walletStore.derivationPath?.rawPath} |- Rent: $rent """.trimIndent(), ) diff --git a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletManagersRepository.kt b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletManagersRepository.kt index d9579349d6..6c1442d65d 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletManagersRepository.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletManagersRepository.kt @@ -51,6 +51,7 @@ internal class DefaultWalletManagersRepository( val foundWalletManager = findWalletManager( userWalletId = userWallet.walletId, blockchain = blockchainNetwork?.blockchain, + derivationPath = blockchainNetwork?.derivationPath, ) foundWalletManager?.updateTokens( @@ -85,7 +86,13 @@ internal class DefaultWalletManagersRepository( return when { blockchain == Blockchain.Unknown || blockchain == null -> { val error = WalletStoresError.UnknownBlockchain() - Timber.e(error) + Timber.e( + error, + """ + Unknown blockchain while creating wallet manager + |- User wallet ID: ${userWallet.walletId} + """.trimIndent(), + ) CompletionResult.Failure(error) } walletManager != null -> { @@ -97,7 +104,15 @@ internal class DefaultWalletManagersRepository( } else -> { val error = WalletStoresError.WalletManagerNotCreated(blockchain) - Timber.e(error) + Timber.e( + error, + """ + Unable to create wallet manager + |- User wallet ID: ${userWallet.walletId} + |- Blockchain: $blockchain + |- Derivation path: ${blockchainNetwork?.derivationPath} + """.trimIndent(), + ) CompletionResult.Failure(error) } } @@ -178,15 +193,19 @@ internal class DefaultWalletManagersRepository( private suspend fun findWalletManager( userWalletId: UserWalletId, blockchain: Blockchain?, + derivationPath: String?, ): WalletManager? { return walletManagersStorage.getAll() .firstOrNull() ?.get(userWalletId) ?.let { userWalletManagers -> - if (blockchain == null) { + if (blockchain == null || derivationPath == null) { userWalletManagers.firstOrNull() } else { - userWalletManagers.firstOrNull { it.wallet.blockchain == blockchain } + userWalletManagers.firstOrNull { + it.wallet.blockchain == blockchain && + it.wallet.publicKey.derivationPath?.rawPath == derivationPath + } } } } diff --git a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt index d052401b0c..efcd36e402 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt @@ -121,9 +121,10 @@ private inline fun List.replaceWalletStores( if (currentWalletStore != updatedWalletStore) { Timber.d( """ - Update wallet store in storage - |- User wallet ID: ${updatedWalletStore.userWalletId} - |- Blockchain: ${updatedWalletStore.blockchain} + Update wallet store in storage + |- User wallet ID: ${updatedWalletStore.userWalletId} + |- Blockchain: ${updatedWalletStore.blockchain} + |- Derivation path: ${updatedWalletStore.derivationPath?.rawPath} """.trimIndent(), ) diff --git a/app/src/main/java/com/tangem/tap/features/disclaimer/DisclaimerType.kt b/app/src/main/java/com/tangem/tap/features/disclaimer/DisclaimerType.kt index d6af0e0596..b88b4488ab 100644 --- a/app/src/main/java/com/tangem/tap/features/disclaimer/DisclaimerType.kt +++ b/app/src/main/java/com/tangem/tap/features/disclaimer/DisclaimerType.kt @@ -35,6 +35,8 @@ fun DisclaimerType.createDisclaimer(cardDTO: CardDTO): Disclaimer { } } +fun CardDTO.createDisclaimer(): Disclaimer = DisclaimerType.get(this).createDisclaimer(this) + private fun provideDisclaimerDataProvider(cardId: String): DisclaimerDataProvider { return object : DisclaimerDataProvider { override fun getLanguage(): String = Locale.getDefault().language diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletData.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletData.kt index b6ed172e1a..e5edb01fa4 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletData.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletData.kt @@ -77,36 +77,35 @@ data class WalletData( if (currencyData.status == BalanceStatus.SameCurrencyTransactionInProgress) { walletWarnings.add(WalletWarning.TransactionInProgress(currency.currencyName)) } - } - - private fun assembleBlockchainWarnings(walletWarnings: MutableList) { - if (!currency.isBlockchain()) return - - if (existentialDepositString != null) { - val warning = WalletWarning.ExistentialDeposit( - currencyName = currency.currencyName, - edStringValueWithSymbol = "$existentialDepositString ${currency.currencySymbol}", - ) - walletWarnings.add(warning) - } if (walletRent != null) { walletWarnings.add(WalletWarning.Rent(walletRent)) } } - private fun assembleTokenWarnings(walletWarnings: MutableList) { - with(currency) { - if (!isToken()) return + private fun assembleBlockchainWarnings(walletWarnings: MutableList) = with(currency) { + if (!isBlockchain()) return - if (blockchainAmountIsEmpty() && !tokenAmountIsEmpty()) { - walletWarnings.add( - WalletWarning.BalanceNotEnoughForFee( - currencyName = currencyName, - blockchainFullName = blockchain.fullName, - blockchainSymbol = blockchain.currency, - ), - ) - } + if (existentialDepositString != null) { + val warning = WalletWarning.ExistentialDeposit( + currencyName = currencyName, + edStringValueWithSymbol = "$existentialDepositString $currencySymbol", + ) + walletWarnings.add(warning) + } + + } + + private fun assembleTokenWarnings(walletWarnings: MutableList) = with(currency) { + if (!isToken()) return + + if (blockchainAmountIsEmpty() && !tokenAmountIsEmpty()) { + walletWarnings.add( + WalletWarning.BalanceNotEnoughForFee( + currencyName = currencyName, + blockchainFullName = blockchain.fullName, + blockchainSymbol = blockchain.currency, + ), + ) } } diff --git a/app/src/main/java/com/tangem/tap/proxy/UserWalletManagerImpl.kt b/app/src/main/java/com/tangem/tap/proxy/UserWalletManagerImpl.kt index 250bf73562..d8273b39ee 100644 --- a/app/src/main/java/com/tangem/tap/proxy/UserWalletManagerImpl.kt +++ b/app/src/main/java/com/tangem/tap/proxy/UserWalletManagerImpl.kt @@ -144,7 +144,9 @@ class UserWalletManagerImpl( val card = requireNotNull(appStateHolder.getActualCard()) { "card not found" } val blockchainNetwork = BlockchainNetwork(blockchain, card) val walletManager = appStateHolder.walletState?.getWalletManager(blockchainNetwork) - return walletManager?.wallet?.recentTransactions?.lastOrNull()?.hash?.let { HEX_PREFIX + it } + return walletManager?.wallet?.recentTransactions + ?.lastOrNull { it.hash?.isNotEmpty() == true } + ?.hash?.let { HEX_PREFIX + it } } override suspend fun getCurrentWalletTokensBalance( diff --git a/app/src/main/res/layout/item_currency_wallet_content.xml b/app/src/main/res/layout/item_currency_wallet_content.xml index aa767d069c..b27a1d1edb 100644 --- a/app/src/main/res/layout/item_currency_wallet_content.xml +++ b/app/src/main/res/layout/item_currency_wallet_content.xml @@ -1,17 +1,17 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="42dp"> + android:id="@+id/guideline_horizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + app:layout_constraintGuide_percent="0.5" /> + tools:text="Transaction in progress and it very long text with some strange status" + tools:visibility="visible" /> + tools:text="46 908 $" + tools:visibility="gone" /> + diff --git a/buildSrc/src/main/java/Versions.kt b/buildSrc/src/main/java/Versions.kt index 96bf06edbb..0667a708c7 100644 --- a/buildSrc/src/main/java/Versions.kt +++ b/buildSrc/src/main/java/Versions.kt @@ -65,7 +65,7 @@ object Versions { // const val tangemBlockchainSdk = "0.0.1" // Keep it! - used for local builds const val tangemCardSdk = "develop-191" - // const val tangemCardSgk = "0.0.1" // Keep it! - used for local builds + // const val tangemCardSdk = "0.0.1" // Keep it! - used for local builds // endregion Tangem // region Tools diff --git a/domain/src/main/java/com/tangem/domain/common/extensions/CardSdk.kt b/domain/src/main/java/com/tangem/domain/common/extensions/CardSdk.kt index bd7a3d7643..c7d205bbe0 100644 --- a/domain/src/main/java/com/tangem/domain/common/extensions/CardSdk.kt +++ b/domain/src/main/java/com/tangem/domain/common/extensions/CardSdk.kt @@ -13,15 +13,12 @@ val FirmwareVersion.Companion.SolanaTokensAvailable get() = FirmwareVersion(4, 52) fun CardDTO.supportedBlockchains(): List { - val supportedBlockchains = when { - firmwareVersion < FirmwareVersion.MultiWalletAvailable -> { - Blockchain.fromCurve(EllipticCurve.Secp256k1) - } - - else -> { - (Blockchain.fromCurve(EllipticCurve.Secp256k1) + Blockchain.fromCurve(EllipticCurve.Ed25519)).distinct() - } + val supportedBlockchains = if (firmwareVersion < FirmwareVersion.MultiWalletAvailable) { + Blockchain.fromCurve(EllipticCurve.Secp256k1) + } else { + wallets.flatMap { Blockchain.fromCurve(it.curve) }.distinct() } + return supportedBlockchains .filter { isTestCard == it.isTestnet() } .filter { it.isSupportedInApp() } @@ -38,12 +35,8 @@ fun CardDTO.supportedTokens(): List { } } } - val filtered = tokensSupportedByCard.filter { isTestCard == it.isTestnet() } - return filtered -} -fun CardDTO.canHandleBlockchain(blockchain: Blockchain): Boolean { - return this.supportedBlockchains().contains(blockchain) + return tokensSupportedByCard.filter { isTestCard == it.isTestnet() } } fun CardDTO.canHandleToken(blockchain: Blockchain): Boolean {