Updated on 2026-08-14

This commit is contained in:
Tangem 2025-08-05 15:45:35 +04:00
parent 539c1a2689
commit fd3d95097f
6 changed files with 160 additions and 0 deletions

1
data/account/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1,37 @@
plugins {
alias(deps.plugins.android.library)
alias(deps.plugins.kotlin.android)
alias(deps.plugins.kotlin.kapt)
id("configuration")
}
android {
namespace = "com.tangem.data.account"
}
dependencies {
// region Project - Core
api(projects.core.utils)
// endregion
// region Project - Domain
api(projects.domain.account)
api(projects.domain.models)
// endregion
// Project - Data
implementation(projects.core.datasource)
// endregion
// region DI
implementation(deps.hilt.core)
kapt(deps.hilt.kapt)
// endregion
// region Other Dependencies
implementation(deps.arrow.core)
implementation(deps.kotlin.coroutines)
implementation(deps.timber)
// endregion
}

View file

@ -0,0 +1,25 @@
package com.tangem.data.account.di
import com.tangem.data.account.repository.DefaultAccountsCRUDRepository
import com.tangem.datasource.local.datastore.RuntimeSharedStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.repository.AccountsCRUDRepository
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 AccountDataModule {
@Provides
@Singleton
fun provideAccountsCRUDRepository(userWalletsStore: UserWalletsStore): AccountsCRUDRepository {
return DefaultAccountsCRUDRepository(
runtimeStore = RuntimeSharedStore(),
userWalletsStore = userWalletsStore,
)
}
}

View file

@ -0,0 +1,47 @@
package com.tangem.data.account.repository
import arrow.core.Option
import arrow.core.Option.Companion.catch
import arrow.core.none
import com.tangem.datasource.local.datastore.RuntimeSharedStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.account.repository.AccountsCRUDRepository
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.utils.extensions.addOrReplace
/**
[REDACTED_AUTHOR]
*/
// TODO: [REDACTED_JIRA]
internal class DefaultAccountsCRUDRepository(
private val runtimeStore: RuntimeSharedStore<List<AccountList>>,
private val userWalletsStore: UserWalletsStore,
) : AccountsCRUDRepository {
override suspend fun getAccounts(userWalletId: UserWalletId): Option<AccountList> = catch {
runtimeStore.getSyncOrNull()
?.firstOrNull { it.userWallet.walletId == userWalletId }
?: return none()
}
override suspend fun getAccount(accountId: AccountId): Option<Account.CryptoPortfolio> = catch {
runtimeStore.getSyncOrNull().orEmpty()
.flatMap { it.accounts }
.firstOrNull { it.accountId == accountId } as? Account.CryptoPortfolio
?: return none()
}
override suspend fun saveAccounts(accountList: AccountList) {
runtimeStore.update(emptyList()) {
it.addOrReplace(accountList) { it.userWallet.walletId == accountList.userWallet.walletId }
}
}
override fun getUserWallet(userWalletId: UserWalletId): UserWallet {
return userWalletsStore.getSyncStrict(userWalletId)
}
}

View file

@ -0,0 +1,49 @@
package com.tangem.domain.account.repository
import arrow.core.Option
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
/**
* Repository interface for performing CRUD operations on accounts
*
[REDACTED_AUTHOR]
*/
interface AccountsCRUDRepository {
/**
* Retrieves a list of accounts associated with a specific user wallet
*
* @param userWalletId the unique identifier of the user wallet
* @return an [Option] containing the [AccountList] if found, or `Option.None` if not
*/
suspend fun getAccounts(userWalletId: UserWalletId): Option<AccountList>
/**
* Retrieves a specific account by its unique identifier
*
* @param accountId the unique identifier of the account
* @return an [Option] containing the [Account.CryptoPortfolio] if found, or `Option.None` if not
*/
suspend fun getAccount(accountId: AccountId): Option<Account.CryptoPortfolio>
/**
* Saves a list of accounts to the repository
*
* @param accountList the list of accounts to be saved.
*/
@Throws
suspend fun saveAccounts(accountList: AccountList)
/**
* Retrieves a user wallet by its unique identifier
*
* @param userWalletId the unique identifier of the user wallet
* @return the [UserWallet] associated with the given identifier
*/
@Throws
fun getUserWallet(userWalletId: UserWalletId): UserWallet
}

View file

@ -334,6 +334,7 @@ include(":domain:wallet-manager:models")
// endregion Domain modules
// region Data modules
include(":data:account")
include(":data:app-currency")
include(":data:app-theme")
include(":data:balance-hiding")