Updated on 2026-08-14
This commit is contained in:
parent
539c1a2689
commit
fd3d95097f
6 changed files with 160 additions and 0 deletions
1
data/account/.gitignore
vendored
Normal file
1
data/account/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
37
data/account/build.gradle.kts
Normal file
37
data/account/build.gradle.kts
Normal 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
|
||||
}
|
||||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue