Skip to content

Commit 1ae6ec6

Browse files
committed
Merge branch 'multisig/05-data-models' into multisig/06-account-pages-support
* multisig/05-data-models: fix: Address PR #515 review comments fix: Remove redundant methods and use injected use cases
2 parents d414b74 + 4a22ce1 commit 1ae6ec6

File tree

10 files changed

+83
-145
lines changed

10 files changed

+83
-145
lines changed

app/src/main/kotlin/com/algorand/android/core/transaction/JointAccountTransactionSignHelper.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,16 @@ class JointAccountTransactionSignHelper @Inject constructor(
127127
): ByteArray? {
128128
val signerAccount = getLocalAccount(signerAddress) ?: return null
129129
return when (signerAccount) {
130-
is LocalAccount.Algo25 -> signWithAlgo25Account(transactionBytes, signerAddress)
131-
is LocalAccount.HdKey -> signWithHdKeyAccount(transactionBytes, signerAccount)
130+
is LocalAccount.Algo25 -> {
131+
localAccountSigningHelper.signWithAlgo25AccountReturnSignature(transactionBytes, signerAddress)
132+
}
133+
is LocalAccount.HdKey -> {
134+
localAccountSigningHelper.signWithHdKeyAccountReturnSignature(transactionBytes, signerAccount)
135+
}
132136
else -> null
133137
}
134138
}
135139

