Updated on 2026-08-14
This commit is contained in:
parent
4c8af6b8e9
commit
1472431435
54 changed files with 370 additions and 352 deletions
|
|
@ -5,7 +5,6 @@ import com.tangem.domain.common.wallets.error.*
|
|||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
/**
|
||||
|
|
@ -31,21 +30,12 @@ interface UserWalletsListRepository {
|
|||
*/
|
||||
val selectedUserWallet: StateFlow<UserWallet?>
|
||||
|
||||
/** Get user wallet by [id] */
|
||||
fun getSyncOrNull(id: UserWalletId): UserWallet?
|
||||
|
||||
/** Get user wallet by [id] */
|
||||
fun getSyncStrict(id: UserWalletId): UserWallet
|
||||
|
||||
/**
|
||||
* Loads user wallets list and selected wallet.
|
||||
* If the list is already loaded, it does nothing.
|
||||
*/
|
||||
suspend fun load()
|
||||
|
||||
/** Loads user wallets list and selected wallet and returns a flow of the list */
|
||||
fun loadAndGet(): Flow<List<UserWallet>>
|
||||
|
||||
/**
|
||||
* Gets and if necessary loads user wallets list and selected wallet.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import arrow.core.raise.either
|
|||
import com.tangem.domain.common.wallets.error.SaveWalletError
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
|
||||
/**
|
||||
* Update user wallet by [userWalletId] and return updated wallet.
|
||||
|
|
@ -29,4 +31,22 @@ suspend fun UserWalletsListRepository.update(
|
|||
.bind()
|
||||
|
||||
updatedUserWallet
|
||||
}
|
||||
|
||||
/** Get user wallet by [id] */
|
||||
fun UserWalletsListRepository.getSyncOrNull(id: UserWalletId): UserWallet? {
|
||||
return userWallets.value?.find { it.walletId == id }
|
||||
}
|
||||
|
||||
/** Get user wallet by [id] or throw an exception if it is not found */
|
||||
fun UserWalletsListRepository.getSyncStrict(id: UserWalletId): UserWallet {
|
||||
return requireNotNull(getSyncOrNull(id)) { "Unable to find user wallet with provided ID: $id" }
|
||||
}
|
||||
|
||||
/** Loads user wallets list and selected wallet and returns a flow of the list */
|
||||
fun UserWalletsListRepository.loadAndGet(): Flow<List<UserWallet>> = flow {
|
||||
load()
|
||||
userWallets.collect {
|
||||
emit(requireNotNull(it))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue