Skip to content

Commit 3aa99cb

Browse files
committed
fix comments
1 parent 9de7488 commit 3aa99cb

9 files changed

Lines changed: 73 additions & 57 deletions

File tree

Bitkit/AppScene.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct AppScene: View {
2525
@StateObject private var transferTracking: TransferTrackingManager
2626
@StateObject private var channelDetails = ChannelDetailsViewModel.shared
2727
@StateObject private var migrations = MigrationsService.shared
28-
@StateObject private var pubkyProfile = PubkyProfileManager()
28+
@State private var pubkyProfile = PubkyProfileManager()
2929

3030
@State private var hideSplash = false
3131
@State private var removeSplash = false
@@ -121,7 +121,7 @@ struct AppScene: View {
121121
.environmentObject(tagManager)
122122
.environmentObject(transferTracking)
123123
.environmentObject(channelDetails)
124-
.environmentObject(pubkyProfile)
124+
.environment(pubkyProfile)
125125
.onAppear {
126126
if !settings.pinEnabled {
127127
isPinVerified = true

Bitkit/Components/Header.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SwiftUI
33
struct Header: View {
44
@EnvironmentObject var app: AppViewModel
55
@EnvironmentObject var navigation: NavigationViewModel
6-
@EnvironmentObject var pubkyProfile: PubkyProfileManager
6+
@Environment(PubkyProfileManager.self) var pubkyProfile
77

88
var body: some View {
99
HStack(alignment: .center, spacing: 0) {

Bitkit/Components/Home/Suggestions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct Suggestions: View {
138138
@EnvironmentObject var sheets: SheetViewModel
139139
@EnvironmentObject var settings: SettingsViewModel
140140
@EnvironmentObject var suggestionsManager: SuggestionsManager
141-
@EnvironmentObject var pubkyProfile: PubkyProfileManager
141+
@Environment(PubkyProfileManager.self) var pubkyProfile
142142

143143
@State private var showShareSheet = false
144144
/// Prevent duplicate item taps when the card is dismissed
@@ -282,6 +282,6 @@ struct Suggestions: View {
282282
.environmentObject(SheetViewModel())
283283
.environmentObject(SettingsViewModel.shared)
284284
.environmentObject(SuggestionsManager())
285-
.environmentObject(PubkyProfileManager())
285+
.environment(PubkyProfileManager())
286286
.preferredColorScheme(.dark)
287287
}

Bitkit/MainNavView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct MainNavView: View {
55
@EnvironmentObject private var currency: CurrencyViewModel
66
@EnvironmentObject private var navigation: NavigationViewModel
77
@EnvironmentObject private var notificationManager: PushNotificationManager
8-
@EnvironmentObject private var pubkyProfile: PubkyProfileManager
8+
@Environment(PubkyProfileManager.self) private var pubkyProfile
99
@EnvironmentObject private var settings: SettingsViewModel
1010
@EnvironmentObject private var sheets: SheetViewModel
1111
@EnvironmentObject private var wallet: WalletViewModel

Bitkit/Managers/PubkyProfileManager.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import Observation
23
import SwiftUI
34

45
enum PubkyAuthState: Equatable {
@@ -9,14 +10,15 @@ enum PubkyAuthState: Equatable {
910
}
1011

1112
@MainActor
12-
class PubkyProfileManager: ObservableObject {
13-
@Published var authState: PubkyAuthState = .idle
14-
@Published var profile: PubkyProfile?
15-
@Published var publicKey: String?
16-
@Published var isLoadingProfile = false
17-
@Published var isInitialized = false
18-
@Published private(set) var cachedName: String?
19-
@Published private(set) var cachedImageUri: String?
13+
@Observable
14+
class PubkyProfileManager {
15+
var authState: PubkyAuthState = .idle
16+
var profile: PubkyProfile?
17+
var publicKey: String?
18+
var isLoadingProfile = false
19+
var isInitialized = false
20+
private(set) var cachedName: String?
21+
private(set) var cachedImageUri: String?
2022

2123
init() {
2224
cachedName = UserDefaults.standard.string(forKey: Self.cachedNameKey)
@@ -150,9 +152,9 @@ class PubkyProfileManager: ObservableObject {
150152

151153
do {
152154
let loadedProfile = try await Task.detached {
153-
let ffiProfile = try await PubkyService.getProfile(publicKey: pk)
154-
Logger.debug("Profile loaded — name: \(ffiProfile.name), image: \(ffiProfile.image ?? "nil")", context: "PubkyProfileManager")
155-
return PubkyProfile(publicKey: pk, ffiProfile: ffiProfile)
155+
let profileDto = try await PubkyService.getProfile(publicKey: pk)
156+
Logger.debug("Profile loaded — name: \(profileDto.name), image: \(profileDto.image ?? "nil")", context: "PubkyProfileManager")
157+
return PubkyProfile(publicKey: pk, ffiProfile: profileDto)
156158
}.value
157159
profile = loadedProfile
158160
cacheProfileMetadata(loadedProfile)
@@ -189,13 +191,11 @@ class PubkyProfileManager: ObservableObject {
189191
private static let cachedImageUriKey = "pubky_profile_image_uri"
190192

191193
var displayName: String? {
192-
guard isAuthenticated else { return nil }
193-
return profile?.name ?? cachedName
194+
profile?.name ?? cachedName
194195
}
195196

196197
var displayImageUri: String? {
197-
guard isAuthenticated else { return nil }
198-
return profile?.imageUrl ?? cachedImageUri
198+
profile?.imageUrl ?? cachedImageUri
199199
}
200200

201201
private func cacheProfileMetadata(_ profile: PubkyProfile) {

Bitkit/Services/PubkyService.swift

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,24 @@ enum PubkyService {
3030
static let requiredCapabilities = "/pub/paykit.app/v0/:rw,/pub/pubky.app/profile.json:rw,/pub/pubky.app/follows/:rw"
3131

3232
static func initialize() async throws {
33-
try await paykitInitialize()
33+
try await ServiceQueue.background(.core) {
34+
try await paykitInitialize()
35+
}
3436
}
3537

3638
// MARK: - Session Management
3739

3840
/// Import a session secret into paykit and return the public key.
3941
static func importSession(secret: String) async throws -> String {
40-
try await paykitImportSession(sessionSecret: secret)
42+
try await ServiceQueue.background(.core) {
43+
try await paykitImportSession(sessionSecret: secret)
44+
}
4145
}
4246

4347
static func exportSession() async throws -> String {
44-
try await paykitExportSession()
48+
try await ServiceQueue.background(.core) {
49+
try await paykitExportSession()
50+
}
4551
}
4652

4753
static func isAuthenticated() async -> Bool {
@@ -56,61 +62,83 @@ enum PubkyService {
5662

5763
/// Step 1: Generate the pubkyauth:// URL to open in Pubky Ring.
5864
static func startAuth() async throws -> String {
59-
try await startPubkyAuth(caps: requiredCapabilities)
65+
try await ServiceQueue.background(.core) {
66+
try await startPubkyAuth(caps: requiredCapabilities)
67+
}
6068
}
6169

6270
/// Step 2: Long-poll until Ring approves. Returns the raw session secret.
6371
static func completeAuth() async throws -> String {
64-
try await completePubkyAuth()
72+
try await ServiceQueue.background(.core) {
73+
try await completePubkyAuth()
74+
}
6575
}
6676

6777
/// Cancel an in-progress auth relay poll started by `startAuth`.
6878
static func cancelAuth() async throws {
69-
try await cancelPubkyAuth()
79+
try await ServiceQueue.background(.core) {
80+
try await cancelPubkyAuth()
81+
}
7082
}
7183

7284
// MARK: - File Fetching
7385

7486
/// Fetch raw bytes from a `pubky://` URI via PKDNS resolution.
7587
static func fetchFile(uri: String) async throws -> Data {
76-
let bytes = try await fetchPubkyFile(uri: uri)
77-
return Data(bytes)
88+
try await ServiceQueue.background(.core) {
89+
let bytes = try await fetchPubkyFile(uri: uri)
90+
return Data(bytes)
91+
}
7892
}
7993

8094
// MARK: - Profile
8195

8296
static func getProfile(publicKey: String) async throws -> FfiProfile {
83-
try await paykitGetProfile(publicKey: publicKey)
97+
try await ServiceQueue.background(.core) {
98+
try await paykitGetProfile(publicKey: publicKey)
99+
}
84100
}
85101

86102
// MARK: - Contacts
87103

88104
static func getContacts(publicKey: String) async throws -> [String] {
89-
try await paykitGetContacts(publicKey: publicKey)
105+
try await ServiceQueue.background(.core) {
106+
try await paykitGetContacts(publicKey: publicKey)
107+
}
90108
}
91109

92110
// MARK: - Payments
93111

94112
static func getPaymentList(publicKey: String) async throws -> [FfiPaymentEntry] {
95-
try await paykitGetPaymentList(publicKey: publicKey)
113+
try await ServiceQueue.background(.core) {
114+
try await paykitGetPaymentList(publicKey: publicKey)
115+
}
96116
}
97117

98118
static func getPaymentEndpoint(publicKey: String, methodId: String) async throws -> String? {
99-
try await paykitGetPaymentEndpoint(publicKey: publicKey, methodId: methodId)
119+
try await ServiceQueue.background(.core) {
120+
try await paykitGetPaymentEndpoint(publicKey: publicKey, methodId: methodId)
121+
}
100122
}
101123

102124
static func setPaymentEndpoint(methodId: String, endpointData: String) async throws {
103-
try await paykitSetPaymentEndpoint(methodId: methodId, endpointData: endpointData)
125+
try await ServiceQueue.background(.core) {
126+
try await paykitSetPaymentEndpoint(methodId: methodId, endpointData: endpointData)
127+
}
104128
}
105129

106130
static func removePaymentEndpoint(methodId: String) async throws {
107-
try await paykitRemovePaymentEndpoint(methodId: methodId)
131+
try await ServiceQueue.background(.core) {
132+
try await paykitRemovePaymentEndpoint(methodId: methodId)
133+
}
108134
}
109135

110136
// MARK: - Sign Out
111137

112138
static func signOut() async throws {
113-
try await paykitSignOut()
139+
try await ServiceQueue.background(.core) {
140+
try await paykitSignOut()
141+
}
114142
}
115143

116144
static func forceSignOut() async {

Bitkit/Views/Profile/ProfileView.swift

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SwiftUI
33
struct ProfileView: View {
44
@EnvironmentObject var app: AppViewModel
55
@EnvironmentObject var navigation: NavigationViewModel
6-
@EnvironmentObject var pubkyProfile: PubkyProfileManager
6+
@Environment(PubkyProfileManager.self) var pubkyProfile
77

88
@State private var showSignOutConfirmation = false
99
@State private var isSigningOut = false
@@ -141,10 +141,7 @@ struct ProfileView: View {
141141
HeadlineText(profile.name)
142142
.fixedSize(horizontal: false, vertical: true)
143143

144-
Text(profile.truncatedPublicKey)
145-
.font(Fonts.semiBold(size: 15))
146-
.foregroundColor(.white)
147-
.kerning(0.4)
144+
BodySSBText(profile.truncatedPublicKey, textColor: .white)
148145
}
149146
.frame(maxWidth: .infinity, alignment: .leading)
150147

@@ -207,10 +204,7 @@ struct ProfileView: View {
207204
}
208205
}
209206

210-
Text(t("profile__qr_scan_label", variables: ["name": profile.name]))
211-
.font(Fonts.regular(size: 15))
212-
.foregroundColor(.white)
213-
.kerning(0.4)
207+
BodySText(t("profile__qr_scan_label", variables: ["name": profile.name]), textColor: .white)
214208
.multilineTextAlignment(.center)
215209
}
216210
.frame(maxWidth: .infinity)
@@ -291,15 +285,9 @@ struct ProfileLinkRow: View {
291285
var body: some View {
292286
VStack(alignment: .leading, spacing: 0) {
293287
VStack(alignment: .leading, spacing: 8) {
294-
Text(label.uppercased())
295-
.font(Fonts.medium(size: 13))
296-
.foregroundColor(.white64)
297-
.kerning(1)
288+
CaptionMText(label, textColor: .white64)
298289

299-
Text(value)
300-
.font(Fonts.semiBold(size: 15))
301-
.foregroundColor(.white)
302-
.kerning(0.4)
290+
BodySSBText(value, textColor: .white)
303291
.frame(maxWidth: .infinity, alignment: .leading)
304292
}
305293
.padding(.vertical, 16)
@@ -316,7 +304,7 @@ struct ProfileLinkRow: View {
316304
ProfileView()
317305
.environmentObject(AppViewModel())
318306
.environmentObject(NavigationViewModel())
319-
.environmentObject(manager)
307+
.environment(manager)
320308
}
321309
.preferredColorScheme(.dark)
322310
}

Bitkit/Views/Profile/PubkyRingAuthView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SwiftUI
33
struct PubkyRingAuthView: View {
44
@EnvironmentObject var app: AppViewModel
55
@EnvironmentObject var navigation: NavigationViewModel
6-
@EnvironmentObject var pubkyProfile: PubkyProfileManager
6+
@Environment(PubkyProfileManager.self) var pubkyProfile
77

88
@State private var isAuthenticating = false
99
@State private var isWaitingForRing = false
@@ -151,7 +151,7 @@ struct PubkyRingAuthView: View {
151151
PubkyRingAuthView()
152152
.environmentObject(AppViewModel())
153153
.environmentObject(NavigationViewModel())
154-
.environmentObject(PubkyProfileManager())
154+
.environment(PubkyProfileManager())
155155
}
156156
.preferredColorScheme(.dark)
157157
}

Bitkit/Views/Wallets/HomeView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ struct HomeView: View {
163163
.environmentObject(ActivityListViewModel())
164164
.environmentObject(AppViewModel())
165165
.environmentObject(NavigationViewModel())
166-
.environmentObject(PubkyProfileManager())
166+
.environment(PubkyProfileManager())
167167
.environmentObject(SettingsViewModel.shared)
168168
.environmentObject(WalletViewModel())
169169
.preferredColorScheme(.dark)

0 commit comments

Comments
 (0)