Updated on 2026-08-14
This commit is contained in:
parent
cbd9ad505d
commit
309c9aad6c
4 changed files with 49 additions and 40 deletions
|
|
@ -97,31 +97,35 @@ internal class DefaultCurrenciesRepository(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun addCurrencies(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) {
|
override suspend fun addCurrencies(
|
||||||
withContext(dispatchers.io) {
|
userWalletId: UserWalletId,
|
||||||
val savedCurrencies = requireNotNull(
|
currencies: List<CryptoCurrency>,
|
||||||
value = getSavedUserTokensResponseSync(key = userWalletId),
|
): List<CryptoCurrency> = withContext(dispatchers.io) {
|
||||||
lazyMessage = { "Saved tokens empty. Can not perform add currencies action" },
|
val savedCurrencies = requireNotNull(
|
||||||
)
|
value = getSavedUserTokensResponseSync(key = userWalletId),
|
||||||
|
lazyMessage = { "Saved tokens empty. Can not perform add currencies action" },
|
||||||
|
)
|
||||||
|
|
||||||
val currenciesToAdd = populateCurrenciesWithMissedCoins(
|
val currenciesToAdd = filterAlreadyAddedCurrencies(
|
||||||
currencies = currencies,
|
savedCurrencies = savedCurrencies.tokens,
|
||||||
).let {
|
currenciesToAdd = populateCurrenciesWithMissedCoins(currencies = currencies),
|
||||||
filterAlreadyAddedCurrencies(savedCurrencies.tokens, it)
|
)
|
||||||
}
|
|
||||||
val updatedResponse = savedCurrencies.copy(
|
|
||||||
tokens = savedCurrencies.tokens + currenciesToAdd.map(userTokensResponseFactory::createResponseToken),
|
|
||||||
)
|
|
||||||
userTokensSaver.storeAndPush(
|
|
||||||
userWalletId = userWalletId,
|
|
||||||
response = updatedResponse,
|
|
||||||
)
|
|
||||||
|
|
||||||
fetchExpressAssetsByNetworkIds(
|
val updatedResponse = savedCurrencies.copy(
|
||||||
userWallet = userWalletsStore.getSyncStrict(key = userWalletId),
|
tokens = savedCurrencies.tokens + currenciesToAdd.map(userTokensResponseFactory::createResponseToken),
|
||||||
userTokens = updatedResponse,
|
)
|
||||||
)
|
|
||||||
}
|
userTokensSaver.storeAndPush(
|
||||||
|
userWalletId = userWalletId,
|
||||||
|
response = updatedResponse,
|
||||||
|
)
|
||||||
|
|
||||||
|
fetchExpressAssetsByNetworkIds(
|
||||||
|
userWallet = userWalletsStore.getSyncStrict(key = userWalletId),
|
||||||
|
userTokens = updatedResponse,
|
||||||
|
)
|
||||||
|
|
||||||
|
currenciesToAdd
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun filterAlreadyAddedCurrencies(
|
private fun filterAlreadyAddedCurrencies(
|
||||||
|
|
@ -573,7 +577,7 @@ internal class DefaultCurrenciesRepository(
|
||||||
|
|
||||||
override fun isNetworkFeeZero(userWalletId: UserWalletId, network: Network): Boolean {
|
override fun isNetworkFeeZero(userWalletId: UserWalletId, network: Network): Boolean {
|
||||||
val blockchain = Blockchain.fromNetworkId(network.backendId)
|
val blockchain = Blockchain.fromNetworkId(network.backendId)
|
||||||
return blockchain?.isNetworkFeeZero() ?: false
|
return blockchain?.isNetworkFeeZero() == true
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun syncTokens(userWalletId: UserWalletId) {
|
override suspend fun syncTokens(userWalletId: UserWalletId) {
|
||||||
|
|
|
||||||
|
|
@ -41,16 +41,15 @@ class SaveMarketTokensUseCase(
|
||||||
removedNetworks: Set<TokenMarketInfo.Network>,
|
removedNetworks: Set<TokenMarketInfo.Network>,
|
||||||
): Either<Throwable, Unit> = Either.catch {
|
): Either<Throwable, Unit> = Either.catch {
|
||||||
if (removedNetworks.isNotEmpty()) {
|
if (removedNetworks.isNotEmpty()) {
|
||||||
currenciesRepository.removeCurrencies(
|
val removedCurrencies = removedNetworks.mapNotNull {
|
||||||
userWalletId = userWalletId,
|
marketsTokenRepository.createCryptoCurrency(
|
||||||
currencies = removedNetworks.mapNotNull {
|
userWalletId = userWalletId,
|
||||||
marketsTokenRepository.createCryptoCurrency(
|
token = tokenMarketParams,
|
||||||
userWalletId = userWalletId,
|
network = it,
|
||||||
token = tokenMarketParams,
|
)
|
||||||
network = it,
|
}
|
||||||
)
|
|
||||||
},
|
currenciesRepository.removeCurrencies(userWalletId = userWalletId, currencies = removedCurrencies)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addedNetworks.isNotEmpty()) {
|
if (addedNetworks.isNotEmpty()) {
|
||||||
|
|
@ -67,13 +66,16 @@ class SaveMarketTokensUseCase(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
currenciesRepository.addCurrencies(userWalletId = userWalletId, currencies = addedCurrencies)
|
val savedCurrencies = currenciesRepository.addCurrencies(
|
||||||
|
userWalletId = userWalletId,
|
||||||
|
currencies = addedCurrencies,
|
||||||
|
)
|
||||||
|
|
||||||
refreshUpdatedNetworks(userWalletId, addedCurrencies)
|
refreshUpdatedNetworks(userWalletId, savedCurrencies)
|
||||||
|
|
||||||
refreshUpdatedYieldBalances(userWalletId, addedCurrencies)
|
refreshUpdatedYieldBalances(userWalletId, savedCurrencies)
|
||||||
|
|
||||||
refreshUpdatedQuotes(addedCurrencies)
|
refreshUpdatedQuotes(savedCurrencies)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ interface CurrenciesRepository {
|
||||||
* @throws DataError.UserWalletError.WrongUserWallet If single-currency user wallet
|
* @throws DataError.UserWalletError.WrongUserWallet If single-currency user wallet
|
||||||
* ID provided.
|
* ID provided.
|
||||||
*/
|
*/
|
||||||
suspend fun addCurrencies(userWalletId: UserWalletId, currencies: List<CryptoCurrency>)
|
suspend fun addCurrencies(userWalletId: UserWalletId, currencies: List<CryptoCurrency>): List<CryptoCurrency>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes currency from a specific user wallet.
|
* Removes currency from a specific user wallet.
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,10 @@ internal class MockCurrenciesRepository(
|
||||||
|
|
||||||
override suspend fun saveNewCurrenciesList(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) = Unit
|
override suspend fun saveNewCurrenciesList(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) = Unit
|
||||||
|
|
||||||
override suspend fun addCurrencies(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) = Unit
|
override suspend fun addCurrencies(
|
||||||
|
userWalletId: UserWalletId,
|
||||||
|
currencies: List<CryptoCurrency>,
|
||||||
|
): List<CryptoCurrency> = emptyList()
|
||||||
|
|
||||||
override suspend fun removeCurrency(userWalletId: UserWalletId, currency: CryptoCurrency) {
|
override suspend fun removeCurrency(userWalletId: UserWalletId, currency: CryptoCurrency) {
|
||||||
removeCurrencyResult.onLeft { throw it }
|
removeCurrencyResult.onLeft { throw it }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue