Skip to content

Commit

Permalink
Update iOS rn 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
afilini committed Oct 17, 2024
1 parent 2bfd700 commit 243b2fc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sdk/libportal-ios/libportal-ios.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "libportal-ios"
s.version = "0.2.1"
s.version = "0.3.0"
s.summary = "iOS bindings for the Portal SDK"
s.homepage = "https://github.com/TwentyTwoHW/portal-software"
s.license = "GPL-3.0"
Expand Down
4 changes: 3 additions & 1 deletion sdk/libportal-react-native/example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ async function getOneTag() {
console.info('Looking for a Portal...');
paused = false;

await NfcManager.registerTagEvent();
if (Platform.OS === 'android') {
await NfcManager.registerTagEvent();
}
await NfcManager.requestTechnology(NfcTech.NfcA, {});
if (Platform.OS === 'ios') {
restartInterval = setInterval(restartPolling, 17500);
Expand Down
9 changes: 9 additions & 0 deletions sdk/libportal-react-native/ios/LibportalReactNative.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ @interface RCT_EXTERN_MODULE(LibportalReactNative, NSObject)
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(getXpub: (NSString)derivationPath
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(setDescriptor: (NSString)descriptor
bsms_data: (NSString)bsms_data
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

+ (BOOL)requiresMainQueueSetup
{
return NO;
Expand Down
56 changes: 56 additions & 0 deletions sdk/libportal-react-native/ios/LibportalReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,60 @@ class LibportalReactNative: NSObject {
}
}
}

@objc func getXpub(_ derivationPath: NSString, withResolver resolve: @escaping RCTPromiseResolveBlock, withRejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
let derivationPath = derivationPath as String

Task {
do {
let xpub = try await self.sdk?.getXpub(path: derivationPath)
let bsms: NSDictionary = [
"version": xpub?.bsms.version as Any,
"token": xpub?.bsms.token as Any,
"keyName": xpub?.bsms.keyName as Any,
"signature": xpub?.bsms.signature as Any,
]
let dict: NSDictionary = [
"xpub": xpub?.xpub as Any,
"bsms": bsms as Any,
]
resolve(dict)
}
catch {
reject("Error", error.localizedDescription, error)
}
}
}

@objc func setDescriptor(_ descriptor: NSString, bsms_data: NSString, withResolver resolve: @escaping RCTPromiseResolveBlock, withRejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
let descriptor = descriptor as String
let bsms_data = bsms_data as String?

struct LocalBsmsData: Codable {
var version: String
var pathRestrictions: String
var firstAddress: String
}

Task {
do {
let bsms_decoded = {
do {
return try bsms_data.flatMap {
let decoder = JSONDecoder()
let decoded = try decoder.decode(LocalBsmsData.self, from: $0.data(using: .utf8)!)
return SetDescriptorBsmsData(version: decoded.version, pathRestrictions: decoded.pathRestrictions, firstAddress: decoded.firstAddress)
}
} catch {
return nil
}
}()
try await self.sdk?.setDescriptor(descriptor: descriptor, bsms: bsms_decoded)
resolve(nil)
}
catch {
reject("Error", error.localizedDescription, error)
}
}
}
}

0 comments on commit 243b2fc

Please sign in to comment.