Skip to content

Commit 1a7352e

Browse files
committed
Merge branch 'develop'
2 parents ff3b66d + c29fb3a commit 1a7352e

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

api/src/main/java/com/getcode/manager/SessionManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.getcode.network.client.registerInstallation
77
import com.getcode.network.client.updatePreferences
88
import com.getcode.solana.organizer.Organizer
99
import com.getcode.utils.installationId
10+
import com.getcode.utils.trace
1011
import com.google.firebase.Firebase
1112
import com.google.firebase.installations.installations
1213
import kotlinx.coroutines.flow.MutableStateFlow
@@ -52,7 +53,7 @@ class SessionManager @Inject constructor(
5253
}
5354

5455
fun clear() {
55-
Timber.d("Clearing session state")
56+
trace("Clearing session state")
5657
update {
5758
SessionState(entropyB64 = null, keyPair = null, isAuthenticated = false)
5859
}

app/src/main/java/com/getcode/manager/AuthManager.kt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.getcode.network.repository.getPublicKeyBase58
2525
import com.getcode.network.repository.isMock
2626
import com.getcode.util.AccountUtils
2727
import com.getcode.utils.ErrorUtils
28+
import com.getcode.utils.TraceType
2829
import com.getcode.utils.installationId
2930
import com.getcode.utils.trace
3031
import com.getcode.utils.token
@@ -62,13 +63,20 @@ class AuthManager @Inject constructor(
6263
) : CoroutineScope by CoroutineScope(Dispatchers.IO) {
6364
private var softLoginDisabled: Boolean = false
6465

66+
companion object {
67+
private const val TAG = "AuthManager"
68+
internal fun taggedTrace(message: String, type: TraceType = TraceType.Log) {
69+
trace(message = message, type = type, tag = TAG)
70+
}
71+
}
72+
6573
@SuppressLint("CheckResult")
6674
fun init(onInitialized: () -> Unit = { }) {
6775
launch {
68-
LibsodiumInitializer.initialize()
6976
val token = AccountUtils.getToken(context)
7077
softLogin(token.orEmpty())
7178
.subscribeOn(Schedulers.computation())
79+
.doOnComplete { LibsodiumInitializer.initializeWithCallback(onInitialized) }
7280
.subscribe(onInitialized, ErrorUtils::handleError)
7381
}
7482
}
@@ -83,9 +91,10 @@ class AuthManager @Inject constructor(
8391
isSoftLogin: Boolean = false,
8492
rollbackOnError: Boolean = false
8593
): Completable {
86-
trace("Login: isSoftLogin: $isSoftLogin, rollbackOnError: $rollbackOnError")
94+
taggedTrace("Login: isSoftLogin: $isSoftLogin, rollbackOnError: $rollbackOnError")
8795

8896
if (entropyB64.isEmpty()) {
97+
taggedTrace("provided entropy was empty", type = TraceType.Error)
8998
sessionManager.clear()
9099
return Completable.complete()
91100
}
@@ -163,14 +172,14 @@ class AuthManager @Inject constructor(
163172
.ignoreElement()
164173
}
165174

166-
fun deleteAndLogout(activity: Activity, onComplete: () -> Unit = {}) {
175+
fun deleteAndLogout(context: Context, onComplete: () -> Unit = {}) {
167176
//todo: add account deletion
168-
logout(activity, onComplete)
177+
logout(context, onComplete)
169178
}
170179

171-
fun logout(activity: Activity, onComplete: () -> Unit = {}) {
180+
fun logout(context: Context, onComplete: () -> Unit = {}) {
172181
launch {
173-
AccountUtils.removeAccounts(activity)
182+
AccountUtils.removeAccounts(context)
174183
.doOnSuccess { res: Boolean ->
175184
if (res) {
176185
clearToken()
@@ -181,8 +190,8 @@ class AuthManager @Inject constructor(
181190
}
182191
}
183192

184-
suspend fun logout(activity: Activity): Result<Unit> {
185-
return AccountUtils.removeAccounts(activity).toFlowable()
193+
suspend fun logout(context: Context): Result<Unit> {
194+
return AccountUtils.removeAccounts(context).toFlowable()
186195
.to {
187196
runCatching { it.firstOrError().blockingGet() }
188197
}.onSuccess {
@@ -194,7 +203,7 @@ class AuthManager @Inject constructor(
194203
private fun fetchData(entropyB64: String):
195204
Single<Pair<PhoneRepository.GetAssociatedPhoneNumberResponse, IdentityRepository.GetUserResponse>> {
196205

197-
trace("fetching account data")
206+
taggedTrace("fetching account data")
198207

199208
var owner = SessionManager.authState.value.keyPair
200209
if (owner == null || SessionManager.authState.value.entropyB64 != entropyB64) {
@@ -226,7 +235,7 @@ class AuthManager @Inject constructor(
226235
.toSingleDefault(Pair(phone!!, user!!))
227236
}
228237
.doOnSuccess {
229-
trace("account data fetched successfully")
238+
taggedTrace("account data fetched successfully")
230239
launch { savePrefs(phone!!, user!!) }
231240
launch { exchange.fetchRatesIfNeeded() }
232241
launch { historyController.fetchChats() }
@@ -240,7 +249,7 @@ class AuthManager @Inject constructor(
240249

241250
private fun loginAnalytics(entropyB64: String) {
242251
val owner = mnemonicManager.getKeyPair(entropyB64)
243-
trace("analytics login event")
252+
taggedTrace("analytics login event")
244253
analytics.login(
245254
ownerPublicKey = owner.getPublicKeyBase58(),
246255
autoCompleteCount = 0,

app/src/main/java/com/getcode/util/AccountUtils.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object AccountUtils {
3333
am.setAuthToken(a, acctType, token)
3434
}
3535

36-
suspend fun removeAccounts(context: Activity): @NonNull Single<Boolean> {
36+
suspend fun removeAccounts(context: Context): @NonNull Single<Boolean> {
3737
return getAccount(context)
3838
.map {
3939
if (it.second == null) return@map false
@@ -42,7 +42,7 @@ object AccountUtils {
4242
}
4343
}
4444

45-
private suspend fun getAccount(context: Activity): @NonNull Single<Pair<String?, Account?>> {
45+
private suspend fun getAccount(context: Context): @NonNull Single<Pair<String?, Account?>> {
4646
val subject = SingleSubject.create<Pair<String?, Account?>>()
4747
return subject.doOnSubscribe {
4848
CoroutineScope(Dispatchers.IO).launch {
@@ -61,7 +61,9 @@ object AccountUtils {
6161
}
6262
}
6363

64-
private suspend fun getAccountNoActivity(context: Context) : Pair<String?, Account?>? = suspendCancellableCoroutine {cont ->
64+
private suspend fun getAccountNoActivity(
65+
context: Context
66+
) : Pair<String?, Account?>? = suspendCancellableCoroutine { cont ->
6567
trace("getAuthToken", type = TraceType.Silent)
6668
val am: AccountManager = AccountManager.get(context)
6769
val accountthing = am.accounts.getOrNull(0)

0 commit comments

Comments
 (0)