Skip to content

Commit

Permalink
Techdebt/update ops data (#234)
Browse files Browse the repository at this point in the history
* ODR Debugging work

- Testing to make sure the 3 ops strings
- Debugging ON Demand
- Working version of the ODR
- Removed unused images
- Rename audio files
- When making the ODR the filenames with accents in the filename there are error
- Debugging the missing receive addressess

Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>

* Good progress….all transactions are showing now

Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>

* Fixed the layout issue with the transactions

On Demand Resources stub
/// Inspired by https://www.youtube.com/watch?v=B5RV8p4-9a8&t=178s
- Refactor
- Refactor tieredOps
- USD based fee
Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>

* Refactor to clean up

Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>

* Refactor for error messages

- added more test error messages
- removed unused File test file
- Added WIP NSPrivacyAccessedAPIType

Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>

---------

Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>
  • Loading branch information
kcw-grunt authored Mar 19, 2024
1 parent 04146e8 commit 1bb73a7
Show file tree
Hide file tree
Showing 137 changed files with 341 additions and 1,108 deletions.
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

0 comments on commit 1bb73a7

Please sign in to comment.