From 741b69b813ef4336e06e00b6fe76b944e039b2aa Mon Sep 17 00:00:00 2001 From: Shreyas Thiagaraj Date: Tue, 22 Oct 2019 02:05:06 +0000 Subject: [PATCH] Hack to make project compile --- .../ios/RNBlockstackSdk/RNBlockstackSdk.swift | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/BlockstackSDK/ios/RNBlockstackSdk/RNBlockstackSdk.swift b/BlockstackSDK/ios/RNBlockstackSdk/RNBlockstackSdk.swift index 5a006a17..63338f98 100644 --- a/BlockstackSDK/ios/RNBlockstackSdk/RNBlockstackSdk.swift +++ b/BlockstackSDK/ios/RNBlockstackSdk/RNBlockstackSdk.swift @@ -37,7 +37,8 @@ class RNBlockstackSdk: NSObject { // TODO: Remove reliance on session config. @objc public func signIn(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { guard let config = self.config, - let redirectUrl = config["redirectUrl"] as? String, + let redirectUrlString = config["redirectUrl"] as? String, + let redirectURL = URL(string: redirectUrlString), let appDomainString = config["appDomain"] as? String, let appDomain = URL(string: appDomainString) else { reject(self.defaultErrorCode, "Invalid session config", nil) @@ -47,9 +48,9 @@ class RNBlockstackSdk: NSObject { if let manifestPath = config["manifestUrl"] as? String { manifestURI = URL(string: manifestPath) } - let scopes = config["scopes"] as? [String] ?? ["store_write"] + let scopes = (config["scopes"] as? [String] ?? ["store_write"]).compactMap { AuthScope.fromString($0) } // TODO: REJECT when cancelled or failed, and handle this in App.js - Blockstack.shared.signIn(redirectURI: redirectUrl, appDomain: appDomain, manifestURI: manifestURI, scopes: scopes) { authResult in + Blockstack.shared.signIn(redirectURI: redirectURL, appDomain: appDomain, manifestURI: manifestURI, scopes: scopes) { authResult in var error: Any = NSNull() let data: [String: Any] switch authResult { @@ -126,7 +127,6 @@ class RNBlockstackSdk: NSObject { } } - } extension Encodable { @@ -135,3 +135,19 @@ extension Encodable { return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? [String: Any] } } } + +// TODO: Make public Blockstack SDK and remove this hack +extension AuthScope { + static func fromString(_ value: String) -> AuthScope? { + switch value { + case AuthScope.storeWrite.rawValue: + return .storeWrite + case AuthScope.publishData.rawValue: + return .publishData + case AuthScope.email.rawValue: + return .email + default: + return nil + } + } +}