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

Bugfix/general maintenance #238

Merged
merged 3 commits into from
May 11, 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
12 changes: 6 additions & 6 deletions litewallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4534,7 +4534,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = litewallet/litewallet.entitlements;
CURRENT_PROJECT_VERSION = 240509.1;
CURRENT_PROJECT_VERSION = 240511.0;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = ZV7987N2ZC;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
Expand All @@ -4550,7 +4550,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.13.3;
MARKETING_VERSION = 3.13.4;
ONLY_ACTIVE_ARCH = YES;
ON_DEMAND_RESOURCES_INITIAL_INSTALL_TAGS = "initial-resources speakTag";
OTHER_SWIFT_FLAGS = "-DDebug $(inherited)";
Expand Down Expand Up @@ -4891,7 +4891,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = litewallet/litewallet.entitlements;
CURRENT_PROJECT_VERSION = 240509.1;
CURRENT_PROJECT_VERSION = 240511.0;
DEVELOPMENT_TEAM = ZV7987N2ZC;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -4906,7 +4906,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.13.3;
MARKETING_VERSION = 3.13.4;
ONLY_ACTIVE_ARCH = YES;
ON_DEMAND_RESOURCES_INITIAL_INSTALL_TAGS = "initial-resources speakTag";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down Expand Up @@ -5032,7 +5032,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = litewallet/litewallet.entitlements;
CURRENT_PROJECT_VERSION = 240509.1;
CURRENT_PROJECT_VERSION = 240511.0;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = ZV7987N2ZC;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = NO;
Expand All @@ -5048,7 +5048,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.13.3;
MARKETING_VERSION = 3.13.4;
ONLY_ACTIVE_ARCH = YES;
ON_DEMAND_RESOURCES_INITIAL_INSTALL_TAGS = "initial-resources speakTag";
OTHER_SWIFT_FLAGS = "-DDebug -DTestnet $(inherited)";
Expand Down
37 changes: 29 additions & 8 deletions litewallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
requestResourceWith(tag: ["initial-resources", "speakTag"]) { [self] in

// Language
updateCurrentUserLocale(localeId: Locale.current.identifier)
Bundle.setLanguage(UserDefaults.selectedLanguage)

// Ops
let startDate = Partner.partnerKeyPath(name: .litewalletStart)
if startDate == "error-litewallet-start-key" {
Expand All @@ -24,14 +29,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
self.setFirebaseConfiguration()

// Pusher
self.pushNotifications.start(instanceId: Partner.partnerKeyPath(name: .pusherStaging))
let generaliOSInterest = "general-ios"
let debugGeneraliOSInterest = "debug-general-ios"
self.pushNotifications.start(instanceId: Partner.partnerKeyPath(name: .pusher))
let generalInterest = String.preferredLanguageInterest(currentId: UserDefaults.selectedLanguage)
let debugGeneralInterest = "debug-general"

try? self.pushNotifications.clearDeviceInterests()

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

let interests = self.pushNotifications.getDeviceInterests()?.joined(separator: "|") ?? ""
let device = UIDevice.current.identifierForVendor?.uuidString ?? "ID"
Expand All @@ -40,14 +47,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

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

let current = UNUserNotificationCenter.current()

current.getNotificationSettings(completionHandler: { settings in

debugPrint(settings.debugDescription)
if settings.authorizationStatus == .denied {
self.pushNotifications.clearAllState {
LWAnalytics.logEventWithParameters(itemName: ._20240506_DPN)
}

self.pushNotifications.stop {
LWAnalytics.logEventWithParameters(itemName: ._20240510_SPN)
}
}
})

} 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 @@ -59,8 +82,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

LWAnalytics.logEventWithParameters(itemName: ._20191105_AL)

Bundle.setLanguage(UserDefaults.selectedLanguage)

return true
}

Expand Down
16 changes: 8 additions & 8 deletions litewallet/ApplicationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ApplicationController: Subscriber, Trackable {
}
exchangeUpdater?.refresh(completion: {})
feeUpdater?.refresh()
walletManager.apiClient?.kv?.syncAllKeys { print("KV finished syncing. err: \(String(describing: $0))") }
// walletManager.apiClient?.kv?.syncAllKeys { print("KV finished syncing. err: \(String(describing: $0))") }
if modalPresenter?.walletManager == nil {
modalPresenter?.walletManager = walletManager
}
Expand All @@ -127,7 +127,7 @@ class ApplicationController: Subscriber, Trackable {
}
exchangeUpdater?.refresh(completion: {})
feeUpdater?.refresh()
walletManager.apiClient?.kv?.syncAllKeys { print("KV finished syncing. err: \(String(describing: $0))") }
// walletManager.apiClient?.kv?.syncAllKeys { print("KV finished syncing. err: \(String(describing: $0))") }
if modalPresenter?.walletManager == nil {
modalPresenter?.walletManager = walletManager
}
Expand All @@ -143,7 +143,7 @@ class ApplicationController: Subscriber, Trackable {
if !store.state.isLoginRequired {
UserDefaults.standard.set(Date().timeIntervalSince1970, forKey: timeSinceLastExitKey)
}
walletManager?.apiClient?.kv?.syncAllKeys { print("KV finished syncing. err: \(String(describing: $0))") }
// walletManager?.apiClient?.kv?.syncAllKeys { print("KV finished syncing. err: \(String(describing: $0))") }
}

