Skip to content

Commit fdd98e9

Browse files
committed
[trello.com/c/dEf1yVQr] Increase speed of loading ADM wallet after recconection
1 parent 927e606 commit fdd98e9

File tree

2 files changed

+13
-29
lines changed

2 files changed

+13
-29
lines changed

Adamant/ServiceProtocols/AccountService.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ protocol AccountService: AnyObject, Sendable {
156156
// MARK: Account functions
157157

158158
/// Update logged account info
159-
func update()
160159
func update(resetBalanceAndUpdate: Bool, updateOnlyADM: Bool, updateOnlyVisible: Bool)
161160

162161
/// Login into Adamant using passphrase.

Adamant/Services/AdamantAccountService.swift

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,15 @@ final class AdamantAccountService: AccountService, @unchecked Sendable {
5656
self.coreDataStack = coreDataStack
5757

5858
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)
6060
}
6161

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-
7262
NotificationCenter.default
7363
.notifications(named: UIApplication.didBecomeActiveNotification, object: nil)
7464
.sink { @MainActor [weak self] _ in
7565
guard self?.previousAppState == .background else { return }
7666
self?.previousAppState = .active
77-
self?.update()
67+
self?.update(resetBalanceAndUpdate: false, updateOnlyADM: false, updateOnlyVisible: true)
7868
}
7969
.store(in: &subscriptions)
8070

@@ -85,9 +75,12 @@ final class AdamantAccountService: AccountService, @unchecked Sendable {
8575
}
8676
.store(in: &subscriptions)
8777

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)
9184

9285
setupSecureStore()
9386
}
@@ -231,15 +224,7 @@ extension AdamantAccountService {
231224
}
232225

233226
// 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 {
243228
func update(resetBalanceAndUpdate: Bool, updateOnlyADM: Bool, updateOnlyVisible: Bool) {
244229
let wallets = walletServiceCompose.getWallets()
245230
if !updateOnlyADM {
@@ -262,7 +247,7 @@ extension AdamantAccountService {
262247
}
263248

264249
update({ _ in
265-
wallets.first(where: {$0.core is AdmWalletService})?.core.update()
250+
wallets.first(where: {$0.core is AdmWalletService})?.core.update()
266251
})
267252
}
268253

@@ -296,14 +281,14 @@ extension AdamantAccountService {
296281
markBalanceAsFresh()
297282
self.account = account
298283

284+
state = .loggedIn
285+
completion?(.success(account: account, alert: nil))
286+
299287
NotificationCenter.default.post(
300288
name: .AdamantAccountService.accountDataUpdated,
301289
object: self
302290
)
303291

304-
state = .loggedIn
305-
completion?(.success(account: account, alert: nil))
306-
307292
case .failure(let error):
308293
completion?(.failure(.apiError(error: error)))
309294
isBalanceExpired = true

0 commit comments

Comments
 (0)