Updated on 2026-08-14
This commit is contained in:
commit
36acf08c79
4 changed files with 39 additions and 13 deletions
|
|
@ -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<Blockchain>,
|
||||
updatedCurrencies: List<Currency>,
|
||||
): CompletionResult<Unit> {
|
||||
val updatedBlockchains = updatedCurrencies
|
||||
.filterIsInstance<Currency.Blockchain>()
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,9 +121,10 @@ private inline fun List<WalletStoreModel>.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(),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue