Updated on 2026-08-14
This commit is contained in:
parent
4c8af6b8e9
commit
1472431435
54 changed files with 370 additions and 352 deletions
|
|
@ -1,53 +0,0 @@
|
|||
package com.tangem.tap.data
|
||||
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.common.catching
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
|
||||
class UserWalletsStoreRepositoryProxy(
|
||||
private val userWalletsListRepository: UserWalletsListRepository,
|
||||
) : UserWalletsStore {
|
||||
|
||||
override val selectedUserWalletOrNull: UserWallet?
|
||||
get() = userWalletsListRepository.selectedUserWallet.value
|
||||
|
||||
override val userWallets: Flow<List<UserWallet>>
|
||||
get() = flow {
|
||||
userWalletsListRepository.load()
|
||||
userWalletsListRepository.userWallets.collect {
|
||||
emit(requireNotNull(it))
|
||||
}
|
||||
}
|
||||
|
||||
override val userWalletsSync: List<UserWallet>
|
||||
get() = userWalletsListRepository.userWallets.value.orEmpty()
|
||||
|
||||
override fun getSyncOrNull(key: UserWalletId): UserWallet? {
|
||||
return userWalletsListRepository.userWallets.value?.find { it.walletId == key }
|
||||
}
|
||||
|
||||
override fun getSyncStrict(key: UserWalletId): UserWallet {
|
||||
return requireNotNull(getSyncOrNull(key)) { "Unable to find user wallet with provided ID: $key" }
|
||||
}
|
||||
|
||||
override suspend fun update(
|
||||
userWalletId: UserWalletId,
|
||||
update: suspend (UserWallet) -> UserWallet,
|
||||
): CompletionResult<UserWallet> {
|
||||
return catching {
|
||||
val userWallet = userWalletsListRepository.userWallets.value?.find { it.walletId == userWalletId }
|
||||
requireNotNull(userWallet) { "Unable to find user wallet with provided ID: $userWalletId" }
|
||||
val updatedUserWallet = update(userWallet)
|
||||
userWalletsListRepository.saveWithoutLock(
|
||||
userWallet = updatedUserWallet,
|
||||
canOverride = true,
|
||||
)
|
||||
updatedUserWallet
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
package com.tangem.tap.di.data
|
||||
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.tap.data.UserWalletsStoreRepositoryProxy
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal object UserWalletsStoreModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideUserWalletsStore(userWalletsListRepository: UserWalletsListRepository): UserWalletsStore {
|
||||
return UserWalletsStoreRepositoryProxy(userWalletsListRepository)
|
||||
}
|
||||
}
|
||||
|
|
@ -38,9 +38,7 @@ import com.tangem.utils.coroutines.runSuspendCatching
|
|||
import com.tangem.utils.extensions.addOrReplace
|
||||
import com.tangem.utils.extensions.indexOfFirstOrNull
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
|
|
@ -69,14 +67,6 @@ internal class DefaultUserWalletsListRepository(
|
|||
|
||||
private val mutex = Mutex()
|
||||
|
||||
override fun getSyncOrNull(id: UserWalletId): UserWallet? {
|
||||
return userWallets.value?.find { it.walletId == id }
|
||||
}
|
||||
|
||||
override fun getSyncStrict(id: UserWalletId): UserWallet {
|
||||
return requireNotNull(getSyncOrNull(id)) { "Unable to find user wallet with provided ID: $id" }
|
||||
}
|
||||
|
||||
override suspend fun load() {
|
||||
mutex.withLock {
|
||||
if (userWallets.value != null) return
|
||||
|
|
@ -111,13 +101,6 @@ internal class DefaultUserWalletsListRepository(
|
|||
}
|
||||
}
|
||||
|
||||
override fun loadAndGet(): Flow<List<UserWallet>> = flow {
|
||||
load()
|
||||
userWallets.collect {
|
||||
emit(requireNotNull(it))
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun userWalletsSync(): List<UserWallet> {
|
||||
load()
|
||||
return requireNotNull(userWallets.value) {
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
package com.tangem.tap.domain.userWalletList.repository
|
||||
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.tap.domain.userWalletList.model.UserWalletEncryptionKey
|
||||
|
||||
internal interface UserWalletsKeysRepository {
|
||||
/**
|
||||
* Obtaining the encryption keys of all user wallets from the biometric vault. Biometric authentication required
|
||||
* If that operation runs more than biometric cipher key expiration time then the user will not receive all
|
||||
* encryption keys
|
||||
* @return [CompletionResult] of operation with stored [UserWalletEncryptionKey] list
|
||||
* */
|
||||
suspend fun getAll(): CompletionResult<List<UserWalletEncryptionKey>>
|
||||
|
||||
/**
|
||||
* Save the encryption key for user wallet. Biometric authentication not required
|
||||
* @param encryptionKey [UserWalletEncryptionKey] to save
|
||||
* @return [CompletionResult] of operation
|
||||
* */
|
||||
suspend fun save(encryptionKey: UserWalletEncryptionKey): CompletionResult<Unit>
|
||||
|
||||
/**
|
||||
* Delete encryption keys for user wallets. Biometric authentication not required
|
||||
* @param userWalletsIds List of [UserWalletId] whose encryption keys will be deleted
|
||||
* */
|
||||
suspend fun delete(userWalletsIds: List<UserWalletId>)
|
||||
|
||||
/**
|
||||
* Clear all encryption keys for user wallets. Biometric authentication not required
|
||||
* */
|
||||
suspend fun clear()
|
||||
|
||||
/**
|
||||
* Determine if the user has saved user wallets
|
||||
* @return [Boolean] true if user has saved wallets
|
||||
* */
|
||||
fun hasSavedEncryptionKeys(): Boolean
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue