Updated on 2026-08-14

This commit is contained in:
Tangem 2025-07-16 17:23:44 +05:00
parent 352ae036f3
commit e5f25fdfb1
7 changed files with 97 additions and 19 deletions

View file

@ -1,7 +1,6 @@
package com.tangem.datasource.info package com.tangem.datasource.info
import android.os.Build import android.os.Build
import com.tangem.utils.SupportedLanguages
import com.tangem.utils.info.AppInfoProvider import com.tangem.utils.info.AppInfoProvider
import com.tangem.utils.version.AppVersionProvider import com.tangem.utils.version.AppVersionProvider
import java.util.* import java.util.*
@ -17,7 +16,7 @@ internal class AndroidAppInfoProvider @Inject constructor(
override val osVersion: String override val osVersion: String
get() = Build.VERSION.RELEASE get() = Build.VERSION.RELEASE
override val language: String override val language: String
get() = SupportedLanguages.getCurrentSupportedLanguageCode() get() = Locale.getDefault().language
override val timezone: String override val timezone: String
get() = TimeZone.getDefault().id get() = TimeZone.getDefault().id
override val appVersion: String override val appVersion: String

View file

@ -38,6 +38,7 @@ class UserTokensSaver(
userWalletId = userWalletId, userWalletId = userWalletId,
response = response, response = response,
) )
store(userWalletId, enrichedUserTokensResponse, false) store(userWalletId, enrichedUserTokensResponse, false)
push(userWalletId, enrichedUserTokensResponse, false) push(userWalletId, enrichedUserTokensResponse, false)
} }

View file

