Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Techdebt/update ops data #234

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ Modules/litewallet-partner-api-ios
litewallet-partner-api-ios
/partner-keys.plist
partner-keys.plist
GoogleService-Info.plist
95 changes: 75 additions & 20 deletions litewallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,48 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let applicationController = ApplicationController()
let pushNotifications = PushNotifications.shared

var resourceRequest: NSBundleResourceRequest?

func application(_ application: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
setFirebaseConfiguration()

requestResourceWith(tag: ["initial-resources", "speakTag"]) { [self] in
// Ops
let startDate = Partner.partnerKeyPath(name: .litewalletStart)
if startDate == "error-litewallet-start-key" {
let errorDescription = "partnerkey_data_missing"
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, properties: ["error": errorDescription])
}
// Firebase
self.setFirebaseConfiguration()

// Pusher
self.pushNotifications.start(instanceId: Partner.partnerKeyPath(name: .pusherStaging))
let generaliOSInterest = "general-ios"
let debugGeneraliOSInterest = "debug-general-ios"

try? self.pushNotifications
.addDeviceInterest(interest: generaliOSInterest)
try? self.pushNotifications
.addDeviceInterest(interest: debugGeneraliOSInterest)

let interests = self.pushNotifications.getDeviceInterests()?.joined(separator: "|") ?? ""
let device = UIDevice.current.identifierForVendor?.uuidString ?? "ID"
let interestsDict: [String: String] = ["device_id": device,
"pusher_interests": interests]

LWAnalytics.logEventWithParameters(itemName: ._20231202_RIGI,
properties: interestsDict)

applicationController.registerBGProcess()

} onFailure: { error in

let properties: [String: String] = ["error_type": "on_demand_resources_not_found",
"error_description": "\(error.debugDescription)"]
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR,
properties: properties)
}
updateCurrentUserLocale(localeId: Locale.current.identifier)

guard let thisWindow = window else { return false }
Expand All @@ -27,24 +65,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

Bundle.setLanguage(UserDefaults.selectedLanguage)

// Pusher
pushNotifications.start(instanceId: Partner.partnerKeyPath(name: .pusherStaging))
// pushNotifications.registerForRemoteNotifications()
let generaliOSInterest = "general-ios"
let debugGeneraliOSInterest = "debug-general-ios"

try? pushNotifications
.addDeviceInterest(interest: generaliOSInterest)
try? pushNotifications
.addDeviceInterest(interest: debugGeneraliOSInterest)

let interests = pushNotifications.getDeviceInterests()?.joined(separator: "|") ?? ""
let device = UIDevice.current.identifierForVendor?.uuidString ?? "ID"
let interestesDict: [String: String] = ["device_id": device,
"pusher_interests": interests]

LWAnalytics.logEventWithParameters(itemName: ._20231202_RIGI, properties: interestesDict)

return true
}

Expand Down Expand Up @@ -117,4 +137,39 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
UserDefaults.userIsInUSA = false
}
}

/// On Demand Resources
/// Use for another resource heavy view
/// Inspired by https://www.youtube.com/watch?v=B5RV8p4-9a8&t=178s
func requestResourceWith(tag: [String],
onSuccess: @escaping () -> Void,
onFailure _: @escaping (NSError) -> Void)
{
resourceRequest = NSBundleResourceRequest(tags: Set(tag))

guard let request = resourceRequest else { return }

request.endAccessingResources()
request.loadingPriority = NSBundleResourceRequestLoadingPriorityUrgent
request.conditionallyBeginAccessingResources { areResourcesAvailable in

DispatchQueue.main.async {
if !areResourcesAvailable {
request.beginAccessingResources { error in
guard error != nil else {
let properties: [String: String] = ["error_type": "on_demand_resources_not_found",
"error_description": "\(error.debugDescription)"]
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR,
properties: properties)

return
}
onSuccess()
}
} else {
onSuccess()
}
}
}
}
}
45 changes: 39 additions & 6 deletions litewallet/ApplicationController.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BackgroundTasks
import StoreKit
import UIKit

Expand Down Expand Up @@ -55,7 +56,6 @@ class ApplicationController: Subscriber, Trackable {
func launch(application: UIApplication, window: UIWindow?) {
self.application = application
self.window = window
application.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
setup()
reachability.didChange = { isReachable in
if !isReachable {
Expand Down Expand Up @@ -102,6 +102,42 @@ 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 All @@ -114,7 +150,6 @@ class ApplicationController: Subscriber, Trackable {
exchangeUpdater?.refresh(completion: {})
feeUpdater?.refresh()
walletManager.apiClient?.kv?.syncAllKeys { print("KV finished syncing. err: \(String(describing: $0))") }
walletManager.apiClient?.updateFeatureFlags()
if modalPresenter?.walletManager == nil {
modalPresenter?.walletManager = walletManager
}
Expand All @@ -129,7 +164,6 @@ class ApplicationController: Subscriber, Trackable {
exchangeUpdater?.refresh(completion: {})
feeUpdater?.refresh()
walletManager.apiClient?.kv?.syncAllKeys { print("KV finished syncing. err: \(String(describing: $0))") }
walletManager.apiClient?.updateFeatureFlags()
if modalPresenter?.walletManager == nil {
modalPresenter?.walletManager = walletManager
}
Expand Down Expand Up @@ -203,7 +237,8 @@ class ApplicationController: Subscriber, Trackable {
}

exchangeUpdater?.refresh(completion: {
NSLog("Rates were updated")
let properties = ["application_controller": "rate_was_updated"]
LWAnalytics.logEventWithParameters(itemName: ._20240315_AI, properties: properties)
})
}
}
Expand All @@ -221,7 +256,6 @@ class ApplicationController: Subscriber, Trackable {
}

private func startDataFetchers() {
walletManager?.apiClient?.updateFeatureFlags()
initKVStoreCoordinator()
feeUpdater?.refresh()
defaultsUpdater?.refresh()
Expand Down Expand Up @@ -298,7 +332,6 @@ class ApplicationController: Subscriber, Trackable {
{ self.exchangeUpdater?.refresh(completion: $0) },
{ self.feeUpdater?.refresh(completion: $0) },
{ self.walletManager?.apiClient?.events?.sync(completion: $0) },
{ self.walletManager?.apiClient?.updateFeatureFlags(); $0() },
], completion: {
LWAnalytics.logEventWithParameters(itemName: ._20200111_DLDG)
group.leave()
Expand Down
21 changes: 0 additions & 21 deletions litewallet/Assets.xcassets/Branding/Logo.imageset/Contents.json

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
Loading