parent
dfa2cecc2a
commit
024e3e371d
@ -1,52 +0,0 @@ |
||||
// Copyright SIX DAY LLC. All rights reserved. |
||||
|
||||
import Foundation |
||||
import UIKit |
||||
|
||||
protocol AddCustomNetworkCoordinatorDelegate: class { |
||||
func didAddNetwork(network: CustomRPC, in coordinator: AddCustomNetworkCoordinator) |
||||
func didCancel(in coordinator: AddCustomNetworkCoordinator) |
||||
} |
||||
|
||||
class AddCustomNetworkCoordinator: Coordinator { |
||||
private let navigationController: UINavigationController |
||||
|
||||
private lazy var addNetworkItem: UIBarButtonItem = { |
||||
return UIBarButtonItem( |
||||
barButtonSystemItem: .add, |
||||
target: self, |
||||
action: #selector(addNetwork) |
||||
) |
||||
}() |
||||
|
||||
private lazy var addCustomNetworkController: AddCustomNetworkViewController = { |
||||
let controller = AddCustomNetworkViewController() |
||||
controller.navigationItem.rightBarButtonItem = addNetworkItem |
||||
return controller |
||||
}() |
||||
|
||||
var coordinators: [Coordinator] = [] |
||||
weak var delegate: AddCustomNetworkCoordinatorDelegate? |
||||
|
||||
init( |
||||
navigationController: UINavigationController = NavigationController() |
||||
) { |
||||
self.navigationController = navigationController |
||||
self.navigationController.modalPresentationStyle = .formSheet |
||||
} |
||||
|
||||
func start() { |
||||
navigationController.viewControllers = [addCustomNetworkController] |
||||
} |
||||
|
||||
@objc func addNetwork() { |
||||
addCustomNetworkController.addNetwork { [weak self] result in |
||||
guard let strongSelf = self else { return } |
||||
switch result { |
||||
case .success(let network): |
||||
strongSelf.delegate?.didAddNetwork(network: network, in: strongSelf) |
||||
case .failure: break |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,85 +0,0 @@ |
||||
// Copyright SIX DAY LLC. All rights reserved. |
||||
|
||||
import UIKit |
||||
import Eureka |
||||
import Result |
||||
|
||||
class AddCustomNetworkViewController: FormViewController { |
||||
private let viewModel = AddCustomNetworkViewModel() |
||||
|
||||
private struct Values { |
||||
static let chainID = "chainID" |
||||
static let name = "name" |
||||
static let symbol = "symbol" |
||||
static let endpoint = "endpoint" |
||||
} |
||||
|
||||
private var chainIDRow: TextFloatLabelRow? { |
||||
return form.rowBy(tag: Values.chainID) as? TextFloatLabelRow |
||||
} |
||||
private var nameRow: TextFloatLabelRow? { |
||||
return form.rowBy(tag: Values.name) as? TextFloatLabelRow |
||||
} |
||||
private var symbolRow: TextFloatLabelRow? { |
||||
return form.rowBy(tag: Values.symbol) as? TextFloatLabelRow |
||||
} |
||||
private var endpointRow: TextFloatLabelRow? { |
||||
return form.rowBy(tag: Values.endpoint) as? TextFloatLabelRow |
||||
} |
||||
|
||||
weak var delegate: NewTokenViewControllerDelegate? |
||||
|
||||
override func viewDidLoad() { |
||||
super.viewDidLoad() |
||||
|
||||
title = viewModel.title |
||||
form = Section() |
||||
|
||||
+++ Section() |
||||
|
||||
<<< AppFormAppearance.textFieldFloat(tag: Values.chainID) { |
||||
$0.add(rule: EthereumAddressRule()) |
||||
$0.validationOptions = .validatesOnDemand |
||||
$0.title = R.string.localizable.chainID() |
||||
}.cellUpdate { cell, _ in |
||||
cell.textField.keyboardType = .decimalPad |
||||
} |
||||
|
||||
<<< AppFormAppearance.textFieldFloat(tag: Values.name) { |
||||
$0.add(rule: RuleRequired()) |
||||
$0.validationOptions = .validatesOnDemand |
||||
$0.title = R.string.localizable.name() |
||||
} |
||||
|
||||
<<< AppFormAppearance.textFieldFloat(tag: Values.symbol) { |
||||
$0.add(rule: RuleRequired()) |
||||
$0.validationOptions = .validatesOnDemand |
||||
$0.title = R.string.localizable.symbol() |
||||
} |
||||
|
||||
<<< AppFormAppearance.textFieldFloat(tag: Values.endpoint) { |
||||
$0.add(rule: RuleRequired()) |
||||
$0.validationOptions = .validatesOnDemand |
||||
$0.title = R.string.localizable.endpoint() |
||||
} |
||||
} |
||||
|
||||
func addNetwork(completion: @escaping(Result<CustomRPC, AnyError>) -> Void) { |
||||
guard form.validate().isEmpty else { |
||||
return |
||||
} |
||||
let chainID = Int(chainIDRow?.value ?? "0") ?? 0 |
||||
let name = nameRow?.value ?? "" |
||||
let symbol = symbolRow?.value ?? "" |
||||
let endpoint = endpointRow?.value ?? "" |
||||
|
||||
let customNetwork = CustomRPC( |
||||
chainID: chainID, |
||||
name: name, |
||||
symbol: symbol, |
||||
endpoint: endpoint |
||||
) |
||||
|
||||
completion(.success(customNetwork)) |
||||
} |
||||
} |
@ -1,9 +0,0 @@ |
||||
// Copyright SIX DAY LLC. All rights reserved. |
||||
|
||||
import Foundation |
||||
|
||||
struct AddCustomNetworkViewModel { |
||||
var title: String { |
||||
return R.string.localizable.settingsCustomNetworkNavigationTitle() |
||||
} |
||||
} |
Loading…
Reference in new issue