Skip to content

Commit 4e2b8c6

Browse files
authored
Merge pull request #84 from functionland/partition-command
added partition command
2 parents 45f1d94 + cc4731d commit 4e2b8c6

8 files changed

Lines changed: 93 additions & 5 deletions

File tree

‎android/src/main/java/land/fx/fula/FulaModule.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,22 @@ public void reboot(Promise promise) {
15221522
});
15231523
}
15241524

1525+
@ReactMethod
1526+
public void partition(Promise promise) {
1527+
ThreadUtils.runOnExecutor(() -> {
1528+
Log.d("ReactNative", "partition");
1529+
try {
1530+
byte[] result = this.fula.partition();
1531+
String resultString = toString(result);
1532+
Log.d("ReactNative", "result string="+resultString);
1533+
promise.resolve(resultString);
1534+
} catch (Exception e) {
1535+
Log.d("ReactNative", e.getMessage());
1536+
promise.reject(e);
1537+
}
1538+
});
1539+
}
1540+
15251541
@ReactMethod
15261542
public void eraseBlData(Promise promise) {
15271543
ThreadUtils.runOnExecutor(() -> {

‎example/src/App.tsx‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ const App = () => {
6767
153, 106, 217, 201, 106, 9, 66, 33, 214, 195, 255, 234, 178, 244, 203, 112,
6868
62, 91, 140, 55, 179, 10, 208, 210, 177, 111, 61, 46, 73, 148, 14, 62,
6969
];
70-
//const bloxPeerId = '12D3KooWDiBNebfFD4QwJ1qDZaeapKcbr72cJfHE8foooTX25Z1V'; //tower
71-
const bloxPeerId = '12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK78Q'; //laptop
70+
const bloxPeerId = '12D3KooWACVcVsQh18jM9UudRQzeYEjxCJQJgFUaAgs41tayjxC4'; //tower
71+
// const bloxPeerId = '12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK78Q'; //laptop
7272
// const bloxPeerId = '12D3KooWQZBdE5zNUVTE2Aayajyy9cJDmK4bJwMZG52ieHt2f6nb'; //laptop2
7373
//const bloxPeerId = '12D3KooWAN5FaAnC4d1GhAvoYxyUXdrkCGqux1NB6Pr4cZXn813E'; //test aws server
7474

75-
const bloxAddr = '/dns/delta-relay.dev.fx.land/tcp/4001/p2p/12D3KooWDtA7kecHAGEB8XYEKHBUTt8GsRfMen1yMs7V85vrpMzC/p2p-circuit/p2p/' + bloxPeerId;
76-
//const bloxAddr = '/ip4/192.168.2.14/tcp/40001/p2p/' + bloxPeerId;
75+
// const bloxAddr = '/dns/delta-relay.dev.fx.land/tcp/4001/p2p/12D3KooWDtA7kecHAGEB8XYEKHBUTt8GsRfMen1yMs7V85vrpMzC/p2p-circuit/p2p/' + bloxPeerId;
76+
const bloxAddr = '/ip4/192.168.2.88/tcp/40001/p2p/' + bloxPeerId;
7777

7878
const initFula = async () => {
7979
try {
@@ -721,6 +721,38 @@ const App = () => {
721721
color={inprogress ? 'green' : 'blue'}
722722
/>
723723

724+
<Button
725+
title={inprogress ? 'Getting...' : 'Partition'}
726+
onPress={async () => {
727+
try {
728+
if (initComplete) {
729+
fula.checkConnection().then((r: any) => {
730+
console.log('connection check');
731+
console.log(r);
732+
if (r) {
733+
console.log(
734+
'initialization is completed. send partition command'
735+
);
736+
fxblox
737+
.partition()
738+
.then((res: any) => {
739+
console.log('partition received');
740+
console.log(res);
741+
})
742+
.catch((e: any) => {
743+
console.log('partition failed');
744+
console.log(e);
745+
});
746+
}
747+
});
748+
} else {
749+
console.log('wait for init to complete');
750+
}
751+
} catch (e) {}
752+
}}
753+
color={inprogress ? 'green' : 'blue'}
754+
/>
755+
724756
<Button
725757
title={inprogress ? 'Putting & Getting...' : 'List Pools'}
726758
onPress={async () => {

‎ios/Fula.mm‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ @interface RCT_EXTERN_MODULE(FulaModule, NSObject)
158158

159159
RCT_EXTERN_METHOD(reboot:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
160160

161+
RCT_EXTERN_METHOD(partition:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
162+
161163
RCT_EXTERN_METHOD(assetsBalance:(NSString *)account withAssetId:(NSString *)assetId withClassId:(NSString *)classId withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
162164

163165
RCT_EXTERN_METHOD(getAccount:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)

‎ios/Fula.swift‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,18 @@ class FulaModule: NSObject {
12861286
}
12871287
}
12881288

1289+
@objc(partition:withRejecter:)
1290+
func partition(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
1291+
do {
1292+
let result = try fula!.partition()
1293+
let resultString = result.toUTF8String()!
1294+
resolve(resultString)
1295+
} catch let error {
1296+
print("partition", error.localizedDescription)
1297+
reject("ERR_FULA", "partition", error)
1298+
}
1299+
}
1300+
12891301
@objc(wifiRemoveall:withRejecter:)
12901302
func wifiRemoveall(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
12911303
do {

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@functionland/react-native-fula",
3-
"version": "1.44.1",
3+
"version": "1.44.2",
44
"description": "This package is a bridge to use the Fula libp2p protocols in the react-native which is using wnfs",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

‎src/interfaces/fulaNativeModule.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ interface FulaNativeModule {
123123
bloxFreeSpace: () => Promise<string>;
124124
wifiRemoveall: () => Promise<string>;
125125
reboot: () => Promise<string>;
126+
partition: () => Promise<string>;
126127
}
127128

128129
const LINKING_ERROR =

‎src/protocols/fxblox.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ export const reboot = (): Promise<BType.rebootResponse> => {
4848
return res2;
4949
};
5050

51+
export const partition = (): Promise<BType.partitionResponse> => {
52+
console.log('partition in react-native started');
53+
let res2 = Fula.partition()
54+
.then((res) => {
55+
try {
56+
let jsonRes: BType.partitionResponse = JSON.parse(res);
57+
return jsonRes;
58+
} catch (e) {
59+
try {
60+
return JSON.parse(res);
61+
} catch (e2) {
62+
return res;
63+
}
64+
}
65+
})
66+
.catch((err) => {
67+
return err;
68+
});
69+
return res2;
70+
};
71+
5172
export const eraseBlData = (): Promise<BType.rebootResponse> => {
5273
console.log('eraseBlData in react-native started');
5374
let res2 = Fula.eraseBlData()

‎src/types/fxblox.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export interface rebootResponse {
66
status: boolean;
77
msg: string;
88
}
9+
export interface partitionResponse {
10+
status: boolean;
11+
msg: string;
12+
}
913

1014
export interface eraseBlDataResponse {
1115
status: boolean;

0 commit comments

Comments
 (0)