From dd22f0ae1e9393ba2eb9ce2a58318a667093ae43 Mon Sep 17 00:00:00 2001 From: Erfan Shekarchi Date: Thu, 4 Apr 2024 15:22:56 -0400 Subject: [PATCH] corected getAccount --- ios/Fula.swift | 28 +++++++++++++++++++--------- package.json | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ios/Fula.swift b/ios/Fula.swift index 7b26075..ee62082 100644 --- a/ios/Fula.swift +++ b/ios/Fula.swift @@ -1372,15 +1372,25 @@ class FulaModule: NSObject { @objc(getAccount:withRejecter:) - func getAccount(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { - do { - let account = try self.fula!.getAccount() - let accountString = String(data: account, encoding: .utf8) - resolve(accountString) - } catch let error { - reject("ERR_FULA", "getAccount: \(error.localizedDescription)", error) - } - } + func getAccount(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + guard let fulaClient = self.fula else { + let error = NSError(domain: "FulaModuleError", code: -1, userInfo: [NSLocalizedDescriptionKey: "Fula client is not initialized"]) + reject("ERR_FULA_NOT_INITIALIZED", "Fula client is not initialized", error) + return + } + + do { + let account = try fulaClient.getAccount() + guard let accountString = String(data: account, encoding: .utf8) else { + let conversionError = NSError(domain: "FulaModuleError", code: -2, userInfo: [NSLocalizedDescriptionKey: "Unable to convert account data to String"]) + reject("ERR_FULA_CONVERSION_FAILED", "Unable to convert account data to String", conversionError) + return + } + resolve(accountString) + } catch let error { + reject("ERR_FULA", "getAccount: \(error.localizedDescription)", error) + } + } @objc(assetsBalance:withAssetId:withClassId:withResolver:withRejecter:) func assetsBalance(account: String, assetId: String, classId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { diff --git a/package.json b/package.json index cf090e7..f1665f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@functionland/react-native-fula", - "version": "1.54.14", + "version": "1.54.15", "description": "This package is a bridge to use the Fula libp2p protocols in the react-native which is using wnfs", "main": "lib/commonjs/index", "module": "lib/module/index",