Updated on 2026-08-14
This commit is contained in:
parent
3f647e8180
commit
b9db5dce07
4 changed files with 68 additions and 30 deletions
|
|
@ -87,6 +87,26 @@ internal class DefaultCurrenciesRepository(
|
|||
storeAndPushTokens(userWalletId, response)
|
||||
}
|
||||
|
||||
override suspend fun saveNewCurrenciesList(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) {
|
||||
val savedResponse = requireNotNull(
|
||||
value = getSavedUserTokensResponseSync(key = userWalletId),
|
||||
lazyMessage = { "Saved tokens empty. Can not perform add currencies action" },
|
||||
)
|
||||
val newCoins = createCoinsForNewTokenList(
|
||||
userWalletId = userWalletId,
|
||||
newTokens = currencies.filterIsInstance<CryptoCurrency.Token>(),
|
||||
)
|
||||
val newCurrencies = (newCoins + currencies).distinct()
|
||||
val updatedResponse = savedResponse.copy(
|
||||
tokens = newCurrencies.map(userTokensResponseFactory::createResponseToken),
|
||||
)
|
||||
storeAndPushTokens(
|
||||
userWalletId = userWalletId,
|
||||
response = updatedResponse,
|
||||
)
|
||||
fetchExchangeableUserMarketCoinsByIds(userWalletId, updatedResponse)
|
||||
}
|
||||
|
||||
override suspend fun addCurrencies(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) {
|
||||
return withContext(dispatchers.io) {
|
||||
val savedCurrencies = requireNotNull(
|
||||
|
|
@ -125,6 +145,19 @@ internal class DefaultCurrenciesRepository(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun createCoinsForNewTokenList(
|
||||
userWalletId: UserWalletId,
|
||||
newTokens: List<CryptoCurrency.Token>,
|
||||
): List<CryptoCurrency.Coin> {
|
||||
return newTokens.mapNotNull {
|
||||
cryptoCurrencyFactory.createCoin(
|
||||
blockchain = getBlockchain(networkId = it.network.id),
|
||||
extraDerivationPath = it.network.derivationPath.value,
|
||||
scanResponse = getUserWallet(userWalletId).scanResponse,
|
||||
)
|
||||
}.distinct()
|
||||
}
|
||||
|
||||
private suspend fun createCoinsForNewTokens(
|
||||
userWalletId: UserWalletId,
|
||||
newTokens: List<CryptoCurrency.Token>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue