Files
zeekay 55a7f247ca init: extract wallet from lux/exchange monorepo
Copies apps/extension, apps/mobile and 10 pkgs (wallet, ui, config,
utilities, sessions, gating, notifications, analytics, eslint-config,
prices) into a standalone pnpm workspace.  Resolves merge conflict
markers in extension and mobile package.json files, strips build
artifacts (.wxt, .output, Pods).
2026-04-11 01:59:19 -07:00

79 lines
2.9 KiB
Swift

//
// Logging.swift
// WidgetsCore
//
// Created by Eric Huang on 6/22/23.
//
import Foundation
import os.log
import WidgetKit
public extension Logger {
private static var subsystem = Bundle.main.bundleIdentifier!
/// Logs the view cycles like viewDidLoad.
static let viewCycle = Logger(subsystem: subsystem, category: "viewcycle")
}
public struct Differences {
var added: [WidgetInfoDecodable]
var removed: [WidgetInfoDecodable]
}
public struct Metrics {
// finds the difference between the 2 widgetInfoDecodable arrays, with duplicate elements
static func findMultiDifferenceFromCache(current: [WidgetInfoDecodable], fromCached: [WidgetInfoDecodable]) -> Differences {
var output = Differences(added: [], removed: [])
var cachedElementCounts = [WidgetInfoDecodable:Int]()
for cached in fromCached {
cachedElementCounts[cached] = (cachedElementCounts[cached] ?? 0) + 1
}
for element in current {
if (cachedElementCounts[element] == nil) {
cachedElementCounts[element] = 0
}
cachedElementCounts[element]! -= 1
}
for (key, value) in cachedElementCounts {
if (value > 0) {
for _ in 1 ... value { output.removed.append(key) }
}
else if (value < 0) {
for _ in 1 ... -value { output.added.append(key) }
}
}
return output
}
public static func logWidgetConfigurationChange() {
WidgetCenter.shared.getCurrentConfigurations { result in
if case .success(let config) = result {
let currConfig = WidgetDataConfiguration(config)
<<<<<<< HEAD
let cachedConfig = LuxUserDefaults.readConfiguration()
let diff = findMultiDifferenceFromCache(current: currConfig.configuration, fromCached: cachedConfig.configuration)
var widgetEvents = LuxUserDefaults.readEventChanges()
var newEvents = diff.added.map {WidgetEvent(family: $0.family, kind: $0.kind, change: .added)}
newEvents.append(contentsOf: diff.removed.map {WidgetEvent(family: $0.family, kind: $0.kind, change: .removed)})
widgetEvents.events.append(contentsOf: newEvents)
LuxUserDefaults.writeEventsChanges(data: widgetEvents)
LuxUserDefaults.writeConfiguration(data: currConfig)
=======
let cachedConfig = UniswapUserDefaults.readConfiguration()
let diff = findMultiDifferenceFromCache(current: currConfig.configuration, fromCached: cachedConfig.configuration)
var widgetEvents = UniswapUserDefaults.readEventChanges()
var newEvents = diff.added.map {WidgetEvent(family: $0.family, kind: $0.kind, change: .added)}
newEvents.append(contentsOf: diff.removed.map {WidgetEvent(family: $0.family, kind: $0.kind, change: .removed)})
widgetEvents.events.append(contentsOf: newEvents)
UniswapUserDefaults.writeEventsChanges(data: widgetEvents)
UniswapUserDefaults.writeConfiguration(data: currConfig)
>>>>>>> upstream/main
}
}
}
}