func performFetch(_ completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Expand All @@ -169,7 +169,9 @@ class ApplicationController: Subscriber, Trackable {
walletCoordinator = WalletCoordinator(walletManager: walletManager, store: store)
modalPresenter = ModalPresenter(store: store, walletManager: walletManager, window: window, apiClient: noAuthApiClient)
exchangeUpdater = ExchangeUpdater(store: store, walletManager: walletManager)
feeUpdater = FeeUpdater(walletManager: walletManager, store: store)

guard let exchangeUpdaterWithFee = exchangeUpdater else { return }
feeUpdater = FeeUpdater(walletManager: walletManager, store: store, exchangeUpdater: exchangeUpdaterWithFee)
startFlowController = StartFlowPresenter(store: store, walletManager: walletManager, rootViewController: rootViewController)
mainViewController?.walletManager = walletManager
defaultsUpdater = UserDefaultsUpdater(walletManager: walletManager)
Expand Down Expand Up @@ -225,9 +227,7 @@ class ApplicationController: Subscriber, Trackable {
defaultsUpdater?.refresh()
walletManager?.apiClient?.events?.up()

exchangeUpdater?.refresh(completion: {
NSLog("::: Refreshed fiat rates")
})
exchangeUpdater?.refresh(completion: {})
}

private func addWalletCreationListener() {
Expand Down Expand Up @@ -265,7 +265,7 @@ class ApplicationController: Subscriber, Trackable {
}

private func offMainInitialization() {
DispatchQueue.global(qos: .background).async {
Task(priority: .background) {
_ = Rate.symbolMap // Initialize currency symbol map
}
}
Expand Down
15 changes: 11 additions & 4 deletions litewallet/BRAPIClient+Wallet.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Foundation

private let fallbackRatesURL = "https://api.loshan.co.uk/api/v1/rates"
private let fallbackRatesURL = "https://api-dev.lite-wallet.org/v1/rates"

extension BRAPIClient {
func feePerKb(_ handler: @escaping (_ fees: Fees, _ error: String?) -> Void) {
let req = URLRequest(url: url("/fee-per-kb"))
let task = dataTaskWithRequest(req) { _, _, _ in
// TODO: Refactor when mobile-api v0.4.0 is in prod
let staticFees = Fees.usingDefaultValues
handler(staticFees, nil)
}
Expand All @@ -15,27 +14,35 @@ extension BRAPIClient {

func exchangeRates(isFallback: Bool = false, _ handler: @escaping (_ rates: [Rate], _ error: String?) -> Void) {
let request = isFallback ? URLRequest(url: URL(string: fallbackRatesURL)!) : URLRequest(url: URL(string: APIServer.baseUrl + "v1/rates")!)
_ = dataTaskWithRequest(request) { data, _, error in
dataTaskWithRequest(request) { data, _, error in
if error == nil, let data = data,
let parsedData = try? JSONSerialization.jsonObject(with: data, options: .allowFragments)
{
if isFallback {
guard let array = parsedData as? [Any]
else {
return handler([], "/rates didn't return an array")
let properties = ["error_message": "is_fallback_no_rate_array_returned"]
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, properties: properties)
return handler([], "::: /rates didn't return an array")
}
handler(array.compactMap { Rate(data: $0) }, nil)
} else {
guard let array = parsedData as? [Any]
else {
let properties = ["error_message": "is_fallback_parsed_data_fail"]
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, properties: properties)
return handler([], "/rates didn't return an array")
}
handler(array.compactMap { Rate(data: $0) }, nil)
}
} else {
if isFallback {
let properties: [String: String] = ["error_message": "is_fallback_no_rate_array_returned"]
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, properties: properties)
handler([], "Error fetching from fallback url")
} else {
let properties: [String: String] = ["error_message": "is_fallback"]
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, properties: properties)
self.exchangeRates(isFallback: true, handler)
}
}
Expand Down
7 changes: 0 additions & 7 deletions litewallet/BRPeerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ class BRPeerManager {
return BRPeerManagerEstimatedBlockHeight(cPtr)
}

// Only show syncing view if more than 2 days behind
var shouldShowSyncingView: Bool {
let lastBlock = Date(timeIntervalSince1970: TimeInterval(lastBlockTimestamp))
let cutoff = Date().addingTimeInterval(-24 * 60 * 60 * 2) // 2 days ago
return lastBlock.compare(cutoff) == .orderedAscending
}

// current network sync progress from 0 to 1
// startHeight is the block height of the most recent fully completed sync
func syncProgress(fromStartHeight: UInt32) -> Double {
Expand Down
12 changes: 10 additions & 2 deletions litewallet/BundleExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ public extension Bundle {
object_setClass(Bundle.main, BundleEx.self as AnyClass)
}

if let temp = language {
guard let bundle = Bundle(path: Bundle.main.path(forResource: temp, ofType: "lproj")!) else {
if var temp = language {
if temp == "zh" {
temp = "zh-Hans"
}

guard let path = Bundle.main.path(forResource: temp, ofType: "lproj") else {
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR)
return
}
guard let bundle = Bundle(path: path) else {
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR)
return
}
Expand Down
6 changes: 6 additions & 0 deletions litewallet/Constants/Constants+Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,10 @@ enum CustomEvent: String {

/// Transactions info
case _20240315_AI = "application_info"

/// Disabled Push Notifications
case _20240506_DPN = "disabled_push_notifications"

/// Stop Push Notifications
case _20240510_SPN = "stopped_push_notifications"
}
5 changes: 4 additions & 1 deletion litewallet/Currency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import UIKit

class Currency {
class func getSymbolForCurrencyCode(code: String) -> String? {
let result = Locale.availableIdentifiers.map { Locale(identifier: $0) }.first { $0.currencyCode == code }
print(" ::: \(code)")
let result = Locale.availableIdentifiers.map {
Locale(identifier: $0)
}.first { $0.currencyCode == code }
return result?.currencySymbol
}
}
Expand Down
33 changes: 33 additions & 0 deletions litewallet/Extensions/String+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,39 @@ extension String {
}
}

// MARK: - Language code String

extension String {
/// 14 Languages
/// Locale.current.identifier)
static func preferredLanguageInterest(currentId: String) -> String {
var codeId = ""
if (currentId == "zh_CN") || (currentId == "zh_SG") {
return "general-chinese-simplified"
} else if (currentId == "zh_TW") || (currentId == "zh_HK") {
return "general-chinese-traditional"
} else {
codeId = String(currentId.suffix(2))
}

switch codeId {
case "en": return "general-english"
case "fr": return "general-french"
case "de": return "general-german"
case "id": return "general-indonesian"
case "it": return "general-italian"
case "ja": return "general-japanese"
case "ko": return "general-korean"
case "pt": return "general-portuguese"
case "ru": return "general-russian"
case "es": return "general-spanish"
case "tr": return "general-turkish"
case "uk": return "general-ukrainian"
default: return "general-english"
}
}
}

extension UnicodeScalar {
var nibble: UInt8? {
if value >= 48, value <= 57 {
Expand Down
10 changes: 8 additions & 2 deletions litewallet/FeeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ class FeeUpdater: Trackable {

private let maxFeePerKB = Fees.usingDefaultValues.luxury
private var timer: Timer?
private let feeUpdateInterval: TimeInterval = 15 // meet Nyquist for api server interval (30)
private let feeUpdateInterval: TimeInterval = 3
private var exchangeUpdater: ExchangeUpdater

// MARK: - Public

init(walletManager: WalletManager, store: Store) {
init(walletManager: WalletManager, store: Store, exchangeUpdater: ExchangeUpdater) {
self.walletManager = walletManager
self.store = store
self.exchangeUpdater = exchangeUpdater
}

func refresh(completion: @escaping () -> Void) {
Expand Down Expand Up @@ -79,5 +81,9 @@ class FeeUpdater: Trackable {

@objc func intervalRefresh() {
refresh(completion: {})
exchangeUpdater.refresh(completion: {
/// DEV: For testing
/// NSLog("::: Rate updated")
})
}
}
Loading