56 lines
1.7 KiB
Swift
56 lines
1.7 KiB
Swift
//
|
|
// CaseWalletService.swift
|
|
// Malinka
|
|
//
|
|
// Created by Juraldinio on 25.08.2022.
|
|
// Copyright © 2022 NUT.Tech. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import WalletKit
|
|
import UIKit
|
|
|
|
|
|
final class CaseWalletService {
|
|
|
|
private let village: Village
|
|
private let cetrifiedDevice: CertifiedDevice
|
|
|
|
init(village: Village, certified device: CertifiedDevice) {
|
|
self.village = village
|
|
self.cetrifiedDevice = device
|
|
}
|
|
|
|
enum ServiceError: Error {
|
|
case controller
|
|
case exists
|
|
case system
|
|
}
|
|
|
|
func createPrivateKeyController(for name: String, manualCreate: Bool) async throws -> UIViewController {
|
|
|
|
do {
|
|
let walletCase = try await self.village.createWalletCase(with: name)
|
|
let walletService = KeysWalletService(village: self.village,
|
|
device: self.cetrifiedDevice.device,
|
|
walletCase: walletCase)
|
|
|
|
let storyboard = await UIStoryboard(name: "AccountOnboarding", bundle: nil)
|
|
guard let viewController = await storyboard.instantiateViewController(withIdentifier: "SetPrivateKeyViewController") as? SetPrivateKeyViewController else {
|
|
throw ServiceError.controller
|
|
}
|
|
// TODO: - THIS BEFORE WE REWRITE TO Layouts
|
|
await MainActor.run {
|
|
viewController.showCreateManual = manualCreate
|
|
viewController.walletService = walletService
|
|
}
|
|
|
|
return viewController
|
|
} catch WalletCaseError.exists {
|
|
throw ServiceError.exists
|
|
} catch WalletCaseError.system {
|
|
throw ServiceError.system
|
|
}
|
|
}
|
|
}
|