Updated on 2026-08-14

This commit is contained in:
Tangem 2023-01-18 10:42:54 +03:00
parent 479d142807
commit 43ee7319ee
3 changed files with 163 additions and 0 deletions

View file

@ -6,16 +6,62 @@ import com.tangem.tap.domain.model.UserWallet
import kotlinx.coroutines.flow.Flow
interface UserWalletsListManager {
/**
* [Flow] with all saved [UserWallet]s updates
* */
val userWallets: Flow<List<UserWallet>>
/**
* [Flow] with selected [UserWallet] updates
* */
val selectedUserWallet: Flow<UserWallet>
/**
* Selected [UserWallet]
* */
val selectedUserWalletSync: UserWallet?
/**
* Indicates that all [UserWallet]s is unlocked
*
* @see [isLockedSync]
* @see [UserWallet.isLocked]
* */
val isLocked: Flow<Boolean>
/**
* Indicates that all [UserWallet]s is unlocked
*
* Sync version
*
* @see [isLocked]
* @see [UserWallet.isLocked]
* */
val isLockedSync: Boolean
val hasSavedUserWallets: Boolean
/**
* Receive saved [UserWallet]s, populate [userWallets] flow with it and set [isLocked] as false.
* Require biometric user authorization
*
* @return [CompletionResult] of operation, with selected [UserWallet]
* or null if there is no selected [UserWallet]
* */
suspend fun unlockWithBiometry(): CompletionResult<UserWallet?>
/**
* Remove [UserWallet]s from [userWallets] and set [isLocked] as true
* */
fun lock()
/**
* Set [UserWallet] with provided [UserWalletId] as selected
*
* @param userWalletId [UserWalletId] of [UserWallet] which must be selected
*
* @return [CompletionResult] of operation with selected [UserWallet]
* */
suspend fun selectWallet(userWalletId: UserWalletId): CompletionResult<UserWallet>
/**
@ -38,10 +84,30 @@ interface UserWalletsListManager {
* */
suspend fun update(userWalletId: UserWalletId, update: (UserWallet) -> UserWallet): CompletionResult<UserWallet>
/**
* Delete saved [UserWallet]s with provided [UserWalletId]s
*
* @param userWalletIds [UserWalletId]s of [UserWallet]s which must be deleted
*
* @return [CompletionResult] of operation
* */
suspend fun delete(userWalletIds: List<UserWalletId>): CompletionResult<Unit>
/**
* Clear all saved [UserWallet]s and set [isLocked] as true
*
* @return [CompletionResult] of operation
* */
suspend fun clear(): CompletionResult<Unit>
/**
* Get [UserWallet] with provided [UserWalletId]
* May terminate with [NoSuchElementException] if [UserWallet] is not found
*
* @return [CompletionResult] of operation with found [UserWallet]
* */
suspend fun get(userWalletId: UserWalletId): CompletionResult<UserWallet>
// For provider
companion object
}

View file

