From be1b361ded64dee6985edfb31a675ae3a886c6ae Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Thu, 2 Jun 2022 22:02:36 +0200
Subject: [PATCH] Add ConnectionIdProvider

---
 Sources/ElixxirDAppsSDK/Connection.swift      |  4 +++
 .../ConnectionIdProvider.swift                | 31 +++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 Sources/ElixxirDAppsSDK/ConnectionIdProvider.swift

diff --git a/Sources/ElixxirDAppsSDK/Connection.swift b/Sources/ElixxirDAppsSDK/Connection.swift
index 4ecac93a..00e18a81 100644
--- a/Sources/ElixxirDAppsSDK/Connection.swift
+++ b/Sources/ElixxirDAppsSDK/Connection.swift
@@ -1,6 +1,7 @@
 import Bindings
 
 public struct Connection {
+  public var getId: ConnectionIdProvider
   public var isAuthenticated: ConnectionAuthStatusProvider
   public var getPartner: ConnectionPartnerProvider
   public var send: MessageSender
@@ -13,6 +14,7 @@ extension Connection {
     bindingsConnection: BindingsConnection
   ) -> Connection {
     Connection(
+      getId: .live(bindingsConnection: bindingsConnection),
       isAuthenticated: .live(bindingsConnection: bindingsConnection),
       getPartner: .live(bindingsConnection: bindingsConnection),
       send: .live(bindingsConnection: bindingsConnection),
@@ -25,6 +27,7 @@ extension Connection {
     bindingsAuthenticatedConnection: BindingsAuthenticatedConnection
   ) -> Connection {
     Connection(
+      getId: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection),
       isAuthenticated: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection),
       getPartner: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection),
       send: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection),
@@ -37,6 +40,7 @@ extension Connection {
 #if DEBUG
 extension Connection {
   public static let failing = Connection(
+    getId: .failing,
     isAuthenticated: .failing,
     getPartner: .failing,
     send: .failing,
diff --git a/Sources/ElixxirDAppsSDK/ConnectionIdProvider.swift b/Sources/ElixxirDAppsSDK/ConnectionIdProvider.swift
new file mode 100644
index 00000000..3261dfd4
--- /dev/null
+++ b/Sources/ElixxirDAppsSDK/ConnectionIdProvider.swift
@@ -0,0 +1,31 @@
+import Bindings
+
+public struct ConnectionIdProvider {
+  public var get: () -> Int
+
+  public func callAsFunction() -> Int {
+    get()
+  }
+}
+
+extension ConnectionIdProvider {
+  public static func live(
+    bindingsConnection: BindingsConnection
+  ) -> ConnectionIdProvider {
+    ConnectionIdProvider(get: bindingsConnection.getId)
+  }
+
+  public static func live(
+    bindingsAuthenticatedConnection: BindingsAuthenticatedConnection
+  ) -> ConnectionIdProvider {
+    ConnectionIdProvider(get: bindingsAuthenticatedConnection.getId)
+  }
+}
+
+#if DEBUG
+extension ConnectionIdProvider {
+  public static let failing = ConnectionIdProvider {
+    fatalError("Not implemented")
+  }
+}
+#endif
-- 
GitLab