IceCubesApp/Packages/AppAccount/Sources/AppAccount/AppAccountViewModel.swift

29 lines
594 B
Swift
Raw Normal View History

2022-12-30 07:36:22 +00:00
import Models
import Network
2023-01-17 10:36:01 +00:00
import SwiftUI
2022-12-30 07:36:22 +00:00
@MainActor
public class AppAccountViewModel: ObservableObject {
let appAccount: AppAccount
let client: Client
2023-01-17 10:36:01 +00:00
2022-12-30 07:36:22 +00:00
@Published var account: Account?
2023-01-17 10:36:01 +00:00
2023-01-10 05:58:50 +00:00
var acct: String {
"@\(account?.acct ?? "...")@\(appAccount.server)"
}
2023-01-17 10:36:01 +00:00
public init(appAccount: AppAccount) {
2022-12-30 07:36:22 +00:00
self.appAccount = appAccount
2023-01-17 10:36:01 +00:00
client = .init(server: appAccount.server, oauthToken: appAccount.oauthToken)
2022-12-30 07:36:22 +00:00
}
2023-01-17 10:36:01 +00:00
2022-12-30 07:36:22 +00:00
func fetchAccount() async {
do {
account = try await client.get(endpoint: Accounts.verifyCredentials)
} catch {
print(error)
}
}
}