@ -71,7 +71,7 @@ internal class DefaultCurrenciesRepository(
isGroupedByNetwork = isGroupedByNetwork, isGroupedByNetwork = isGroupedByNetwork,
isSortedByBalance = isSortedByBalance, isSortedByBalance = isSortedByBalance,
) )
userTokensSaver.storeAndPush(userWalletId, response) userTokensSaver.store(userWalletId, response)
} }
override suspend fun saveNewCurrenciesList(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) { override suspend fun saveNewCurrenciesList(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) {
@ -129,6 +129,61 @@ internal class DefaultCurrenciesRepository(
currenciesToAdd currenciesToAdd
} }
override suspend fun saveNewCurrenciesListCache(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) {
withContext(dispatchers.io) {
val savedResponse = requireNotNull(
value = getSavedUserTokensResponseSync(key = userWalletId),
lazyMessage = { "Saved tokens empty. Can not perform add currencies action." },
)
val newCurrencies = populateCurrenciesWithMissedCoins(currencies)
val updatedResponse = savedResponse.copy(
tokens = newCurrencies.map(userTokensResponseFactory::createResponseToken),
)
userTokensSaver.store(
userWalletId = userWalletId,
response = updatedResponse,
)
fetchExpressAssetsByNetworkIds(
userWallet = userWalletsStore.getSyncStrict(key = userWalletId),
userTokens = updatedResponse,
)
}
}
override suspend fun addCurrenciesCache(
userWalletId: UserWalletId,
currencies: List<CryptoCurrency>,
): List<CryptoCurrency> = withContext(dispatchers.io) {
val savedCurrencies = requireNotNull(
value = getSavedUserTokensResponseSync(key = userWalletId),
lazyMessage = { "Saved tokens empty. Can not perform add currencies action" },
)
val currenciesToAdd = filterAlreadyAddedCurrencies(
savedCurrencies = savedCurrencies.tokens,
currenciesToAdd = populateCurrenciesWithMissedCoins(currencies = currencies),
)
val updatedResponse = savedCurrencies.copy(
tokens = savedCurrencies.tokens + currenciesToAdd.map(userTokensResponseFactory::createResponseToken),
)
userTokensSaver.store(
userWalletId = userWalletId,
response = updatedResponse,
)
fetchExpressAssetsByNetworkIds(
userWallet = userWalletsStore.getSyncStrict(key = userWalletId),
userTokens = updatedResponse,
)
currenciesToAdd
}
private fun filterAlreadyAddedCurrencies( private fun filterAlreadyAddedCurrencies(
savedCurrencies: List<UserTokensResponse.Token>, savedCurrencies: List<UserTokensResponse.Token>,
currenciesToAdd: List<CryptoCurrency>, currenciesToAdd: List<CryptoCurrency>,
@ -589,17 +644,16 @@ internal class DefaultCurrenciesRepository(
} }
override suspend fun syncTokens(userWalletId: UserWalletId) { override suspend fun syncTokens(userWalletId: UserWalletId) {
val savedCurrencies = requireNotNull( runCatching {
value = getSavedUserTokensResponseSync(key = userWalletId), val savedCurrencies = requireNotNull(
lazyMessage = { "Saved tokens empty. Can not perform add currencies action" }, value = getSavedUserTokensResponseSync(key = userWalletId),
) lazyMessage = { "Saved tokens empty. Can not perform add currencies action" },
userTokensSaver.push( )
userWalletId = userWalletId, userTokensSaver.storeAndPush(
response = savedCurrencies, userWalletId = userWalletId,
onFailSend = { response = savedCurrencies,
throw IllegalStateException("Unable to push tokens") )
}, }
)
} }
override fun getCardTypesResolver(userWalletId: UserWalletId): CardTypesResolver { override fun getCardTypesResolver(userWalletId: UserWalletId): CardTypesResolver {

View file

@ -50,7 +50,7 @@ class SaveManagedTokensUseCase(
val addingCurrencies = currenciesToAdd.mapToCryptoCurrencies(userWalletId) val addingCurrencies = currenciesToAdd.mapToCryptoCurrencies(userWalletId)
val savedCurrencies = currenciesRepository.addCurrencies( val savedCurrencies = currenciesRepository.addCurrenciesCache(
userWalletId = userWalletId, userWalletId = userWalletId,
currencies = addingCurrencies, currencies = addingCurrencies,
) )
@ -87,6 +87,8 @@ class SaveManagedTokensUseCase(
networks = addedCurrencies.map(CryptoCurrency::network).toSet(), networks = addedCurrencies.map(CryptoCurrency::network).toSet(),
), ),
) )
currenciesRepository.syncTokens(userWalletId)
} }
private suspend fun refreshUpdatedYieldBalances( private suspend fun refreshUpdatedYieldBalances(

View file

@ -66,7 +66,7 @@ class SaveMarketTokensUseCase(
) )
} }
val savedCurrencies = currenciesRepository.addCurrencies( val savedCurrencies = currenciesRepository.addCurrenciesCache(
userWalletId = userWalletId, userWalletId = userWalletId,
currencies = addedCurrencies, currencies = addedCurrencies,
) )
@ -86,6 +86,7 @@ class SaveMarketTokensUseCase(
networks = addedCurrencies.map(CryptoCurrency::network).toSet(), networks = addedCurrencies.map(CryptoCurrency::network).toSet(),
), ),
) )
currenciesRepository.syncTokens(userWalletId)
} }
private suspend fun refreshUpdatedYieldBalances( private suspend fun refreshUpdatedYieldBalances(

View file

@ -119,7 +119,7 @@ class AddCryptoCurrenciesUseCase(
* Refreshes the network statuses for tokens that have corresponding coins in the * Refreshes the network statuses for tokens that have corresponding coins in the
* [existingCurrencies] list. * [existingCurrencies] list.
*/ */
private suspend fun Raise<Throwable>.refreshUpdatedNetworks( private suspend fun refreshUpdatedNetworks(
userWalletId: UserWalletId, userWalletId: UserWalletId,
currencyToAdd: CryptoCurrency, currencyToAdd: CryptoCurrency,
existingCurrencies: List<CryptoCurrency>, existingCurrencies: List<CryptoCurrency>,
@ -140,7 +140,8 @@ class AddCryptoCurrenciesUseCase(
networks = setOfNotNull(networksToUpdate, networkToUpdate), networks = setOfNotNull(networksToUpdate, networkToUpdate),
), ),
) )
.bind()
currenciesRepository.syncTokens(userWalletId)
} }
private suspend fun refreshUpdatedYieldBalances(userWalletId: UserWalletId, addedCurrency: CryptoCurrency) { private suspend fun refreshUpdatedYieldBalances(userWalletId: UserWalletId, addedCurrency: CryptoCurrency) {
@ -191,7 +192,7 @@ class AddCryptoCurrenciesUseCase(
private suspend fun Raise<Throwable>.addCurrencies(userWalletId: UserWalletId, currency: CryptoCurrency) { private suspend fun Raise<Throwable>.addCurrencies(userWalletId: UserWalletId, currency: CryptoCurrency) {
catch( catch(
{ currenciesRepository.addCurrencies(userWalletId, listOf(currency)) }, { currenciesRepository.addCurrenciesCache(userWalletId, listOf(currency)) },
) { ) {
raise(it) raise(it)
} }

View file

@ -52,6 +52,26 @@ interface CurrenciesRepository {
*/ */
suspend fun addCurrencies(userWalletId: UserWalletId, currencies: List<CryptoCurrency>): List<CryptoCurrency> suspend fun addCurrencies(userWalletId: UserWalletId, currencies: List<CryptoCurrency>): List<CryptoCurrency>
/**
* Saves the given list of cryptocurrencies for a specific multi-currency user wallet.
*
* @param userWalletId The unique identifier of the user wallet.
* @param currencies The list of cryptocurrencies to be saved.
*/
@Deprecated("Tech debt")
suspend fun saveNewCurrenciesListCache(userWalletId: UserWalletId, currencies: List<CryptoCurrency>)
/**
* Add currencies to a specific user wallet.
*
* @param userWalletId The unique identifier of the user wallet.
* @param currencies The currencies which must be added.
* @throws DataError.UserWalletError.WrongUserWallet If single-currency user wallet
* ID provided.
*/
@Deprecated("Tech debt")
suspend fun addCurrenciesCache(userWalletId: UserWalletId, currencies: List<CryptoCurrency>): List<CryptoCurrency>
/** /**
* Removes currency from a specific user wallet. * Removes currency from a specific user wallet.
* *