@@ -25,6 +25,7 @@ import com.getcode.network.repository.getPublicKeyBase58
25
25
import com.getcode.network.repository.isMock
26
26
import com.getcode.util.AccountUtils
27
27
import com.getcode.utils.ErrorUtils
28
+ import com.getcode.utils.TraceType
28
29
import com.getcode.utils.installationId
29
30
import com.getcode.utils.trace
30
31
import com.getcode.utils.token
@@ -62,13 +63,20 @@ class AuthManager @Inject constructor(
62
63
) : CoroutineScope by CoroutineScope(Dispatchers .IO ) {
63
64
private var softLoginDisabled: Boolean = false
64
65
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
+
65
73
@SuppressLint(" CheckResult" )
66
74
fun init (onInitialized : () -> Unit = { }) {
67
75
launch {
68
- LibsodiumInitializer .initialize()
69
76
val token = AccountUtils .getToken(context)
70
77
softLogin(token.orEmpty())
71
78
.subscribeOn(Schedulers .computation())
79
+ .doOnComplete { LibsodiumInitializer .initializeWithCallback(onInitialized) }
72
80
.subscribe(onInitialized, ErrorUtils ::handleError)
73
81
}
74
82
}
@@ -83,9 +91,10 @@ class AuthManager @Inject constructor(
83
91
isSoftLogin : Boolean = false,
84
92
rollbackOnError : Boolean = false
85
93
): Completable {
86
- trace (" Login: isSoftLogin: $isSoftLogin , rollbackOnError: $rollbackOnError " )
94
+ taggedTrace (" Login: isSoftLogin: $isSoftLogin , rollbackOnError: $rollbackOnError " )
87
95
88
96
if (entropyB64.isEmpty()) {
97
+ taggedTrace(" provided entropy was empty" , type = TraceType .Error )
89
98
sessionManager.clear()
90
99
return Completable .complete()
91
100
}
@@ -163,14 +172,14 @@ class AuthManager @Inject constructor(
163
172
.ignoreElement()
164
173
}
165
174
166
- fun deleteAndLogout (activity : Activity , onComplete : () -> Unit = {}) {
175
+ fun deleteAndLogout (context : Context , onComplete : () -> Unit = {}) {
167
176
// todo: add account deletion
168
- logout(activity , onComplete)
177
+ logout(context , onComplete)
169
178
}
170
179
171
- fun logout (activity : Activity , onComplete : () -> Unit = {}) {
180
+ fun logout (context : Context , onComplete : () -> Unit = {}) {
172
181
launch {
173
- AccountUtils .removeAccounts(activity )
182
+ AccountUtils .removeAccounts(context )
174
183
.doOnSuccess { res: Boolean ->
175
184
if (res) {
176
185
clearToken()
@@ -181,8 +190,8 @@ class AuthManager @Inject constructor(
181
190
}
182
191
}
183
192
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()
186
195
.to {
187
196
runCatching { it.firstOrError().blockingGet() }
188
197
}.onSuccess {
@@ -194,7 +203,7 @@ class AuthManager @Inject constructor(
194
203
private fun fetchData (entropyB64 : String ):
195
204
Single <Pair <PhoneRepository .GetAssociatedPhoneNumberResponse , IdentityRepository .GetUserResponse >> {
196
205
197
- trace (" fetching account data" )
206
+ taggedTrace (" fetching account data" )
198
207
199
208
var owner = SessionManager .authState.value.keyPair
200
209
if (owner == null || SessionManager .authState.value.entropyB64 != entropyB64) {
@@ -226,7 +235,7 @@ class AuthManager @Inject constructor(
226
235
.toSingleDefault(Pair (phone!! , user!! ))
227
236
}
228
237
.doOnSuccess {
229
- trace (" account data fetched successfully" )
238
+ taggedTrace (" account data fetched successfully" )
230
239
launch { savePrefs(phone!! , user!! ) }
231
240
launch { exchange.fetchRatesIfNeeded() }
232
241
launch { historyController.fetchChats() }
@@ -240,7 +249,7 @@ class AuthManager @Inject constructor(
240
249
241
250
private fun loginAnalytics (entropyB64 : String ) {
242
251
val owner = mnemonicManager.getKeyPair(entropyB64)
243
- trace (" analytics login event" )
252
+ taggedTrace (" analytics login event" )
244
253
analytics.login(
245
254
ownerPublicKey = owner.getPublicKeyBase58(),
246
255
autoCompleteCount = 0 ,
0 commit comments