Skip to content

Commit

Permalink
🚀[Release v3.13.1-20240322.0] Merge into Develop #235 (#236)
Browse files Browse the repository at this point in the history
* removed registerBG

Added more error messages

Signed-off-by: kcw-grunt <[email protected]>

* Converted DispatchQueue to Task method

- bump version

Signed-off-by: kcw-grunt <[email protected]>

---------

Signed-off-by: kcw-grunt <[email protected]>
  • Loading branch information
kcw-grunt committed Apr 2, 2024
1 parent 1bb73a7 commit 9038d6e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 48 deletions.
16 changes: 11 additions & 5 deletions litewallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
}
}
Expand Down
46 changes: 7 additions & 39 deletions litewallet/ApplicationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 5 additions & 4 deletions litewallet/WalletCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 9038d6e

Please sign in to comment.