From e8194482e842365f3d2abbf6bdf0437815386cc9 Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Tue, 7 Jun 2022 12:10:01 +0200
Subject: [PATCH] Use Fact model in ContactFactsProvider

---
 Sources/ElixxirDAppsSDK/ContactFactsProvider.swift | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/Sources/ElixxirDAppsSDK/ContactFactsProvider.swift b/Sources/ElixxirDAppsSDK/ContactFactsProvider.swift
index e2adebfb..2029dc6f 100644
--- a/Sources/ElixxirDAppsSDK/ContactFactsProvider.swift
+++ b/Sources/ElixxirDAppsSDK/ContactFactsProvider.swift
@@ -1,9 +1,9 @@
 import Bindings
 
 public struct ContactFactsProvider {
-  public var get: (Data) throws -> Data
+  public var get: (Data) throws -> [Fact]
 
-  public func callAsFunction(contact: Data) throws -> Data {
+  public func callAsFunction(contact: Data) throws -> [Fact] {
     try get(contact)
   }
 }
@@ -11,13 +11,15 @@ public struct ContactFactsProvider {
 extension ContactFactsProvider {
   public static let live = ContactFactsProvider { contact in
     var error: NSError?
-    let facts = BindingsGetFactsFromContact(contact, &error)
+    let factsData = BindingsGetFactsFromContact(contact, &error)
     if let error = error {
       throw error
     }
-    guard let facts = facts else {
+    guard let factsData = factsData else {
       fatalError("BindingsGetFactsFromContact returned `nil` without providing error")
     }
+    let decoder = JSONDecoder()
+    let facts = try decoder.decode([Fact].self, from: factsData)
     return facts
   }
 }
-- 
GitLab