Skip to content

Commit

Permalink
Objective C Extensions for Xamarin (trustwallet#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Niach authored and alejandro-isaza committed Jun 2, 2018
1 parent aae062e commit 29997e8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
47 changes: 47 additions & 0 deletions Sources/TrustSDK/ObjCWrapper/TrustSDKObjC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright © 2018 Trust.
//
// This file is part of TrustSDK. The full TrustSDK copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
#if XAMARIN
import Foundation
import TrustCore
import BigInt

@objc(TrustSDK)
public extension TrustSDK {
@objc
public func signMessage(_ message: Data, address: String? = nil, completion: @escaping (Data) -> Void) {
guard WalletAppManager.hasWalletApp else {
return fallbackToInstall()
}
let addr = Address(string: address!)
let command = SignMessageCommand(message: message, address: addr, callbackScheme: callbackScheme, completion: completion)
execute(command: command)
}
@objc
public func signTransaction(_ gasPrice: String, _ gasLimit: UInt64, _ address: String, amount: String, completion: @escaping (Data) -> Void) {
guard WalletAppManager.hasWalletApp else {
return fallbackToInstall()
}
let gasP = BigInt(gasPrice)
let addr = Address(string: address)
var transaction = Transaction(gasPrice: gasP!, gasLimit: gasLimit, to: addr!)
let am = BigInt(amount)
transaction.amount = am!

let command = SignTransactionCommand(transaction: transaction, callbackScheme: callbackScheme, completion: completion)
execute(command: command)
}
@objc
public func signPersonalMessage(_ message: Data, address: String? = nil, completion: @escaping (Data) -> Void) {
guard WalletAppManager.hasWalletApp else {
return fallbackToInstall()
}
let addr = Address(string: address!)
let command = SignPersonalMessageCommand(message: message, address: addr, callbackScheme: callbackScheme, completion: completion)
execute(command: command)
}
}

#endif
8 changes: 4 additions & 4 deletions Sources/TrustSDK/TrustSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import TrustCore
import UIKit

public final class TrustSDK {
@objc(TrustSDK)
public final class TrustSDK: NSObject {
/// The callback URL scheme.
public let callbackScheme: String

Expand All @@ -16,15 +16,15 @@ public final class TrustSDK {

private var pendingCommand: Command?

public init(callbackScheme: String) {
@objc public init(callbackScheme: String) {
self.callbackScheme = callbackScheme
walletApp = WalletAppManager.availableApps.first
}

/// Handles an open URL callback
///
/// - Returns: `true` is the URL was handled; `false` otherwise.
public func handleCallback(url: URL) -> Bool {
@objc public func handleCallback(url: URL) -> Bool {
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false), components.scheme == callbackScheme else {
return false
}
Expand Down
14 changes: 14 additions & 0 deletions TrustSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
7558EF019B1FAEAA1A7120F2 /* Pods_TrustSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E6F5D371F4D1BC5896BA9642 /* Pods_TrustSDK.framework */; };
8B1F64449ED56221FC322F14 /* Pods_TrustSDK_TrustWalletSDKTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9BFFDED920C477EEE88B651 /* Pods_TrustSDK_TrustWalletSDKTests.framework */; };
BF91DE839E2B1B7737732A36 /* Pods_TrustSDK_TrustSDKTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B625F4851358BD32C57BCB3 /* Pods_TrustSDK_TrustSDKTests.framework */; };
F2B757F920C1CC0E0011E673 /* TrustSDKObjC.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2B757F820C1CC0E0011E673 /* TrustSDKObjC.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -85,6 +86,7 @@
C9BFFDED920C477EEE88B651 /* Pods_TrustSDK_TrustWalletSDKTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TrustSDK_TrustWalletSDKTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D6797EADF852BBA8C1308A1F /* Pods-TrustSDK.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TrustSDK.release.xcconfig"; path = "Pods/Target Support Files/Pods-TrustSDK/Pods-TrustSDK.release.xcconfig"; sourceTree = "<group>"; };
E6F5D371F4D1BC5896BA9642 /* Pods_TrustSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TrustSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F2B757F820C1CC0E0011E673 /* TrustSDKObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrustSDKObjC.swift; sourceTree = "<group>"; };
F7A4BA16B1025288FCC38A1E /* Pods-TrustSDK-TrustWalletSDK.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TrustSDK-TrustWalletSDK.release.xcconfig"; path = "Pods/Target Support Files/Pods-TrustSDK-TrustWalletSDK/Pods-TrustSDK-TrustWalletSDK.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -204,6 +206,7 @@
618C423C20AE952F00D2F704 /* TrustSDK */ = {
isa = PBXGroup;
children = (
F2B757F720C1CBB00011E673 /* ObjCWrapper */,
6149DAAA20A53050004EDA7A /* Command.swift */,
6149DAAC20A53050004EDA7A /* TrustSDK.swift */,
6149DAAB20A53050004EDA7A /* WalletApp.swift */,
Expand Down Expand Up @@ -257,6 +260,14 @@
name = Pods;
sourceTree = "<group>";
};
F2B757F720C1CBB00011E673 /* ObjCWrapper */ = {
isa = PBXGroup;
children = (
F2B757F820C1CC0E0011E673 /* TrustSDKObjC.swift */,
);
path = ObjCWrapper;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -587,6 +598,7 @@
6149DAE120A54A6A004EDA7A /* WalletAppManager.swift in Sources */,
6149DADD20A5335E004EDA7A /* SignMessageCommand.swift in Sources */,
6149DADE20A54A66004EDA7A /* Command.swift in Sources */,
F2B757F920C1CC0E0011E673 /* TrustSDKObjC.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -765,6 +777,7 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = YES;
INFOPLIST_FILE = Metadata/TrustSDKInfo.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -792,6 +805,7 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = YES;
INFOPLIST_FILE = Metadata/TrustSDKInfo.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
Expand Down

0 comments on commit 29997e8

Please sign in to comment.