136-
private suspend fun signWithAlgo25Account(transactionBytes: ByteArray, signerAddress: String): ByteArray? {
137-
return localAccountSigningHelper.signWithAlgo25AccountReturnSignature(transactionBytes, signerAddress)
138-
}
139-
140-
private suspend fun signWithHdKeyAccount(transactionBytes: ByteArray, hdKey: LocalAccount.HdKey): ByteArray? {
141-
return localAccountSigningHelper.signWithHdKeyAccountReturnSignature(transactionBytes, hdKey)
142-
}
143-
144140
private data class PreparedJointAccountData(
145141
val jointAccount: LocalAccount.Joint,
146142
val proposerAddress: String,

app/src/main/kotlin/com/algorand/android/modules/accounts/ui/viewmodel/AccountPreviewProcessor.kt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.algorand.wallet.account.custom.domain.usecase.GetAccountsCustomInfo
3232
import com.algorand.wallet.account.detail.domain.model.AccountRegistrationType
3333
import com.algorand.wallet.account.detail.domain.model.AccountType
3434
import com.algorand.wallet.account.detail.domain.usecase.GetAccountRegistrationType
35+
import com.algorand.wallet.account.detail.domain.usecase.GetAccountType
3536
import com.algorand.wallet.account.local.domain.model.LocalAccount
3637
import com.algorand.wallet.account.local.domain.usecase.GetLocalAccount
3738
import com.algorand.wallet.account.local.domain.usecase.GetLocalAccounts
@@ -56,6 +57,7 @@ class AccountPreviewProcessor @Inject constructor(
5657
private val getLocalAccounts: GetLocalAccounts,
5758
private val getAccountsCustomInfo: GetAccountsCustomInfo,
5859
private val getAccountRegistrationType: GetAccountRegistrationType,
60+
private val getAccountType: GetAccountType,
5961
private val sortAccountsBySortingPreference: SortAccountsBySortingPreference,
6062
private val amountRendererTypeMapper: AmountRendererTypeMapper,
6163
private val getCompactPrimaryAmountRenderer: GetCompactPrimaryAmountRenderer,
@@ -121,8 +123,8 @@ class AccountPreviewProcessor @Inject constructor(
121123
val localAccounts = getLocalAccounts()
122124
val customInfos = getAccountsCustomInfo(localAccounts.map { it.algoAddress })
123125
val accountErrorItems = localAccounts
124-
.map { localAccount ->
125-
val accountType = getLocalAccountType(localAccount)
126+
.mapNotNull { localAccount ->
127+
val accountType = getAccountType(localAccount.algoAddress) ?: return@mapNotNull null
126128
val registrationType = getAccountRegistrationType(localAccount)
127129
val customInfo = customInfos[localAccount.algoAddress]
128130
val displayName = getAccountDisplayName(
@@ -202,14 +204,4 @@ class AccountPreviewProcessor @Inject constructor(
202204
)
203205
)
204206
}
205-
206-
private fun getLocalAccountType(localAccount: LocalAccount): AccountType {
207-
return when (localAccount) {
208-
is LocalAccount.Algo25 -> AccountType.Algo25
209-
is LocalAccount.LedgerBle -> AccountType.LedgerBle
210-
is LocalAccount.NoAuth -> AccountType.NoAuth
211-
is LocalAccount.HdKey -> AccountType.HdKey
212-
is LocalAccount.Joint -> AccountType.Joint
213-
}
214-
}
215207
}

common-sdk/src/main/kotlin/com/algorand/wallet/inbox/asset/data/repository/AssetInboxRepositoryImpl.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,26 @@
1212

1313
package com.algorand.wallet.inbox.asset.data.repository
1414

15+
import com.algorand.wallet.foundation.cache.InMemoryCachedObject
1516
import com.algorand.wallet.inbox.asset.domain.model.AssetInboxRequest
1617
import com.algorand.wallet.inbox.asset.domain.repository.AssetInboxRepository
17-
import com.algorand.wallet.inbox.data.cache.InboxInMemoryCache
18+
import com.algorand.wallet.inbox.domain.model.InboxMessages
1819
import kotlinx.coroutines.flow.Flow
1920
import kotlinx.coroutines.flow.map
2021

2122
internal class AssetInboxRepositoryImpl(
22-
private val inboxInMemoryCache: InboxInMemoryCache
23+
private val inboxCache: InMemoryCachedObject<InboxMessages>,
24+
private val inboxCacheFlow: Flow<InboxMessages?>
2325
) : AssetInboxRepository {
2426

2527
override fun getRequestCountFlow(): Flow<Int> {
26-
return inboxInMemoryCache.observe().map { inboxMessages ->
28+
return inboxCacheFlow.map { inboxMessages ->
2729
inboxMessages?.assetInboxes?.sumOf { it.requestCount } ?: 0
2830
}
2931
}
3032

3133
override suspend fun getRequest(address: String): AssetInboxRequest? {
32-
val inboxMessages = inboxInMemoryCache.get()
34+
val inboxMessages = inboxCache.get()
3335
return inboxMessages?.assetInboxes?.find { it.address == address }?.let {
3436
AssetInboxRequest(address = it.address, requestCount = it.requestCount)
3537
}

common-sdk/src/main/kotlin/com/algorand/wallet/inbox/asset/di/AssetInboxModule.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,29 @@
1212

1313
package com.algorand.wallet.inbox.asset.di
1414

15+
import com.algorand.wallet.foundation.cache.InMemoryCachedObject
1516
import com.algorand.wallet.inbox.asset.data.repository.AssetInboxRepositoryImpl
1617
import com.algorand.wallet.inbox.asset.domain.repository.AssetInboxRepository
1718
import com.algorand.wallet.inbox.asset.domain.usecase.GetAssetInboxRequest
1819
import com.algorand.wallet.inbox.asset.domain.usecase.GetAssetInboxRequestCountFlow
19-
import com.algorand.wallet.inbox.data.cache.InboxInMemoryCache
20+
import com.algorand.wallet.inbox.domain.model.InboxMessages
2021
import dagger.Module
2122
import dagger.Provides
2223
import dagger.hilt.InstallIn
2324
import dagger.hilt.components.SingletonComponent
25+
import kotlinx.coroutines.flow.MutableStateFlow
26+
import javax.inject.Named
2427

2528
@Module
2629
@InstallIn(SingletonComponent::class)
2730
internal object AssetInboxModule {
2831

2932
@Provides
30-
fun provideAssetInboxRepository(inboxInMemoryCache: InboxInMemoryCache): AssetInboxRepository {
31-
return AssetInboxRepositoryImpl(inboxInMemoryCache)
33+
fun provideAssetInboxRepository(
34+
@Named("inboxCache") inboxCache: InMemoryCachedObject<InboxMessages>,
35+
@Named("inboxCacheFlow") inboxCacheFlow: MutableStateFlow<InboxMessages?>
36+
): AssetInboxRepository {
37+
return AssetInboxRepositoryImpl(inboxCache, inboxCacheFlow)
3238
}
3339

3440
@Provides

common-sdk/src/main/kotlin/com/algorand/wallet/inbox/data/cache/DefaultInboxInMemoryCache.kt

Lines changed: 0 additions & 46 deletions
This file was deleted.

common-sdk/src/main/kotlin/com/algorand/wallet/inbox/data/cache/InboxInMemoryCache.kt

Lines changed: 0 additions & 23 deletions
This file was deleted.

common-sdk/src/main/kotlin/com/algorand/wallet/inbox/di/InboxModule.kt

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
package com.algorand.wallet.inbox.di
1414

1515
import com.algorand.wallet.foundation.cache.InMemoryCacheProvider
16-
import com.algorand.wallet.inbox.data.cache.DefaultInboxInMemoryCache
17-
import com.algorand.wallet.inbox.data.cache.InboxInMemoryCache
16+
import com.algorand.wallet.foundation.cache.InMemoryCachedObject
1817
import com.algorand.wallet.inbox.data.repository.InboxApiRepositoryImpl
1918
import com.algorand.wallet.inbox.domain.InboxCacheManager
2019
import com.algorand.wallet.inbox.domain.InboxCacheManagerImpl
20+
import com.algorand.wallet.inbox.domain.model.InboxMessages
2121
import com.algorand.wallet.inbox.domain.repository.InboxApiRepository
2222
import com.algorand.wallet.inbox.domain.usecase.CacheInboxMessages
2323
import com.algorand.wallet.inbox.domain.usecase.ClearInboxCache
@@ -35,6 +35,7 @@ import dagger.Module
3535
import dagger.Provides
3636
import dagger.hilt.InstallIn
3737
import dagger.hilt.components.SingletonComponent
38+
import kotlinx.coroutines.flow.MutableStateFlow
3839
import retrofit2.Retrofit
3940
import javax.inject.Named
4041
import javax.inject.Singleton
@@ -43,6 +44,9 @@ import javax.inject.Singleton
4344
@InstallIn(SingletonComponent::class)
4445
internal object InboxModule {
4546

47+
private const val INBOX_CACHE_NAME = "inboxCache"
48+
private const val INBOX_CACHE_FLOW_NAME = "inboxCacheFlow"
49+
4650
@Provides
4751
@Singleton
4852
fun provideInboxApiService(
@@ -52,8 +56,6 @@ internal object InboxModule {
5256
}
5357

5458
@Provides
55-
@Singleton
56-
@Named(InboxApiRepository.INJECTION_NAME)
5759
fun provideInboxApiRepository(
5860
repository: InboxApiRepositoryImpl
5961
): InboxApiRepository = repository
@@ -64,31 +66,53 @@ internal object InboxModule {
6466

6567
@Provides
6668
@Singleton
67-
fun provideInboxInMemoryCache(inMemoryCacheProvider: InMemoryCacheProvider): InboxInMemoryCache {
68-
return DefaultInboxInMemoryCache(inMemoryCacheProvider)
69-
}
69+
@Named(INBOX_CACHE_NAME)
70+
fun provideInboxCache(
71+
inMemoryCacheProvider: InMemoryCacheProvider
72+
): InMemoryCachedObject<InboxMessages> = inMemoryCacheProvider.getInMemoryCache()
73+
74+
@Provides
75+
@Singleton
76+
@Named(INBOX_CACHE_FLOW_NAME)
77+
fun provideInboxCacheFlow(): MutableStateFlow<InboxMessages?> = MutableStateFlow(null)
7078

7179
@Provides
7280
fun provideInboxSearchMapper(impl: InboxSearchMapperImpl): InboxSearchMapper = impl
7381

7482
@Provides
75-
fun provideCacheInboxMessages(cache: InboxInMemoryCache): CacheInboxMessages {
76-
return CacheInboxMessages(cache::put)
83+
fun provideCacheInboxMessages(
84+
@Named(INBOX_CACHE_NAME) cache: InMemoryCachedObject<InboxMessages>,
85+
@Named(INBOX_CACHE_FLOW_NAME) cacheFlow: MutableStateFlow<InboxMessages?>
86+
): CacheInboxMessages {
87+
return CacheInboxMessages { inboxMessages ->
88+
cache.put(inboxMessages)
89+
cacheFlow.value = inboxMessages
90+
}
7791
}
7892

7993
@Provides
80-
fun provideClearInboxCache(cache: InboxInMemoryCache): ClearInboxCache {
81-
return ClearInboxCache(cache::clear)
94+
fun provideClearInboxCache(
95+
@Named(INBOX_CACHE_NAME) cache: InMemoryCachedObject<InboxMessages>,
96+
@Named(INBOX_CACHE_FLOW_NAME) cacheFlow: MutableStateFlow<InboxMessages?>
97+
): ClearInboxCache {
98+
return ClearInboxCache {
99+
cache.clear()
100+
cacheFlow.value = null
101+
}
82102
}
83103

84104
@Provides
85-
fun provideGetInboxMessagesFlow(cache: InboxInMemoryCache): GetInboxMessagesFlow {
86-
return GetInboxMessagesFlow(cache::observe)
105+
fun provideGetInboxMessagesFlow(
106+
@Named(INBOX_CACHE_FLOW_NAME) cacheFlow: MutableStateFlow<InboxMessages?>
107+
): GetInboxMessagesFlow {
108+
return GetInboxMessagesFlow { cacheFlow }
87109
}
88110

89111
@Provides
90-
fun provideGetInboxMessages(cache: InboxInMemoryCache): GetInboxMessages {
91-
return GetInboxMessages(cache::get)
112+
fun provideGetInboxMessages(
113+
@Named(INBOX_CACHE_NAME) cache: InMemoryCachedObject<InboxMessages>
114+
): GetInboxMessages {
115+
return GetInboxMessages { cache.get() }
92116
}
93117

94118
@Provides

common-sdk/src/main/kotlin/com/algorand/wallet/inbox/domain/InboxCacheManagerImpl.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import com.algorand.wallet.inbox.domain.usecase.GetInboxValidAddresses
2626
import kotlinx.coroutines.CoroutineScope
2727
import kotlinx.coroutines.flow.collectLatest
2828
import javax.inject.Inject
29-
import javax.inject.Named
3029

3130
internal class InboxCacheManagerImpl @Inject constructor(
3231
private val cacheManager: LifecycleAwareCacheManager,
@@ -36,7 +35,6 @@ internal class InboxCacheManagerImpl @Inject constructor(
3635
private val getInboxValidAddresses: GetInboxValidAddresses,
3736
private val getAllAccountInformationFlow: GetAllAccountInformationFlow,
3837
private val getSelectedNodeDeviceId: GetSelectedNodeDeviceId,
39-
@param:Named(InboxApiRepository.INJECTION_NAME)
4038
private val inboxApiRepository: InboxApiRepository
4139
) : InboxCacheManager, LifecycleAwareCacheManager.CacheManagerListener {
4240

common-sdk/src/main/kotlin/com/algorand/wallet/inbox/domain/repository/InboxApiRepository.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,4 @@ interface InboxApiRepository {
2727
deviceId: Long,
2828
jointAddress: String
2929
): PeraResult<Unit>
30-
31-
companion object {
32-
const val INJECTION_NAME = "inboxApiRepositoryInjectionName"
33-
}
3430
}

0 commit comments

Comments
 (0)