Updated on 2026-08-14
This commit is contained in:
parent
591dce57c4
commit
0e5c6fa85b
3 changed files with 20 additions and 14 deletions
|
|
@ -103,7 +103,7 @@ internal class BiometricUserWalletsListManager(
|
|||
|
||||
override suspend fun save(userWallet: UserWallet, canOverride: Boolean): CompletionResult<Unit> {
|
||||
return if (canOverride) {
|
||||
saveInternal(userWallet, changeSelectedUserWallet = true)
|
||||
saveInternal(userWallet, changeSelectedUserWallet = true, canOverridePublicInfo = false)
|
||||
} else {
|
||||
val isWalletSaved = state.value.userWallets
|
||||
.any {
|
||||
|
|
@ -113,7 +113,7 @@ internal class BiometricUserWalletsListManager(
|
|||
if (isWalletSaved) {
|
||||
CompletionResult.Failure(UserWalletsListError.WalletAlreadySaved)
|
||||
} else {
|
||||
saveInternal(userWallet, changeSelectedUserWallet = true)
|
||||
saveInternal(userWallet, changeSelectedUserWallet = true, canOverridePublicInfo = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ internal class BiometricUserWalletsListManager(
|
|||
update(storedUserWallet)
|
||||
}
|
||||
.flatMap { updatedUserWallet ->
|
||||
saveInternal(updatedUserWallet, changeSelectedUserWallet = false)
|
||||
saveInternal(updatedUserWallet, changeSelectedUserWallet = false, canOverridePublicInfo = true)
|
||||
}
|
||||
.flatMap {
|
||||
get(userWalletId)
|
||||
|
|
@ -181,10 +181,11 @@ internal class BiometricUserWalletsListManager(
|
|||
private suspend fun saveInternal(
|
||||
userWallet: UserWallet,
|
||||
changeSelectedUserWallet: Boolean,
|
||||
canOverridePublicInfo: Boolean,
|
||||
): CompletionResult<Unit> {
|
||||
return saveEncryptionKeyIfNotNull(userWallet)
|
||||
.flatMap { sensitiveInformationRepository.save(userWallet, encryptionKey = it) }
|
||||
.flatMap { publicInformationRepository.save(userWallet) }
|
||||
.flatMap { publicInformationRepository.save(userWallet, canOverridePublicInfo) }
|
||||
.map {
|
||||
if (changeSelectedUserWallet) {
|
||||
selectedUserWalletRepository.set(userWallet.walletId)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import com.tangem.domain.wallets.models.UserWalletId
|
|||
import com.tangem.tap.domain.userWalletList.model.UserWalletPublicInformation
|
||||
|
||||
internal interface UserWalletsPublicInformationRepository {
|
||||
suspend fun save(userWallet: UserWallet): CompletionResult<Unit>
|
||||
suspend fun save(userWallet: UserWallet, canOverride: Boolean): CompletionResult<Unit>
|
||||
|
||||
suspend fun getAll(): CompletionResult<List<UserWalletPublicInformation>>
|
||||
|
||||
|
|
|
|||
|
|
@ -24,18 +24,23 @@ internal class DefaultUserWalletsPublicInformationRepository(
|
|||
Types.newParameterizedType(List::class.java, UserWalletPublicInformation::class.java),
|
||||
)
|
||||
|
||||
override suspend fun save(userWallet: UserWallet): CompletionResult<Unit> {
|
||||
override suspend fun save(userWallet: UserWallet, canOverride: Boolean): CompletionResult<Unit> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
getAll()
|
||||
.flatMap { savedInformation ->
|
||||
val infoToSave = withContext(Dispatchers.Default) {
|
||||
savedInformation.addOrReplace(userWallet.publicInformation) {
|
||||
userWallet.walletId == it.walletId
|
||||
}
|
||||
getAll().flatMap { savedWalletsInformation ->
|
||||
val infoToSave = if (canOverride) {
|
||||
savedWalletsInformation.addOrReplace(userWallet.publicInformation) {
|
||||
it.walletId == userWallet.walletId
|
||||
}
|
||||
} else {
|
||||
if (savedWalletsInformation.none { it.walletId == userWallet.walletId }) {
|
||||
savedWalletsInformation + userWallet.publicInformation
|
||||
} else {
|
||||
return@withContext CompletionResult.Success(Unit)
|
||||
}
|
||||
|
||||
save(infoToSave)
|
||||
}
|
||||
|
||||
save(infoToSave)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue