From 80b587c7a3c66bdc7e362cd103bcc0a2a1ddf495 Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Tue, 3 Jan 2023 09:41:28 -0500 Subject: [PATCH] Added WNFS check to isReady --- README.md | 4 +++- android/src/main/java/land/fx/fula/FulaModule.java | 10 ++++++++-- example/src/App.tsx | 5 +++-- src/interfaces/fulaNativeModule.ts | 2 +- src/protocols/fula.ts | 4 ++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5ae0ae6..5c2058b 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,9 @@ await fula.mv( //checks if fula is ready (initialized through newClient or init) const result //returns true if succesful and false if fails = -await fula.isReady(); +await fula.isReady( + filesystemCheck: boolean //Default is true. If true it checks if both WNFS and Fula are ready. If false it only checks fula +); ``` diff --git a/android/src/main/java/land/fx/fula/FulaModule.java b/android/src/main/java/land/fx/fula/FulaModule.java index fb1fab2..ba52be6 100755 --- a/android/src/main/java/land/fx/fula/FulaModule.java +++ b/android/src/main/java/land/fx/fula/FulaModule.java @@ -188,13 +188,19 @@ public void newClient(String identityString, String storePath, String bloxAddr, } @ReactMethod - public void isReady(Promise promise) { + public void isReady(boolean filesystemCheck, Promise promise) { Log.d("ReactNative", "isReady started"); ThreadUtils.runOnExecutor(() -> { boolean initialized = false; try { if (this.fula != null && this.fula.id() != null) { - initialized = true; + if (filesystemCheck) { + if (this.client != null && this.rootConfig != null && !this.rootConfig.getCid().isEmpty()) { + initialized = true; + } + } else { + initialized = true; + } } promise.resolve(initialized); } catch (Exception e) { diff --git a/example/src/App.tsx b/example/src/App.tsx index ba304c5..643c23e 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -37,12 +37,13 @@ const App = () => { 94, 225, 7, 153, 168, 239, 94, 7, 187, 123, 158, 149, 149, 227, 170, 32, 54, 203, 243, 211, 78, 120, 114, 199, 1, 197, 134, 6, 91, 87, 152, ]; + const bloxAddr = '/dns/relay.dev.fx.land/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit/p2p/12D3KooWR2EiA8DbULqDAJZCcN2V2Nasmh756R1aLe5t3NniCnAS'; const newClient = async () => { try { return fula.newClient( privateKey.toString(), '', - '/ip4/192.168.2.14/tcp/40001/p2p/12D3KooWBdzmgXe9uyYoxaeLLKTLWM7mG3ZtBiKHAnSVxtrVJc2A', + bloxAddr, '' ); } catch (e) { @@ -55,7 +56,7 @@ const App = () => { return fula.init( privateKey.toString(), '', - '/ip4/192.168.2.14/tcp/40001/p2p/12D3KooWBdzmgXe9uyYoxaeLLKTLWM7mG3ZtBiKHAnSVxtrVJc2A', + bloxAddr, '' ); } catch (e) { diff --git a/src/interfaces/fulaNativeModule.ts b/src/interfaces/fulaNativeModule.ts index 68cc5f1..bddf4b0 100644 --- a/src/interfaces/fulaNativeModule.ts +++ b/src/interfaces/fulaNativeModule.ts @@ -16,7 +16,7 @@ interface FulaNativeModule { exchange: string, //set to 'noope' for testing autoFlush: boolean //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write ) => Promise; - isReady: () => Promise; + isReady: (filesystemCheck: boolean) => Promise; logout: (identity: string, storePath: string) => Promise; checkFailedActions: (retry: boolean) => Promise; checkConnection: () => Promise; diff --git a/src/protocols/fula.ts b/src/protocols/fula.ts index bd6adb8..1e81537 100644 --- a/src/protocols/fula.ts +++ b/src/protocols/fula.ts @@ -259,6 +259,6 @@ export const shutdown = (): Promise => { * @param path * @returns string: new cid of the root */ -export const isReady = (): Promise => { - return Fula.isReady(); +export const isReady = (filesystemCheck: boolean = true): Promise => { + return Fula.isReady(filesystemCheck); };