mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-05-28 13:18:19 +00:00
32 lines
587 B
Swift
32 lines
587 B
Swift
import Foundation
|
|
import Models
|
|
import Network
|
|
|
|
@MainActor
|
|
public class CurrentAccount: ObservableObject {
|
|
@Published public private(set) var account: Account?
|
|
|
|
private var client: Client?
|
|
|
|
public init() {
|
|
|
|
}
|
|
|
|
public func setClient(client: Client) {
|
|
self.client = client
|
|
Task {
|
|
await fetchCurrentAccount()
|
|
}
|
|
}
|
|
|
|
public func fetchCurrentAccount() async {
|
|
guard let client = client, client.isAuth else {
|
|
account = nil
|
|
return
|
|
}
|
|
Task {
|
|
account = try? await client.get(endpoint: Accounts.verifyCredentials)
|
|
}
|
|
}
|
|
}
|