diff --git a/litewallet/AppDelegate.swift b/litewallet/AppDelegate.swift index 6e1ab70f..7e50c702 100644 --- a/litewallet/AppDelegate.swift +++ b/litewallet/AppDelegate.swift @@ -41,9 +41,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { LWAnalytics.logEventWithParameters(itemName: ._20231202_RIGI, properties: interestsDict) - - applicationController.registerBGProcess() - } onFailure: { error in let properties: [String: String] = ["error_type": "on_demand_resources_not_found", @@ -118,11 +115,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Load a Firebase debug config file. // let filePath = Bundle.main.path(forResource: "Debug-GoogleService-Info", ofType: "plist") - let filePath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist") + guard let filePath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist") else { + let properties = ["error_message": "gs_info_file_missing"] + LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, + properties: properties) + assertionFailure("Couldn't load google services file") + return + } - if let fboptions = FirebaseOptions(contentsOfFile: filePath!) { + if let fboptions = FirebaseOptions(contentsOfFile: filePath) { FirebaseApp.configure(options: fboptions) } else { + let properties = ["error_message": "firebase_config_failed"] + LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, + properties: properties) assertionFailure("Couldn't load Firebase config file") } } diff --git a/litewallet/ApplicationController.swift b/litewallet/ApplicationController.swift index b0022d5e..2001322f 100644 --- a/litewallet/ApplicationController.swift +++ b/litewallet/ApplicationController.swift @@ -102,42 +102,6 @@ class ApplicationController: Subscriber, Trackable { TransactionManager.sharedInstance.fetchTransactionData(store: store) } - func registerBGProcess() { - /// Register for Backgroud Tasks - BGTaskScheduler.shared.register( - forTaskWithIdentifier: LWBGTaskidentifier.fetch.rawValue, - using: nil - ) { task in - self.handleAppRefreshTask(task: task as! BGAppRefreshTask) - } - } - - func handleAppRefreshTask(task: BGAppRefreshTask) { - task.expirationHandler = { [weak self] in - self?.willEnterForeground() - task.setTaskCompleted(success: false) - } - didEnterBackground() - task.setTaskCompleted(success: true) - - scheduleBackgroundChainandFiatDataFetch() - } - - func scheduleBackgroundChainandFiatDataFetch() { - let litewalletFetchTask = BGAppRefreshTaskRequest(identifier: LWBGTaskidentifier.fetch.rawValue - ) - litewalletFetchTask.earliestBeginDate = Date(timeIntervalSinceNow: 60) - do { - try BGTaskScheduler.shared.submit(litewalletFetchTask) - let properties = ["application_info": "bgtaskscheduler_started"] - LWAnalytics.logEventWithParameters(itemName: ._20240315_AI, properties: properties) - } catch { - let properties = ["error": "unable_to_submit_task", - "error_message": "\(error.localizedDescription)"] - LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, properties: properties) - } - } - func willEnterForeground() { guard let walletManager = walletManager else { return } guard !walletManager.noWallet else { return } @@ -277,18 +241,22 @@ class ApplicationController: Subscriber, Trackable { private func initKVStoreCoordinator() { guard let kvStore = walletManager?.apiClient?.kv else { - NSLog("kvStore not initialized") + let properties = ["applications_info": "kvstore_not_initialized"] + LWAnalytics.logEventWithParameters(itemName: ._20240315_AI, properties: properties) return } guard kvStoreCoordinator == nil else { - NSLog("kvStoreCoordinator not initialized") + let properties = ["applications_info": "kvstorecoordinator_not_initialized"] + LWAnalytics.logEventWithParameters(itemName: ._20240315_AI, properties: properties) return } kvStore.syncAllKeys { error in - print("KV finished syncing. err: \(String(describing: error))") + let properties = ["error_message": "kv_finished_syning", + "error": "\(String(describing: error))"] + LWAnalytics.logEventWithParameters(itemName: ._20240315_AI, properties: properties) self.walletCoordinator?.kvStore = kvStore self.kvStoreCoordinator = KVStoreCoordinator(store: self.store, kvStore: kvStore) self.kvStoreCoordinator?.retreiveStoredWalletInfo() diff --git a/litewallet/WalletCoordinator.swift b/litewallet/WalletCoordinator.swift index 75349ac9..be250468 100644 --- a/litewallet/WalletCoordinator.swift +++ b/litewallet/WalletCoordinator.swift @@ -119,15 +119,16 @@ class WalletCoordinator: Subscriber, Trackable { @objc private func updateTransactions() { updateTimer?.invalidate() updateTimer = nil - DispatchQueue.walletQueue.async { + Task { guard let txRefs = self.walletManager.wallet?.transactions else { let properties = ["error_message": "wallet_tx_refs_are_nil"] LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, properties: properties) return } - let transactions = self.makeTransactionViewModels(transactions: txRefs, walletManager: self.walletManager, kvStore: self.kvStore, rate: self.store.state.currentRate) + + let transactions = await self.makeTransactionViewModels(transactions: txRefs, walletManager: self.walletManager, kvStore: self.kvStore, rate: self.store.state.currentRate) if !transactions.isEmpty { - DispatchQueue.main.async { + Task { self.store.perform(action: WalletChange.setTransactions(transactions)) } } else { @@ -137,7 +138,7 @@ class WalletCoordinator: Subscriber, Trackable { } } - func makeTransactionViewModels(transactions: [BRTxRef?], walletManager: WalletManager, kvStore: BRReplicatedKVStore?, rate: Rate?) -> [Transaction] + func makeTransactionViewModels(transactions: [BRTxRef?], walletManager: WalletManager, kvStore: BRReplicatedKVStore?, rate: Rate?) async -> [Transaction] { /// Send analytical data for any nils in this method if kvStore == nil {