From ad1c12ff3d8a14f05ee3d01e5fd21eb7b905e2ab Mon Sep 17 00:00:00 2001 From: Mattia Ferrari <65465360+mattiaferrari02@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:28:13 +0200 Subject: [PATCH] Add destroy session (#6) add destroy session --- cpp/GdkHostObject.cpp | 38 +++++- .../ios/GdkExample.xcodeproj/project.pbxproj | 8 ++ example/ios/Podfile | 2 +- example/ios/Podfile.lock | 112 +----------------- example/src/App.tsx | 15 ++- src/GdkNativeInterface.ts | 1 + src/createGdk.ts | 4 +- 7 files changed, 68 insertions(+), 112 deletions(-) diff --git a/cpp/GdkHostObject.cpp b/cpp/GdkHostObject.cpp index fd8597a..d47a4d7 100644 --- a/cpp/GdkHostObject.cpp +++ b/cpp/GdkHostObject.cpp @@ -13,12 +13,16 @@ using json = nlohmann::json; GdkHostObject::GdkHostObject(std::string dirUrl, jsi::Runtime &runtime, std::shared_ptr jsCallInvoker): invoker(jsCallInvoker), rt(runtime) { sessionDirectoryUrl = dirUrl; pool = std::make_shared(); - + session = NULL; } GdkHostObject::~GdkHostObject() { + + if(session != nullptr) { GA_set_notification_handler(session, nullptr, nullptr); GA_destroy_session(session); + } + } @@ -51,6 +55,7 @@ std::vector GdkHostObject::getPropertyNames(jsi::Runtime& rt) { result.push_back(jsi::PropNameID::forUtf8(rt, std::string("getNetworks"))); result.push_back(jsi::PropNameID::forUtf8(rt, std::string("signPsbt"))); result.push_back(jsi::PropNameID::forUtf8(rt, std::string("registerNetwork"))); + result.push_back(jsi::PropNameID::forUtf8(rt, std::string("destroySession"))); return result; } @@ -59,6 +64,25 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop auto propName = propNameId.utf8(runtime); auto funcName = "gdk." + propName; + if (propName == "destroySession") { + return jsi::Function::createFromHostFunction(runtime, + jsi::PropNameID::forAscii(runtime, funcName), + 0, + [this](jsi::Runtime& runtime, + const jsi::Value& thisValue, + const jsi::Value* arguments, + size_t count) -> jsi::Value { + + GA_set_notification_handler(session, nullptr, nullptr); + utils::wrapCall(GA_destroy_session(session)); + + session = NULL; + + + return jsi::Value::undefined(); + }); + } + if (propName == "generateMnemonic12") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, funcName), @@ -112,8 +136,16 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop const jsi::Value& thisValue, const jsi::Value* arguments, size_t count) -> jsi::Value { - - utils::wrapCall(GA_create_session(&session)); + if (session != NULL) { + throw new jsi::JSError(runtime, "Cannot recreate session. Call destroy before"); + } + + GA_session* newSession; + + + utils::wrapCall(GA_create_session(&newSession)); + + session = newSession; utils::wrapCall(GA_set_notification_handler(session, utils::notificationsHandler, this)); diff --git a/example/ios/GdkExample.xcodeproj/project.pbxproj b/example/ios/GdkExample.xcodeproj/project.pbxproj index d741ba1..ab64c06 100644 --- a/example/ios/GdkExample.xcodeproj/project.pbxproj +++ b/example/ios/GdkExample.xcodeproj/project.pbxproj @@ -465,7 +465,10 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 5N4S52Y7KS; ENABLE_BITCODE = NO; INFOPLIST_FILE = GdkExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -480,6 +483,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = GdkExample; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; @@ -492,7 +496,10 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 5N4S52Y7KS; INFOPLIST_FILE = GdkExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -506,6 +513,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = GdkExample; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; diff --git a/example/ios/Podfile b/example/ios/Podfile index 7057462..14138b1 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -19,7 +19,7 @@ prepare_react_native_project! # dependencies: { # ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}), # ``` -flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled +flipper_config = FlipperConfiguration.disabled linkage = ENV['USE_FRAMEWORKS'] if linkage != nil diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index a694eb9..6f3999f 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,71 +1,13 @@ PODS: - boost (1.83.0) - - CocoaAsyncSocket (7.6.5) - DoubleConversion (1.1.6) - FBLazyVector (0.73.3) - - Flipper (0.201.0): - - Flipper-Folly (~> 2.6) - - Flipper-Boost-iOSX (1.76.0.1.11) - - Flipper-DoubleConversion (3.2.0.1) - - Flipper-Fmt (7.1.7) - - Flipper-Folly (2.6.10): - - Flipper-Boost-iOSX - - Flipper-DoubleConversion - - Flipper-Fmt (= 7.1.7) - - Flipper-Glog - - libevent (~> 2.1.12) - - OpenSSL-Universal (= 1.1.1100) - - Flipper-Glog (0.5.0.5) - - Flipper-PeerTalk (0.0.4) - - FlipperKit (0.201.0): - - FlipperKit/Core (= 0.201.0) - - FlipperKit/Core (0.201.0): - - Flipper (~> 0.201.0) - - FlipperKit/CppBridge - - FlipperKit/FBCxxFollyDynamicConvert - - FlipperKit/FBDefines - - FlipperKit/FKPortForwarding - - SocketRocket (~> 0.6.0) - - FlipperKit/CppBridge (0.201.0): - - Flipper (~> 0.201.0) - - FlipperKit/FBCxxFollyDynamicConvert (0.201.0): - - Flipper-Folly (~> 2.6) - - FlipperKit/FBDefines (0.201.0) - - FlipperKit/FKPortForwarding (0.201.0): - - CocoaAsyncSocket (~> 7.6) - - Flipper-PeerTalk (~> 0.0.4) - - FlipperKit/FlipperKitHighlightOverlay (0.201.0) - - FlipperKit/FlipperKitLayoutHelpers (0.201.0): - - FlipperKit/Core - - FlipperKit/FlipperKitHighlightOverlay - - FlipperKit/FlipperKitLayoutTextSearchable - - FlipperKit/FlipperKitLayoutIOSDescriptors (0.201.0): - - FlipperKit/Core - - FlipperKit/FlipperKitHighlightOverlay - - FlipperKit/FlipperKitLayoutHelpers - - FlipperKit/FlipperKitLayoutPlugin (0.201.0): - - FlipperKit/Core - - FlipperKit/FlipperKitHighlightOverlay - - FlipperKit/FlipperKitLayoutHelpers - - FlipperKit/FlipperKitLayoutIOSDescriptors - - FlipperKit/FlipperKitLayoutTextSearchable - - FlipperKit/FlipperKitLayoutTextSearchable (0.201.0) - - FlipperKit/FlipperKitNetworkPlugin (0.201.0): - - FlipperKit/Core - - FlipperKit/FlipperKitReactPlugin (0.201.0): - - FlipperKit/Core - - FlipperKit/FlipperKitUserDefaultsPlugin (0.201.0): - - FlipperKit/Core - - FlipperKit/SKIOSNetworkPlugin (0.201.0): - - FlipperKit/Core - - FlipperKit/FlipperKitNetworkPlugin - fmt (6.2.1) - glog (0.3.5) - hermes-engine (0.73.3): - hermes-engine/Pre-built (= 0.73.3) - hermes-engine/Pre-built (0.73.3) - libevent (2.1.12) - - OpenSSL-Universal (1.1.1100) - RCT-Folly (2022.05.16.00): - boost - DoubleConversion @@ -943,7 +885,7 @@ PODS: - React-Mapbuffer (0.73.3): - glog - React-debug - - react-native-gdk (0.0.3): + - react-native-gdk (0.0.6): - React - React-callinvoker - React-Core @@ -1164,30 +1106,9 @@ DEPENDENCIES: - boost (from `../node_modules/react-native/third-party-podspecs/boost.podspec`) - DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`) - FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`) - - Flipper (= 0.201.0) - - Flipper-Boost-iOSX (= 1.76.0.1.11) - - Flipper-DoubleConversion (= 3.2.0.1) - - Flipper-Fmt (= 7.1.7) - - Flipper-Folly (= 2.6.10) - - Flipper-Glog (= 0.5.0.5) - - Flipper-PeerTalk (= 0.0.4) - - FlipperKit (= 0.201.0) - - FlipperKit/Core (= 0.201.0) - - FlipperKit/CppBridge (= 0.201.0) - - FlipperKit/FBCxxFollyDynamicConvert (= 0.201.0) - - FlipperKit/FBDefines (= 0.201.0) - - FlipperKit/FKPortForwarding (= 0.201.0) - - FlipperKit/FlipperKitHighlightOverlay (= 0.201.0) - - FlipperKit/FlipperKitLayoutPlugin (= 0.201.0) - - FlipperKit/FlipperKitLayoutTextSearchable (= 0.201.0) - - FlipperKit/FlipperKitNetworkPlugin (= 0.201.0) - - FlipperKit/FlipperKitReactPlugin (= 0.201.0) - - FlipperKit/FlipperKitUserDefaultsPlugin (= 0.201.0) - - FlipperKit/SKIOSNetworkPlugin (= 0.201.0) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) - libevent (~> 2.1.12) - - OpenSSL-Universal (= 1.1.1100) - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) - RCT-Folly/Fabric (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) - RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`) @@ -1196,7 +1117,6 @@ DEPENDENCIES: - React-callinvoker (from `../node_modules/react-native/ReactCommon/callinvoker`) - React-Codegen (from `build/generated/ios`) - React-Core (from `../node_modules/react-native/`) - - React-Core/DevSupport (from `../node_modules/react-native/`) - React-Core/RCTWebSocket (from `../node_modules/react-native/`) - React-CoreModules (from `../node_modules/react-native/React/CoreModules`) - React-cxxreact (from `../node_modules/react-native/ReactCommon/cxxreact`) @@ -1241,18 +1161,8 @@ DEPENDENCIES: SPEC REPOS: trunk: - - CocoaAsyncSocket - - Flipper - - Flipper-Boost-iOSX - - Flipper-DoubleConversion - - Flipper-Fmt - - Flipper-Folly - - Flipper-Glog - - Flipper-PeerTalk - - FlipperKit - fmt - libevent - - OpenSSL-Universal - SocketRocket EXTERNAL SOURCES: @@ -1364,22 +1274,12 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: boost: d3f49c53809116a5d38da093a8aa78bf551aed09 - CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953 FBLazyVector: 70590b4f9e8ae9b0ce076efacea3abd7bc585ace - Flipper: c7a0093234c4bdd456e363f2f19b2e4b27652d44 - Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c - Flipper-DoubleConversion: 2dc99b02f658daf147069aad9dbd29d8feb06d30 - Flipper-Fmt: 60cbdd92fc254826e61d669a5d87ef7015396a9b - Flipper-Folly: 584845625005ff068a6ebf41f857f468decd26b3 - Flipper-Glog: 70c50ce58ddaf67dc35180db05f191692570f446 - Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9 - FlipperKit: 37525a5d056ef9b93d1578e04bc3ea1de940094f fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 - glog: 035f1e36e53b355cf70f6434d161b36e7d21fecd + glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2 hermes-engine: 5420539d016f368cd27e008f65f777abd6098c56 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c RCT-Folly: 7169b2b1c44399c76a47b5deaaba715eeeb476c0 RCTRequired: 9b898847f76977a6dfed2a08f4c5ed37add75ec0 RCTTypeSafety: 0debdc4ba38c8138016d8d8ada4bdf9ec1b8aa82 @@ -1402,7 +1302,7 @@ SPEC CHECKSUMS: React-jsitracing: 18b04aa81d7e36ce4d60db121ce0567f9ac4b5ea React-logger: cb0dd15ac67b00e7b771ef15203edcb29d4a3f8e React-Mapbuffer: d59258be3b0d2280c6ba8964ab6e36ec69211871 - react-native-gdk: c32c6f2b309d9deefb236955e7721f8b36e7d017 + react-native-gdk: 07f19b2ab7ff72ac28a2a2db21e64266f4ab2cf0 React-nativeconfig: 4d3076dc3dc498ec49819e4e4225b55d3507f902 React-NativeModulesApple: 46f14baf36010b22ffd84fd89d5586e4148edfb3 React-perflogger: 27ccacf853ba725524ef2b4e444f14e34d0837b0 @@ -1427,8 +1327,8 @@ SPEC CHECKSUMS: React-utils: b22b4a51aa578b3aac1e7c19501c0b9ba358ed79 ReactCommon: e708b8be8cb317b83e31c6ccfeda8bf6c0d1a2b3 SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - Yoga: ff0382b894475dba0b4d2a5fda860bfee5a9afad + Yoga: 08cd7601462818c4985bda7b205b9e6a92a7e66a -PODFILE CHECKSUM: c3bf70c3e64beb3e9646a17bb26321a569363c56 +PODFILE CHECKSUM: c8067a7f65bb9bd09ea4c1d92497439e59390a44 -COCOAPODS: 1.12.0 +COCOAPODS: 1.15.2 diff --git a/example/src/App.tsx b/example/src/App.tsx index 75b0f85..e8246dd 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -13,7 +13,7 @@ const gdk = Gdk() const App: React.FunctionComponent = () => { - const [mnemonic] = React.useState(gdk.generateMnemonic12()) + const [mnemonic, setMnemonic] = React.useState(gdk.generateMnemonic12()) const [connected, setConnected] = React.useState(false) const called = React.useRef(false) @@ -50,6 +50,12 @@ const App: React.FunctionComponent = () => { mnemonic: {mnemonic} Connected: {connected ? "yes" : "no"} +