Skip to content

Commit

Permalink
Delete subscriptions store module (#4222)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/488551667048375/1206717065299519/f

### Description
See task

### Steps to test this PR
See task
  • Loading branch information
marcosholgado authored Mar 1, 2024
1 parent c7cfee3 commit de21397
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 84 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ dependencies {
if (project.hasProperty('internal-testing')) {
implementation project(':subscriptions-api')
implementation project(':subscriptions-impl')
implementation project(':subscriptions-store')
internalImplementation project(':subscriptions-internal')
internalImplementation project(':network-protection-subscription-internal')
}
Expand Down
3 changes: 2 additions & 1 deletion subscriptions/subscriptions-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ dependencies {
implementation project(path: ':js-messaging-api')
implementation project(path: ':user-agent-api')
implementation project(path: ':subscriptions-api')
implementation project(path: ':subscriptions-store')
implementation project(path: ':settings-api')
implementation project(path: ':autofill-api')
implementation project(path: ':network-protection-api')
Expand All @@ -53,6 +52,7 @@ dependencies {

implementation AndroidX.appCompat
implementation KotlinX.coroutines.core
implementation AndroidX.work.runtimeKtx
implementation Google.android.material

implementation "com.android.billingclient:billing:_"
Expand All @@ -66,6 +66,7 @@ dependencies {
implementation AndroidX.constraintLayout
implementation Square.retrofit2.converter.moshi
implementation Square.okHttp3.okHttp
implementation AndroidX.security.crypto

// Testing dependencies
testImplementation project(path: ':common-test')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package com.duckduckgo.subscriptions.impl.di

import android.content.Context
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.subscriptions.store.AuthDataStore
import com.duckduckgo.subscriptions.store.AuthEncryptedDataStore
import com.duckduckgo.subscriptions.store.EncryptedSharedPrefsProvider
import com.duckduckgo.subscriptions.store.SharedPrefsProvider
import com.duckduckgo.subscriptions.impl.store.EncryptedSharedPrefsProvider
import com.duckduckgo.subscriptions.impl.store.SharedPrefsProvider
import com.duckduckgo.subscriptions.impl.store.SubscriptionsDataStore
import com.duckduckgo.subscriptions.impl.store.SubscriptionsEncryptedDataStore
import com.squareup.anvil.annotations.ContributesTo
import dagger.Module
import dagger.Provides
Expand All @@ -39,9 +39,9 @@ object SubscriptionsModule {

@Provides
@SingleInstanceIn(AppScope::class)
fun providesAuthDataStore(
fun providesSubscriptionsDataStore(
sharedPrefsProvider: SharedPrefsProvider,
): AuthDataStore {
return AuthEncryptedDataStore(sharedPrefsProvider)
): SubscriptionsDataStore {
return SubscriptionsEncryptedDataStore(sharedPrefsProvider)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.duckduckgo.subscriptions.impl.repository

import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.subscriptions.store.AuthDataStore
import com.duckduckgo.subscriptions.impl.store.SubscriptionsDataStore
import com.squareup.anvil.annotations.ContributesBinding
import dagger.SingleInstanceIn
import javax.inject.Inject
Expand All @@ -40,37 +40,41 @@ interface AuthRepository {
@ContributesBinding(AppScope::class)
@SingleInstanceIn(AppScope::class)
class RealAuthRepository @Inject constructor(
private val authDataStore: AuthDataStore,
private val subscriptionsDataStore: SubscriptionsDataStore,
) : AuthRepository {

override fun isUserAuthenticated(): Boolean = !authDataStore.accessToken.isNullOrBlank() && !authDataStore.authToken.isNullOrBlank()
override fun isUserAuthenticated(): Boolean =
!subscriptionsDataStore.accessToken.isNullOrBlank() && !subscriptionsDataStore.authToken.isNullOrBlank()

override suspend fun signOut() {
authDataStore.authToken = null
authDataStore.accessToken = null
authDataStore.platform = null
authDataStore.email = null
authDataStore.externalId = null
authDataStore.expiresOrRenewsAt = 0
subscriptionsDataStore.authToken = null
subscriptionsDataStore.accessToken = null
subscriptionsDataStore.platform = null
subscriptionsDataStore.email = null
subscriptionsDataStore.externalId = null
subscriptionsDataStore.expiresOrRenewsAt = 0
}

override suspend fun clearSubscriptionData() {
authDataStore.platform = null
authDataStore.expiresOrRenewsAt = 0
subscriptionsDataStore.platform = null
subscriptionsDataStore.expiresOrRenewsAt = 0
}

override suspend fun authenticate(authToken: String?, accessToken: String?, externalId: String?, email: String?) {
authDataStore.authToken = authToken
authDataStore.accessToken = accessToken
authDataStore.externalId = externalId
authDataStore.email = email
subscriptionsDataStore.authToken = authToken
subscriptionsDataStore.accessToken = accessToken
subscriptionsDataStore.externalId = externalId
subscriptionsDataStore.email = email
}

override fun tokens(): SubscriptionsTokens = SubscriptionsTokens(authToken = authDataStore.authToken, accessToken = authDataStore.accessToken)
override fun tokens(): SubscriptionsTokens = SubscriptionsTokens(
authToken = subscriptionsDataStore.authToken,
accessToken = subscriptionsDataStore.accessToken,
)

override suspend fun saveSubscriptionData(platform: String, expiresOrRenewsAt: Long) {
authDataStore.platform = platform
authDataStore.expiresOrRenewsAt = expiresOrRenewsAt
subscriptionsDataStore.platform = platform
subscriptionsDataStore.expiresOrRenewsAt = expiresOrRenewsAt
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.duckduckgo.subscriptions.store
package com.duckduckgo.subscriptions.impl.store

import android.content.Context
import android.content.SharedPreferences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

package com.duckduckgo.subscriptions.store
package com.duckduckgo.subscriptions.impl.store

import android.content.SharedPreferences
import androidx.core.content.edit

interface AuthDataStore {
interface SubscriptionsDataStore {
var accessToken: String?
var authToken: String?
var email: String?
Expand All @@ -29,9 +29,9 @@ interface AuthDataStore {
fun canUseEncryption(): Boolean
}

class AuthEncryptedDataStore(
class SubscriptionsEncryptedDataStore(
private val sharedPrefsProv: SharedPrefsProvider,
) : AuthDataStore {
) : SubscriptionsDataStore {

private val encryptedPreferences: SharedPreferences? by lazy { encryptedPreferences() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.duckduckgo.subscriptions.impl.billing.BillingClientWrapper
import com.duckduckgo.subscriptions.impl.billing.PurchaseState
import com.duckduckgo.subscriptions.impl.pixels.SubscriptionPixelSender
import com.duckduckgo.subscriptions.impl.repository.AuthRepository
import com.duckduckgo.subscriptions.impl.repository.FakeAuthDataStore
import com.duckduckgo.subscriptions.impl.repository.FakeSubscriptionsDataStore
import com.duckduckgo.subscriptions.impl.repository.RealAuthRepository
import com.duckduckgo.subscriptions.impl.services.AccessTokenResponse
import com.duckduckgo.subscriptions.impl.services.AccountResponse
Expand All @@ -32,7 +32,7 @@ import com.duckduckgo.subscriptions.impl.services.StoreLoginResponse
import com.duckduckgo.subscriptions.impl.services.SubscriptionResponse
import com.duckduckgo.subscriptions.impl.services.SubscriptionsService
import com.duckduckgo.subscriptions.impl.services.ValidateTokenResponse
import com.duckduckgo.subscriptions.store.AuthDataStore
import com.duckduckgo.subscriptions.impl.store.SubscriptionsDataStore
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.TestScope
Expand Down Expand Up @@ -62,7 +62,7 @@ class RealSubscriptionsManagerTest {

private val authService: AuthService = mock()
private val subscriptionsService: SubscriptionsService = mock()
private val authDataStore: AuthDataStore = FakeAuthDataStore()
private val authDataStore: SubscriptionsDataStore = FakeSubscriptionsDataStore()
private val authRepository = RealAuthRepository(authDataStore)
private val emailManager: EmailManager = mock()
private val billingClient: BillingClientWrapper = mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package com.duckduckgo.subscriptions.impl.repository

import com.duckduckgo.subscriptions.store.AuthDataStore
import com.duckduckgo.subscriptions.impl.store.SubscriptionsDataStore

class FakeAuthDataStore : AuthDataStore {
class FakeSubscriptionsDataStore : SubscriptionsDataStore {

override var accessToken: String? = null
override var authToken: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RealAuthRepositoryTest {
@get:Rule
val coroutineRule = CoroutineTestRule()

private val authStore = FakeAuthDataStore()
private val authStore = FakeSubscriptionsDataStore()
private val authRepository: AuthRepository = RealAuthRepository(authStore)

@Test
Expand Down
1 change: 0 additions & 1 deletion subscriptions/subscriptions-internal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ android {
dependencies {
anvil project(':anvil-compiler')
implementation project(':anvil-annotations')
implementation project(':subscriptions-store')
implementation project(':subscriptions-impl')
implementation project(':di')
implementation project(':common-utils')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.duckduckgo.internal.features.api.InternalFeaturePlugin
import com.duckduckgo.subscriptions.impl.AccessToken
import com.duckduckgo.subscriptions.impl.SubscriptionsData
import com.duckduckgo.subscriptions.impl.SubscriptionsManager
import com.duckduckgo.subscriptions.store.AuthDataStore
import com.duckduckgo.subscriptions.impl.store.SubscriptionsDataStore
import com.squareup.anvil.annotations.ContributesMultibinding
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -67,7 +67,7 @@ class InternalDeleteView @Inject constructor(
@ContributesMultibinding(AppScope::class)
class CopyDataView @Inject constructor(
private val subscriptionsManager: SubscriptionsManager,
private val authDataStore: AuthDataStore,
private val subscriptionsDataStore: SubscriptionsDataStore,
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
val dispatcherProvider: DispatcherProvider,
val context: Context,
Expand All @@ -84,7 +84,7 @@ class CopyDataView @Inject constructor(
val clipboardManager = context.getSystemService(ClipboardManager::class.java)

appCoroutineScope.launch(dispatcherProvider.io()) {
val auth = authDataStore.authToken
val auth = subscriptionsDataStore.authToken
val authToken = if (auth.isNullOrBlank()) {
"No auth token found"
} else {
Expand Down
1 change: 0 additions & 1 deletion subscriptions/subscriptions-store/.gitignore

This file was deleted.

41 changes: 0 additions & 41 deletions subscriptions/subscriptions-store/build.gradle

This file was deleted.

0 comments on commit de21397

Please sign in to comment.