From 0488d26eddae98d3d39bcf641d0a51063673e8be Mon Sep 17 00:00:00 2001 From: EA Date: Thu, 3 Oct 2024 14:27:53 +0600 Subject: [PATCH] Disconnect TonConnect apps on delete account --- .../UnstoppableWallet/Core/App.swift | 2 +- .../Core/Managers/AccountManager.swift | 66 +++++++++---------- .../AccountRestoreWarningManager.swift | 10 +-- .../Core/Managers/BackupManager.swift | 8 ++- .../WalletConnectSessionManager.swift | 16 +++-- .../Core/Managers/WalletManager.swift | 12 +++- .../Core/Storage/CexAssetManager.swift | 10 +-- .../Modules/Main/MainBadgeService.swift | 18 ++--- .../Modules/Main/MainService.swift | 7 +- .../ManageAccount/ManageAccountService.swift | 14 ++-- .../ManageAccountsService.swift | 14 ++-- .../ProFeaturesAuthorizationManager.swift | 7 +- .../Settings/Main/MainSettingsService.swift | 6 +- .../TonConnect/TonConnectManager.swift | 23 ++++++- .../Wallet/EnabledWalletCacheManager.swift | 8 ++- .../Modules/Wallet/WalletService.swift | 32 +++++---- 16 files changed, 147 insertions(+), 106 deletions(-) diff --git a/UnstoppableWallet/UnstoppableWallet/Core/App.swift b/UnstoppableWallet/UnstoppableWallet/Core/App.swift index cbf01fd3a6..70e7a8258b 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/App.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/App.swift @@ -317,7 +317,7 @@ class App { statManager = StatManager(marketKit: marketKit, storage: statStorage, userDefaultsStorage: userDefaultsStorage) let tonConnectStorage = try TonConnectStorage(dbPool: dbPool) - tonConnectManager = TonConnectManager(storage: tonConnectStorage) + tonConnectManager = TonConnectManager(storage: tonConnectStorage, accountManager: accountManager) kitCleaner = KitCleaner(accountManager: accountManager) diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountManager.swift b/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountManager.swift index 14701b32d2..7d1121bd59 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountManager.swift @@ -1,17 +1,15 @@ import Combine -import RxRelay -import RxSwift class AccountManager { private let passcodeManager: PasscodeManager private let storage: AccountCachedStorage private var cancellables = Set() - private let activeAccountRelay = PublishRelay() - private let accountsRelay = PublishRelay<[Account]>() - private let accountUpdatedRelay = PublishRelay() - private let accountDeletedRelay = PublishRelay() - private let accountsLostRelay = BehaviorRelay(value: false) + private let activeAccountSubject = PassthroughSubject() + private let accountsSubject = PassthroughSubject<[Account], Never>() + private let accountUpdatedSubject = PassthroughSubject() + private let accountDeletedSubject = PassthroughSubject() + private let accountsLostSubject = CurrentValueSubject(false) private var lastCreatedAccount: Account? @@ -21,9 +19,7 @@ class AccountManager { storage = AccountCachedStorage(level: passcodeManager.currentPasscodeLevel, accountStorage: accountStorage, activeAccountStorage: activeAccountStorage) passcodeManager.$currentPasscodeLevel - .sink { [weak self] level in - self?.handle(level: level) - } + .sink { [weak self] in self?.handle(level: $0) } .store(in: &cancellables) passcodeManager.$isDuressPasscodeSet @@ -38,8 +34,8 @@ class AccountManager { private func handle(level: Int) { storage.set(level: level) - accountsRelay.accept(storage.accounts) - activeAccountRelay.accept(storage.activeAccount) + accountsSubject.send(storage.accounts) + activeAccountSubject.send(storage.activeAccount) } private func handleDisableDuress() { @@ -52,7 +48,7 @@ class AccountManager { } } - accountsRelay.accept(storage.accounts) + accountsSubject.send(storage.accounts) } private func clearAccounts(ids: [String]) { @@ -61,30 +57,30 @@ class AccountManager { } if storage.allAccounts.isEmpty { - accountsLostRelay.accept(true) + accountsLostSubject.send(true) } } } extension AccountManager { - var activeAccountObservable: Observable { - activeAccountRelay.asObservable() + var activeAccountPublisher: AnyPublisher { + activeAccountSubject.eraseToAnyPublisher() } - var accountsObservable: Observable<[Account]> { - accountsRelay.asObservable() + var accountsPublisher: AnyPublisher<[Account], Never> { + accountsSubject.eraseToAnyPublisher() } - var accountUpdatedObservable: Observable { - accountUpdatedRelay.asObservable() + var accountUpdatedPublisher: AnyPublisher { + accountUpdatedSubject.eraseToAnyPublisher() } - var accountDeletedObservable: Observable { - accountDeletedRelay.asObservable() + var accountDeletedPublisher: AnyPublisher { + accountDeletedSubject.eraseToAnyPublisher() } - var accountsLostObservable: Observable { - accountsLostRelay.asObservable() + var accountsLostPublisher: AnyPublisher { + accountsLostSubject.eraseToAnyPublisher() } var currentLevel: Int { @@ -101,7 +97,7 @@ extension AccountManager { } storage.set(activeAccountId: activeAccountId) - activeAccountRelay.accept(storage.activeAccount) + activeAccountSubject.send(storage.activeAccount) } var accounts: [Account] { @@ -115,14 +111,14 @@ extension AccountManager { func update(account: Account) { storage.save(account: account) - accountsRelay.accept(storage.accounts) - accountUpdatedRelay.accept(account) + accountsSubject.send(storage.accounts) + accountUpdatedSubject.send(account) } func save(account: Account) { storage.save(account: account) - accountsRelay.accept(storage.accounts) + accountsSubject.send(storage.accounts) set(activeAccountId: account.id) } @@ -132,7 +128,7 @@ extension AccountManager { storage.save(account: account) } - accountsRelay.accept(storage.accounts) + accountsSubject.send(storage.accounts) if let first = accounts.first { set(activeAccountId: first.id) } @@ -141,8 +137,8 @@ extension AccountManager { func delete(account: Account) { storage.delete(account: account) - accountsRelay.accept(storage.accounts) - accountDeletedRelay.accept(account) + accountsSubject.send(storage.accounts) + accountDeletedSubject.send(account) if account == storage.activeAccount { set(activeAccountId: storage.accounts.first?.id) @@ -152,7 +148,7 @@ extension AccountManager { func clear() { storage.clear() - accountsRelay.accept(storage.accounts) + accountsSubject.send(storage.accounts) set(activeAccountId: nil) } @@ -181,10 +177,10 @@ extension AccountManager { } for account in lostAccounts { - accountDeletedRelay.accept(account) + accountDeletedSubject.send(account) } - accountsRelay.accept(storage.accounts) + accountsSubject.send(storage.accounts) } func set(lastCreatedAccount: Account) { @@ -207,7 +203,7 @@ extension AccountManager { } } - accountsRelay.accept(storage.accounts) + accountsSubject.send(storage.accounts) } } diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountRestoreWarningManager.swift b/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountRestoreWarningManager.swift index 0b7c0889d4..f192e8c959 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountRestoreWarningManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountRestoreWarningManager.swift @@ -1,5 +1,5 @@ import Foundation -import RxSwift +import Combine class AccountRestoreWarningManager { private let accountManager: AccountManager @@ -16,18 +16,14 @@ extension AccountRestoreWarningManager { !accountManager.accounts.filter(\.nonStandard).isEmpty } - var hasNonStandardObservable: Observable { - accountManager.accountsObservable.map { !$0.filter(\.nonStandard).isEmpty } + var hasNonStandardPublisher: AnyPublisher { + accountManager.accountsPublisher.map { !$0.filter(\.nonStandard).isEmpty }.eraseToAnyPublisher() } var hasNonRecommended: Bool { !accountManager.accounts.filter(\.nonRecommended).isEmpty } - var hasNonRecommendedObservable: Observable { - accountManager.accountsObservable.map { !$0.filter(\.nonStandard).isEmpty } - } - func removeIgnoreWarning(account: Account) { userDefaultsStorage.set(value: nil as Bool?, for: AccountRestoreWarningFactory.keyAccountWarningPrefix + account.id) } diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Managers/BackupManager.swift b/UnstoppableWallet/UnstoppableWallet/Core/Managers/BackupManager.swift index d6f1b7c912..809c833b16 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Managers/BackupManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Managers/BackupManager.swift @@ -5,14 +5,16 @@ import RxSwift class BackupManager { private let accountManager: AccountManager - - private let disposeBag = DisposeBag() + private var cancellables = Set() private let allBackedUpRelay = PublishRelay() init(accountManager: AccountManager) { self.accountManager = accountManager - subscribe(disposeBag, accountManager.accountsObservable) { [weak self] _ in self?.updateAllBackedUp() } + + accountManager.accountsPublisher + .sink { [weak self] _ in self?.updateAllBackedUp() } + .store(in: &cancellables) } private func updateAllBackedUp() { diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Managers/WalletConnectSessionManager.swift b/UnstoppableWallet/UnstoppableWallet/Core/Managers/WalletConnectSessionManager.swift index 153fe599cf..f177b70f5b 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Managers/WalletConnectSessionManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Managers/WalletConnectSessionManager.swift @@ -1,3 +1,4 @@ +import Combine import MarketKit import RxCocoa import RxSwift @@ -6,6 +7,7 @@ import WalletConnectUtils class WalletConnectSessionManager { private let disposeBag = DisposeBag() + private var cancellables = Set() let service: WalletConnectService private let storage: WalletConnectSessionStorage @@ -24,12 +26,14 @@ class WalletConnectSessionManager { self.requestHandler = requestHandler self.currentDateProvider = currentDateProvider - subscribe(disposeBag, accountManager.accountDeletedObservable) { [weak self] in - self?.handleDeleted(account: $0) - } - subscribe(disposeBag, accountManager.activeAccountObservable) { [weak self] in - self?.handle(activeAccount: $0) - } + accountManager.activeAccountPublisher + .sink { [weak self] in self?.handle(activeAccount: $0) } + .store(in: &cancellables) + + accountManager.accountDeletedPublisher + .sink { [weak self] in self?.handleDeleted(account: $0) } + .store(in: &cancellables) + subscribe(disposeBag, service.sessionsUpdatedObservable) { [weak self] in self?.syncSessions() } diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Managers/WalletManager.swift b/UnstoppableWallet/UnstoppableWallet/Core/Managers/WalletManager.swift index fa993d5991..93eed2e9d1 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Managers/WalletManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Managers/WalletManager.swift @@ -1,3 +1,4 @@ +import Combine import Foundation import MarketKit import RxRelay @@ -6,7 +7,7 @@ import RxSwift class WalletManager { private let accountManager: AccountManager private let storage: WalletStorage - private let disposeBag = DisposeBag() + private var cancellables = Set() private let activeWalletDataRelay = PublishRelay() @@ -18,8 +19,13 @@ class WalletManager { self.accountManager = accountManager self.storage = storage - subscribe(disposeBag, accountManager.activeAccountObservable) { [weak self] _ in self?.reloadWallets() } - subscribe(disposeBag, accountManager.accountDeletedObservable) { [weak self] in self?.handleDelete(account: $0) } + accountManager.activeAccountPublisher + .sink { [weak self] _ in self?.reloadWallets() } + .store(in: &cancellables) + + accountManager.accountDeletedPublisher + .sink { [weak self] in self?.handleDelete(account: $0) } + .store(in: &cancellables) } private func handleDelete(account: Account) { diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Storage/CexAssetManager.swift b/UnstoppableWallet/UnstoppableWallet/Core/Storage/CexAssetManager.swift index 126f5d7e99..0d7abed8a4 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Storage/CexAssetManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Storage/CexAssetManager.swift @@ -1,20 +1,20 @@ +import Combine import MarketKit -import RxSwift class CexAssetManager { private let accountManager: AccountManager private let marketKit: MarketKit.Kit private let storage: CexAssetRecordStorage - private let disposeBag = DisposeBag() + private var cancellables = Set() init(accountManager: AccountManager, marketKit: MarketKit.Kit, storage: CexAssetRecordStorage) { self.accountManager = accountManager self.marketKit = marketKit self.storage = storage - subscribe(disposeBag, accountManager.accountDeletedObservable) { [weak self] account in - try? self?.storage.clear(accountId: account.id) - } + accountManager.accountDeletedPublisher + .sink { [weak self] account in try? self?.storage.clear(accountId: account.id) } + .store(in: &cancellables) } private func mapped(records: [CexAssetRecord]) throws -> [CexAsset] { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainBadgeService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainBadgeService.swift index ec1dfdf95f..3abe87b475 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainBadgeService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainBadgeService.swift @@ -24,13 +24,9 @@ class MainBadgeService { self.walletConnectSessionManager = walletConnectSessionManager self.contactBookManager = contactBookManager - accountRestoreWarningManager.hasNonStandardObservable - .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .background)) - .observeOn(ConcurrentDispatchQueueScheduler(qos: .background)) - .subscribe(onNext: { [weak self] _ in - self?.syncSettingsBadge() - }) - .disposed(by: disposeBag) + accountRestoreWarningManager.hasNonStandardPublisher + .sink { [weak self] _ in self?.syncSettingsBadge() } + .store(in: &cancellables) backupManager.allBackedUpObservable .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .background)) @@ -41,15 +37,11 @@ class MainBadgeService { .disposed(by: disposeBag) passcodeManager.$isPasscodeSet - .sink { [weak self] _ in - self?.syncSettingsBadge() - } + .sink { [weak self] _ in self?.syncSettingsBadge() } .store(in: &cancellables) termsManager.$termsAccepted - .sink { [weak self] _ in - self?.syncSettingsBadge() - } + .sink { [weak self] _ in self?.syncSettingsBadge() } .store(in: &cancellables) walletConnectSessionManager.activePendingRequestsObservable diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainService.swift index 0caa3a5c5c..8ed45014dc 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainService.swift @@ -1,3 +1,4 @@ +import Combine import Foundation import RxRelay import RxSwift @@ -13,6 +14,7 @@ class MainService { private let lockManager: LockManager private let presetTab: MainModule.Tab? private let disposeBag = DisposeBag() + private var cancellables = Set() private let hasAccountsRelay = PublishRelay() private(set) var hasAccounts: Bool = false { @@ -46,7 +48,10 @@ class MainService { self.lockManager = lockManager self.presetTab = presetTab - subscribe(disposeBag, accountManager.accountsObservable) { [weak self] in self?.sync(accounts: $0) } + accountManager.accountsPublisher + .sink { [weak self] in self?.sync(accounts: $0) } + .store(in: &cancellables) + subscribe(disposeBag, walletManager.activeWalletDataUpdatedObservable) { [weak self] in self?.sync(activeWallets: $0.wallets) } subscribe(disposeBag, launchScreenManager.showMarketObservable) { [weak self] in self?.sync(showMarket: $0) } subscribe(disposeBag, appManager.didBecomeActiveObservable) { [weak self] in self?.didBecomeActive() } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/ManageAccount/ManageAccountService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/ManageAccount/ManageAccountService.swift index 1b3e84fd3e..bc4338de7e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/ManageAccount/ManageAccountService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/ManageAccount/ManageAccountService.swift @@ -14,7 +14,6 @@ class ManageAccountService { private let accountManager: AccountManager private let cloudBackupManager: CloudBackupManager private let passcodeManager: PasscodeManager - private let disposeBag = DisposeBag() private var cancellables = Set() private let stateRelay = PublishRelay() @@ -41,13 +40,16 @@ class ManageAccountService { newName = account.name - subscribe(disposeBag, accountManager.accountUpdatedObservable) { [weak self] in self?.handleUpdated(account: $0) } - subscribe(disposeBag, accountManager.accountDeletedObservable) { [weak self] in self?.handleDeleted(account: $0) } + accountManager.accountUpdatedPublisher + .sink { [weak self] in self?.handleUpdated(account: $0) } + .store(in: &cancellables) + + accountManager.accountDeletedPublisher + .sink { [weak self] in self?.handleDeleted(account: $0) } + .store(in: &cancellables) cloudBackupManager.$oneWalletItems - .sink { [weak self] _ in - self?.cloudBackedUpRelay.accept(()) - } + .sink { [weak self] _ in self?.cloudBackedUpRelay.accept(()) } .store(in: &cancellables) syncState() diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/ManageAccounts/ManageAccountsService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/ManageAccounts/ManageAccountsService.swift index 246b92b61d..d033ef25bb 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/ManageAccounts/ManageAccountsService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/ManageAccounts/ManageAccountsService.swift @@ -5,7 +5,6 @@ import RxSwift class ManageAccountsService { private let accountManager: AccountManager private let cloudBackupManager: CloudBackupManager - private let disposeBag = DisposeBag() private var cancellables = Set() private let itemsRelay = PublishRelay<[Item]>() @@ -19,13 +18,16 @@ class ManageAccountsService { self.accountManager = accountManager self.cloudBackupManager = cloudBackupManager - subscribe(disposeBag, accountManager.accountsObservable) { [weak self] _ in self?.syncItems() } - subscribe(disposeBag, accountManager.activeAccountObservable) { [weak self] _ in self?.syncItems() } + accountManager.activeAccountPublisher + .sink { [weak self] _ in self?.syncItems() } + .store(in: &cancellables) + + accountManager.accountsPublisher + .sink { [weak self] _ in self?.syncItems() } + .store(in: &cancellables) cloudBackupManager.$oneWalletItems - .sink { [weak self] _ in - self?.syncItems() - } + .sink { [weak self] _ in self?.syncItems() } .store(in: &cancellables) syncItems() diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/ProFeatures/ProFeaturesAuthorizationManager.swift b/UnstoppableWallet/UnstoppableWallet/Modules/ProFeatures/ProFeaturesAuthorizationManager.swift index 5c72b4ce2e..58263cd08f 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/ProFeatures/ProFeaturesAuthorizationManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/ProFeatures/ProFeaturesAuthorizationManager.swift @@ -1,4 +1,5 @@ import BigInt +import Combine import EvmKit import HsExtensions import RxCocoa @@ -10,7 +11,7 @@ class ProFeaturesAuthorizationManager { static let contractAddress = try! EvmKit.Address(hex: "0x495f947276749ce646f68ac8c248420045cb7b5e") static let tokenId = BigUInt("77929411300911548602579223184347481465604416464327802926072149574722519040001", radix: 10)! - private let disposeBag = DisposeBag() + private var cancellables = Set() private let accountManager: AccountManager private let storage: ProFeaturesStorage @@ -23,7 +24,9 @@ class ProFeaturesAuthorizationManager { self.accountManager = accountManager self.evmSyncSourceManager = evmSyncSourceManager - subscribe(disposeBag, accountManager.accountDeletedObservable) { [weak self] in self?.sync(deletedAccount: $0) } + accountManager.accountDeletedPublisher + .sink { [weak self] in self?.sync(deletedAccount: $0) } + .store(in: &cancellables) } private func sync(deletedAccount: Account) { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Settings/Main/MainSettingsService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Settings/Main/MainSettingsService.swift index f9f8e5c890..0131cd8702 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Settings/Main/MainSettingsService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Settings/Main/MainSettingsService.swift @@ -5,6 +5,7 @@ import ThemeKit class MainSettingsService { private let disposeBag = DisposeBag() + private var cancellables = Set() private let backupManager: BackupManager private let cloudAccountBackupManager: CloudBackupManager @@ -47,7 +48,10 @@ class MainSettingsService { } subscribe(disposeBag, backupManager.allBackedUpObservable) { [weak self] _ in self?.syncWalletRequiredActions() } - subscribe(disposeBag, accountRestoreWarningManager.hasNonStandardObservable) { [weak self] _ in self?.syncWalletRequiredActions() } + + accountRestoreWarningManager.hasNonStandardPublisher + .sink { [weak self] _ in self?.syncWalletRequiredActions() } + .store(in: &cancellables) syncWalletRequiredActions() } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectManager.swift b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectManager.swift index 1815026e3f..6e004c7fc9 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectManager.swift @@ -11,6 +11,8 @@ import TweetNacl class TonConnectManager { private let apiClient: TonConnectAPI.Client private let storage: TonConnectStorage + private let accountManager: AccountManager + private var cancellables = Set() @PostPublished private(set) var tonConnectApps = [TonConnectApp]() @@ -19,7 +21,7 @@ class TonConnectManager { private let sendTransactionRequestSubject = PassthroughSubject() - init(storage: TonConnectStorage) { + init(storage: TonConnectStorage, accountManager: AccountManager) { let configuration = URLSessionConfiguration.default configuration.timeoutIntervalForRequest = TimeInterval(Int.max) configuration.timeoutIntervalForResource = TimeInterval(Int.max) @@ -31,10 +33,29 @@ class TonConnectManager { ) self.storage = storage + self.accountManager = accountManager + + accountManager.accountDeletedPublisher + .sink { [weak self] in self?.handleDeleted(account: $0) } + .store(in: &cancellables) syncTonConnectApps() } + private func handleDeleted(account: Account) { + let apps = tonConnectApps.filter { $0.accountId == account.id } + + guard !apps.isEmpty else { + return + } + + Task { [weak self] in + for app in apps { + try await self?.disconnect(tonConnectApp: app) + } + } + } + private func syncTonConnectApps() { do { tonConnectApps = try storage.tonConnectApps() diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/EnabledWalletCacheManager.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/EnabledWalletCacheManager.swift index 5da45da6e2..090f2dfc32 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/EnabledWalletCacheManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/EnabledWalletCacheManager.swift @@ -1,13 +1,15 @@ -import RxSwift +import Combine class EnabledWalletCacheManager { private let storage: EnabledWalletCacheStorage - private let disposeBag = DisposeBag() + private var cancellables = Set() init(storage: EnabledWalletCacheStorage, accountManager: AccountManager) { self.storage = storage - subscribe(disposeBag, accountManager.accountDeletedObservable) { [weak self] in self?.handleDelete(account: $0) } + accountManager.accountDeletedPublisher + .sink { [weak self] in self?.handleDelete(account: $0) } + .store(in: &cancellables) } private func handleDelete(account: Account) { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift index 0e4311ba87..41242cb697 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift @@ -106,20 +106,26 @@ class WalletService { sortType = .balance } - subscribe(disposeBag, accountManager.activeAccountObservable) { [weak self] in - self?.handleUpdated(activeAccount: $0) - } - subscribe(disposeBag, accountManager.accountUpdatedObservable) { [weak self] in - self?.handleUpdated(account: $0) - } - subscribe(disposeBag, accountManager.accountDeletedObservable) { [weak self] in - self?.handleDeleted(account: $0) - } - subscribe(disposeBag, accountManager.accountsLostObservable) { [weak self] isAccountsLost in - if isAccountsLost { - self?.accountsLostRelay.accept(()) + accountManager.activeAccountPublisher + .sink { [weak self] in self?.handleUpdated(activeAccount: $0) } + .store(in: &cancellables) + + accountManager.accountUpdatedPublisher + .sink { [weak self] in self?.handleUpdated(account: $0) } + .store(in: &cancellables) + + accountManager.accountDeletedPublisher + .sink { [weak self] in self?.handleDeleted(account: $0) } + .store(in: &cancellables) + + accountManager.accountsLostPublisher + .sink { [weak self] isAccountsLost in + if isAccountsLost { + self?.accountsLostRelay.accept(()) + } } - } + .store(in: &cancellables) + subscribe(disposeBag, appManager.willEnterForegroundObservable) { [weak self] in self?.coinPriceService.refresh() }