Tunnel view model: No need to save if we already have a validated configuration object

This commit is contained in:
Roopesh Chander 2018-11-05 22:55:09 +05:30
parent 12a4acef61
commit 3e8af3fd19
1 changed files with 8 additions and 0 deletions

View File

@ -96,6 +96,10 @@ class TunnelViewModel {
}
func save() -> SaveResult<InterfaceConfiguration> {
if let validatedConfiguration = validatedConfiguration {
// It's already validated and saved
return .saved(validatedConfiguration)
}
fieldsWithError.removeAll()
guard let name = scratchpad[.name]?.trimmingCharacters(in: .whitespacesAndNewlines), (!name.isEmpty) else {
fieldsWithError.insert(.name)
@ -234,6 +238,10 @@ class TunnelViewModel {
}
func save() -> SaveResult<PeerConfiguration> {
if let validatedConfiguration = validatedConfiguration {
// It's already validated and saved
return .saved(validatedConfiguration)
}
fieldsWithError.removeAll()
guard let publicKeyString = scratchpad[.publicKey] else {
fieldsWithError.insert(.publicKey)