@ -5,25 +5,70 @@ import com.tangem.tap.domain.model.UserWallet
import com.tangem.tap.features.wallet.models.Currency
interface WalletCurrenciesManager {
/**
* Update [UserWallet] currencies with same blockchain as provided [Currency] blockchain
* [UserWallet] currencies updates can be observed
* with [com.tangem.tap.domain.walletStores.WalletStoresManager.getAll]
* or [com.tangem.tap.domain.walletStores.WalletStoresManager.get]
*
* @param userWallet [UserWallet] which currencies will be updated
* @param currency [Currency] to find other currencies to update
*
* @return [CompletionResult] of operation
* */
suspend fun update(
userWallet: UserWallet,
currency: Currency,
): CompletionResult<Unit>
/**
* Add list of [Currency] to [UserWallet].
* [UserWallet] currencies updates can be observed
* with [com.tangem.tap.domain.walletStores.WalletStoresManager.getAll]
* or [com.tangem.tap.domain.walletStores.WalletStoresManager.get]
*
* @param userWallet [UserWallet] to add currencies
* @param currenciesToAdd list of [Currency] to add [UserWallet]
*
* @return [CompletionResult] of operation
* */
suspend fun addCurrencies(
userWallet: UserWallet,
currenciesToAdd: List<Currency>,
): CompletionResult<Unit>
/**
* Remove [Currency] from [UserWallet]
* [UserWallet] currencies updates can be observed
* with [com.tangem.tap.domain.walletStores.WalletStoresManager.getAll]
* or [com.tangem.tap.domain.walletStores.WalletStoresManager.get]
*
* @param userWallet [UserWallet] which currency will be removed
* @param currencyToRemove [Currency] to remove from [UserWallet]
*
* @return [CompletionResult] of operation
* */
suspend fun removeCurrency(
userWallet: UserWallet,
currencyToRemove: Currency,
): CompletionResult<Unit>
/**
* Remove list of [Currency] from [UserWallet]
* [UserWallet] currencies updates can be observed
* with [com.tangem.tap.domain.walletStores.WalletStoresManager.getAll]
* or [com.tangem.tap.domain.walletStores.WalletStoresManager.get]
*
* @param userWallet [UserWallet] which currency will be removed
* @param currenciesToRemove list of [Currency] to remove from [UserWallet]
*
* @return [CompletionResult] of operation
* */
suspend fun removeCurrencies(
userWallet: UserWallet,
currenciesToRemove: List<Currency>,
): CompletionResult<Unit>
// For provider
companion object
}

View file

@ -7,25 +7,77 @@ import com.tangem.tap.domain.model.WalletStoreModel
import kotlinx.coroutines.flow.Flow
interface WalletStoresManager {
/**
* Get all [WalletStoreModel]s updates
*
* @return [Flow] with map of [WalletStoreModel] list assigned by [UserWalletId]
* */
fun getAll(): Flow<Map<UserWalletId, List<WalletStoreModel>>>
/**
* Get [WalletStoreModel]s updates which associated with provided [UserWalletId]
*
* @param userWalletId [UserWalletId] of user wallet
*
* @return [Flow] with [WalletStoreModel] list
* */
fun get(userWalletId: UserWalletId): Flow<List<WalletStoreModel>>
/**
* Delete [WalletStoreModel]s associated with provided [UserWalletId]s
*
* @param userWalletsIds [UserWalletId] list
*
* @return [CompletionResult] of operation
* */
suspend fun delete(userWalletsIds: List<UserWalletId>): CompletionResult<Unit>
/**
* Clear all [WalletStoreModel]s
*
* @return [CompletionResult] of operation
* */
suspend fun clear(): CompletionResult<Unit>
/**
* Fetch wallet stores associated with provided [UserWallet]. Fetched [WalletStoreModel]s updates can be observed
* with [get] and [getAll] methods
*
* @param userWallet [UserWallet] to fetch [WalletStoreModel]s
*
* @return [CompletionResult] of operation
* */
suspend fun fetch(
userWallet: UserWallet,
refresh: Boolean = false,
): CompletionResult<Unit>
/**
* Fetch wallet stores associated with provided [UserWallet]s. Fetched [WalletStoreModel]s updates can be observed
* with [get] and [getAll] methods
*
* @param userWallets [UserWallet]s list to fetch [WalletStoreModel]s
*
* @return [CompletionResult] of operation
* */
suspend fun fetch(
userWallets: List<UserWallet>,
refresh: Boolean = false,
): CompletionResult<Unit>
/**
* Update [WalletStoreModel]s amounts associated with provided [UserWallet]s
*
* @param userWallets [UserWallet]s list to update [WalletStoreModel]s amounts
*
* @return [CompletionResult] of operation
* */
suspend fun updateAmounts(
userWallets: List<UserWallet>,
): CompletionResult<Unit>
// For provider
companion object
}