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

View file

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

View file

@ -71,7 +71,7 @@ internal class DefaultCurrenciesRepository(
isGroupedByNetwork = isGroupedByNetwork,
isSortedByBalance = isSortedByBalance,
)
userTokensSaver.storeAndPush(userWalletId, response)
userTokensSaver.store(userWalletId, response)
}
override suspend fun saveNewCurrenciesList(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) {
@ -129,6 +129,61 @@ internal class DefaultCurrenciesRepository(
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(
savedCurrencies: List<UserTokensResponse.Token>,
currenciesToAdd: List<CryptoCurrency>,
@ -589,18 +644,17 @@ internal class DefaultCurrenciesRepository(
}
override suspend fun syncTokens(userWalletId: UserWalletId) {
runCatching {
val savedCurrencies = requireNotNull(
value = getSavedUserTokensResponseSync(key = userWalletId),
lazyMessage = { "Saved tokens empty. Can not perform add currencies action" },
)
userTokensSaver.push(
userTokensSaver.storeAndPush(
userWalletId = userWalletId,
response = savedCurrencies,
onFailSend = {
throw IllegalStateException("Unable to push tokens")
},
)
}
}
override fun getCardTypesResolver(userWalletId: UserWalletId): CardTypesResolver {
return userWalletsStore.getSyncStrict(userWalletId).requireColdWallet().cardTypesResolver // TODO [REDACTED_TASK_KEY]

View file

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

View file

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

View file

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

View file

@ -52,6 +52,26 @@ interface CurrenciesRepository {
*/
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.
*