From 3658c4f829878ea9f7e4cfdc4251f74473021d6f Mon Sep 17 00:00:00 2001 From: Steve Kalkwarf Date: Mon, 23 Jan 2023 00:41:01 -0500 Subject: [PATCH] Primitive validation of domain before trying to connect (#287) * Primitive validation of domain before trying to connect Every domain needs at least one "dot" and can't end with a "dot." Don't try connecting unless/until these are both true. * Correctly reset instance when invalid Co-authored-by: Thomas Ricouard --- .../App/Tabs/Settings/AddAccountsView.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/IceCubesApp/App/Tabs/Settings/AddAccountsView.swift b/IceCubesApp/App/Tabs/Settings/AddAccountsView.swift index 5d2ec988..68a29c55 100644 --- a/IceCubesApp/App/Tabs/Settings/AddAccountsView.swift +++ b/IceCubesApp/App/Tabs/Settings/AddAccountsView.swift @@ -87,11 +87,17 @@ struct AddAccountView: View { let client = Client(server: newValue) Task { do { - let instance: Instance = try await client.get(endpoint: Instances.instance) - withAnimation { - self.instance = instance + // bare bones preflight for domain validity + if client.server.contains(".") && client.server.last != "." { + let instance: Instance = try await client.get(endpoint: Instances.instance) + withAnimation { + self.instance = instance + } + instanceFetchError = nil + } else { + instance = nil + instanceFetchError = nil } - instanceFetchError = nil } catch _ as DecodingError { instance = nil instanceFetchError = "account.add.error.instance-not-supported"