From 3e8af3fd19d9f680c483e19abbecc74a9754e8e3 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Mon, 5 Nov 2018 22:55:09 +0530 Subject: [PATCH] Tunnel view model: No need to save if we already have a validated configuration object --- WireGuard/WireGuard/UI/TunnelViewModel.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift index 6fa13b4..da292c4 100644 --- a/WireGuard/WireGuard/UI/TunnelViewModel.swift +++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift @@ -96,6 +96,10 @@ class TunnelViewModel { } func save() -> SaveResult { + 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 { + if let validatedConfiguration = validatedConfiguration { + // It's already validated and saved + return .saved(validatedConfiguration) + } fieldsWithError.removeAll() guard let publicKeyString = scratchpad[.publicKey] else { fieldsWithError.insert(.publicKey)