@@ -56,25 +56,15 @@ final class AdamantAccountService: AccountService, @unchecked Sendable {
56
56
self . coreDataStack = coreDataStack
57
57
58
58
NotificationCenter . default. addObserver ( forName: . AdamantAccountService. forceUpdateBalance, object: nil , queue: OperationQueue . main) { [ weak self] _ in
59
- self ? . update ( )
59
+ self ? . update ( resetBalanceAndUpdate : false , updateOnlyADM : false , updateOnlyVisible : true )
60
60
}
61
61
62
- NotificationCenter . default
63
- . notifications ( named: . AdamantReachabilityMonitor. reachabilityChanged)
64
- . sink { @MainActor [ weak self] data in
65
- let connection = data. userInfo ? [ AdamantUserInfoKey . ReachabilityMonitor. connection] as? Bool
66
-
67
- guard connection == true else { return }
68
- self ? . update ( resetBalanceAndUpdate: false , updateOnlyADM: false , updateOnlyVisible: true )
69
- }
70
- . store ( in: & subscriptions)
71
-
72
62
NotificationCenter . default
73
63
. notifications ( named: UIApplication . didBecomeActiveNotification, object: nil )
74
64
. sink { @MainActor [ weak self] _ in
75
65
guard self ? . previousAppState == . background else { return }
76
66
self ? . previousAppState = . active
77
- self ? . update ( )
67
+ self ? . update ( resetBalanceAndUpdate : false , updateOnlyADM : false , updateOnlyVisible : true )
78
68
}
79
69
. store ( in: & subscriptions)
80
70
@@ -85,9 +75,12 @@ final class AdamantAccountService: AccountService, @unchecked Sendable {
85
75
}
86
76
. store ( in: & subscriptions)
87
77
88
- connection. filter { $0 } . sink { [ weak self] _ in
89
- self ? . update ( )
90
- } . store ( in: & subscriptions)
78
+ connection
79
+ . filter { $0 }
80
+ . sink { [ weak self] connection in
81
+ guard connection == true else { return }
82
+ self ? . update ( resetBalanceAndUpdate: false , updateOnlyADM: false , updateOnlyVisible: true )
83
+ } . store ( in: & subscriptions)
91
84
92
85
setupSecureStore ( )
93
86
}
@@ -231,15 +224,7 @@ extension AdamantAccountService {
231
224
}
232
225
233
226
// MARK: - AccountService
234
- extension AdamantAccountService {
235
- // MARK: Update logged account info
236
- /// Does not update UI balance, but the
237
- /// `func update(resetBalanceAndUpdate: Bool, updateOnlyADM: Bool, updateOnlyVisible: Bool)
238
- /// does, via `wallets.first(where: {$0.core is AdmWalletService})?.core.update()`in completion
239
- func update( ) {
240
- self . update ( nil )
241
- }
242
-
227
+ extension AdamantAccountService {
243
228
func update( resetBalanceAndUpdate: Bool , updateOnlyADM: Bool , updateOnlyVisible: Bool ) {
244
229
let wallets = walletServiceCompose. getWallets ( )
245
230
if !updateOnlyADM {
@@ -262,7 +247,7 @@ extension AdamantAccountService {
262
247
}
263
248
264
249
update ( { _ in
265
- wallets. first ( where: { $0. core is AdmWalletService } ) ? . core. update ( )
250
+ wallets. first ( where: { $0. core is AdmWalletService } ) ? . core. update ( )
266
251
} )
267
252
}
268
253
@@ -296,14 +281,14 @@ extension AdamantAccountService {
296
281
markBalanceAsFresh ( )
297
282
self . account = account
298
283
284
+ state = . loggedIn
285
+ completion ? ( . success( account: account, alert: nil ) )
286
+
299
287
NotificationCenter . default. post (
300
288
name: . AdamantAccountService. accountDataUpdated,
301
289
object: self
302
290
)
303
291
304
- state = . loggedIn
305
- completion ? ( . success( account: account, alert: nil ) )
306
-
307
292
case . failure( let error) :
308
293
completion ? ( . failure( . apiError( error: error) ) )
309
294
isBalanceExpired = true
0 commit comments