From 3f4d0415117ef1b0b9d3be4d3b7f4fe24890269c Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Fri, 22 Jul 2022 13:03:17 +0100
Subject: [PATCH] Add ConnectionIsAuthenticated functor

---
 Sources/ElixxirDAppsSDK/Connection.swift      |  4 +++
 .../ConnectionIsAuthenticated.swift           | 26 +++++++++++++++
 .../Legacy/ConnectionAuthStatusProvider.swift | 33 -------------------
 3 files changed, 30 insertions(+), 33 deletions(-)
 create mode 100644 Sources/ElixxirDAppsSDK/ConnectionIsAuthenticated.swift
 delete mode 100644 Sources/ElixxirDAppsSDK/Legacy/ConnectionAuthStatusProvider.swift

diff --git a/Sources/ElixxirDAppsSDK/Connection.swift b/Sources/ElixxirDAppsSDK/Connection.swift
index 4daaacdc..8009d9c1 100644
--- a/Sources/ElixxirDAppsSDK/Connection.swift
+++ b/Sources/ElixxirDAppsSDK/Connection.swift
@@ -1,6 +1,7 @@
 import Bindings
 
 public struct Connection {
+  public var isAuthenticated: ConnectionIsAuthenticated
   public var getId: ConnectionGetId
   public var getPartner: ConnectionGetPartner
   public var close: ConnectionClose
@@ -9,6 +10,7 @@ public struct Connection {
 extension Connection {
   public static func live(_ bindingsConnection: BindingsConnection) -> Connection {
     Connection(
+      isAuthenticated: .live(bindingsConnection),
       getId: .live(bindingsConnection),
       getPartner: .live(bindingsConnection),
       close: .live(bindingsConnection)
@@ -17,6 +19,7 @@ extension Connection {
 
   public static func live(_ bindingsConnection: BindingsAuthenticatedConnection) -> Connection {
     Connection(
+      isAuthenticated: .live(bindingsConnection),
       getId: .live(bindingsConnection),
       getPartner: .live(bindingsConnection),
       close: .live(bindingsConnection)
@@ -26,6 +29,7 @@ extension Connection {
 
 extension Connection {
   public static let unimplemented = Connection(
+    isAuthenticated: .unimplemented,
     getId: .unimplemented,
     getPartner: .unimplemented,
     close: .unimplemented
diff --git a/Sources/ElixxirDAppsSDK/ConnectionIsAuthenticated.swift b/Sources/ElixxirDAppsSDK/ConnectionIsAuthenticated.swift
new file mode 100644
index 00000000..86fc7f97
--- /dev/null
+++ b/Sources/ElixxirDAppsSDK/ConnectionIsAuthenticated.swift
@@ -0,0 +1,26 @@
+import Bindings
+import XCTestDynamicOverlay
+
+public struct ConnectionIsAuthenticated {
+  public var run: () -> Bool
+
+  public func callAsFunction() -> Bool {
+    run()
+  }
+}
+
+extension ConnectionIsAuthenticated {
+  public static func live(_ bindingsConnection: BindingsConnection) -> ConnectionIsAuthenticated {
+    ConnectionIsAuthenticated { false }
+  }
+
+  public static func live(_ bindingsConnection: BindingsAuthenticatedConnection) -> ConnectionIsAuthenticated {
+    ConnectionIsAuthenticated(run: bindingsConnection.isAuthenticated)
+  }
+}
+
+extension ConnectionIsAuthenticated {
+  public static let unimplemented = ConnectionIsAuthenticated(
+    run: XCTUnimplemented("\(Self.self)")
+  )
+}
diff --git a/Sources/ElixxirDAppsSDK/Legacy/ConnectionAuthStatusProvider.swift b/Sources/ElixxirDAppsSDK/Legacy/ConnectionAuthStatusProvider.swift
deleted file mode 100644
index d42e78f3..00000000
--- a/Sources/ElixxirDAppsSDK/Legacy/ConnectionAuthStatusProvider.swift
+++ /dev/null
@@ -1,33 +0,0 @@
-import Bindings
-
-public struct ConnectionAuthStatusProvider {
-  public var isAuthenticated: () -> Bool
-
-  public func callAsFunction() -> Bool {
-    isAuthenticated()
-  }
-}
-
-extension ConnectionAuthStatusProvider {
-  public static func live(
-    bindingsConnection: BindingsConnection
-  ) -> ConnectionAuthStatusProvider {
-    ConnectionAuthStatusProvider { false }
-  }
-
-  public static func live(
-    bindingsAuthenticatedConnection: BindingsAuthenticatedConnection
-  ) -> ConnectionAuthStatusProvider {
-    ConnectionAuthStatusProvider(
-      isAuthenticated: bindingsAuthenticatedConnection.isAuthenticated
-    )
-  }
-}
-
-#if DEBUG
-extension ConnectionAuthStatusProvider {
-  public static let failing = ConnectionAuthStatusProvider {
-    fatalError("Not implemented")
-  }
-}
-#endif
-- 
GitLab