-
Notifications
You must be signed in to change notification settings - Fork 6
/
AppCore.swift
45 lines (38 loc) · 1.33 KB
/
AppCore.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// AppCore.swift
// TestApp
//
// Created by Yehor Popovych on 15.11.2022.
//
import Foundation
import TesseractClient
final class TesseractTransportDelegate: TesseractDelegate {
private weak var alerts: AlertProvider!
init(alerts: AlertProvider) {
self.alerts = alerts
}
func select(transports: Dictionary<String, Status>) async -> String? {
assert(transports.count == 1, "How the heck do we have more than one transport here?")
let transport = transports.first!
switch transport.value {
case .ready: return transport.key
case .unavailable(let why):
await alerts.showAlert(alert: "Transport '\(transport.key)' is not available because of the following reason: \(why)")
return nil
case .error(let err):
await alerts.showAlert(alert: "Transport '\(transport.key)' is not available because the transport produced an error: \(err)")
return nil
}
}
}
struct AppCore {
private let service: TestService
init(alerts: AlertProvider) {
service = try! Tesseract
.default(delegate: TesseractTransportDelegate(alerts: alerts))
.service(TestService.self)
}
func signTx(tx: String) async throws -> String {
try await service.signTransaction(req: tx)
}
}