Skip to content

Commit c049800

Browse files
authored
Merge pull request #79 from functionland/completing-ios-and-trasnferToFula
Completing ios and trasnfer to fula
2 parents 4060029 + 01ec42e commit c049800

File tree

9 files changed

+83
-4
lines changed

9 files changed

+83
-4
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ dependencies {
9494
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
9595
//noinspection GradleDynamicVersion
9696
implementation "com.facebook.react:react-native:+"
97-
implementation 'com.github.functionland:fula-build-aar:v1.32.0' // From jitpack.io
97+
implementation 'com.github.functionland:fula-build-aar:v1.33.0' // From jitpack.io
9898
implementation 'com.github.functionland:wnfs-android:v1.8.1' // From jitpack.io
9999
implementation 'commons-io:commons-io:20030203.000550'
100100
implementation 'commons-codec:commons-codec:1.15'

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,21 @@ public void assetsBalance(String account, String assetId, String classId, Promis
11871187
});
11881188
}
11891189

1190+
@ReactMethod
1191+
public void transferToFula(String amount, String wallet, String chain, Promise promise) {
1192+
ThreadUtils.runOnExecutor(() -> {
1193+
Log.d("ReactNative", "transferToFula called ");
1194+
try {
1195+
byte[] result = this.fula.transferToFula(amount, wallet, chain);
1196+
String resultString = toString(result);
1197+
promise.resolve(resultString);
1198+
} catch (Exception e) {
1199+
Log.d("ReactNative", e.getMessage());
1200+
promise.reject(e);
1201+
}
1202+
});
1203+
}
1204+
11901205
@ReactMethod
11911206
public void checkAccountExists(String accountString, Promise promise) {
11921207
ThreadUtils.runOnExecutor(() -> {

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const App = () => {
1313
const [value, setValue] = React.useState<string>('');
1414
const [inprogress, setInprogress] = React.useState<boolean>(false);
1515
const [newRootCid, setNewRootCid] = React.useState<string>('');
16-
const root_cid = 'bafyr4id2oxonbgmyg7tul53omvmb7r23et2p2bf3jzi6c2p2zmh4fyi26m';
16+
const root_cid = 'bafyr4igvbqjrqi4ukrj4skydwpdeo4zaof5iduk7jfzdz6bd7z5wkmokwq';
1717
const seed =
1818
'0xmd93c00b5v99f99ti871r8r17r2rt66ee277777ge1be6fb47709b691efb0e777';
1919

ios/Fula.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ @interface RCT_EXTERN_MODULE(FulaModule, NSObject)
189189
RCT_EXTERN_METHOD(bloxFreeSpace:(RCTPromiseResolveBlock)resolve
190190
withRejecter:(RCTPromiseRejectBlock)reject)
191191

192+
RCT_EXTERN_METHOD(transferToFula:(NSString *)amount
193+
wallet:(NSString *)wallet
194+
chain:(NSString *)chain
195+
withResolver:(RCTPromiseResolveBlock)resolve
196+
withRejecter:(RCTPromiseRejectBlock)reject)
192197
RCT_EXTERN_METHOD(eraseBlData:(RCTPromiseResolveBlock)resolve
193198
withRejecter:(RCTPromiseRejectBlock)reject)
194199

ios/Fula.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,20 @@ class FulaModule: NSObject {
11761176

11771177
}
11781178

1179+
@objc(transferToFula:wallet:chain:withResolver:withRejecter:)
1180+
func transferToFula(amount: String, wallet: String, chain: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
1181+
DispatchQueue.global(qos: .default).async {
1182+
do {
1183+
print("ReactNative", "transferToFula called")
1184+
let result = try fula!.transferToFula(amount, wallet: wallet, chain: chain)
1185+
let resultString = String(data: result!, encoding: .utf8)
1186+
resolve(resultString)
1187+
} catch let error {
1188+
print("ReactNative", "transferToFula failed with Error: \(error.localizedDescription)")
1189+
reject("ERR_FULA_TRANSFER", "transferToFula failed", error)
1190+
}
1191+
}
1192+
}
11791193

11801194

11811195
@objc(getAccount:withRejecter:)
@@ -1273,7 +1287,6 @@ class FulaModule: NSObject {
12731287
}
12741288
}
12751289

1276-
12771290
}
12781291

12791292

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.32.0",
3+
"version": "1.33.0",
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { NativeModules, Platform } from 'react-native';
2+
import { transferToFula } from '../../.history/src/protocols/blockchain_20231223214858';
23

34
interface FulaNativeModule {
45
initFula: (
@@ -98,6 +99,7 @@ interface FulaNativeModule {
9899
cid: string
99100
) => Promise<string>;
100101

102+
//On Blox calls for chain
101103
//Hardware
102104
bloxFreeSpace: () => Promise<string>;
103105
wifiRemoveall: () => Promise<string>;
@@ -109,6 +111,18 @@ interface FulaNativeModule {
109111
assetId: string,
110112
classId: string
111113
) => Promise<string>;
114+
transferToFula: (
115+
amount: string,
116+
wallet: string,
117+
chain: string
118+
) => Promise<string>;
119+
120+
121+
//Hardware
122+
bloxFreeSpace: () => Promise<string>;
123+
wifiRemoveall: () => Promise<string>;
124+
reboot: () => Promise<string>;
125+
getAccount: () => Promise<string>;
112126
}
113127

114128
const LINKING_ERROR =

src/protocols/blockchain.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,30 @@ export const assetsBalance = (
547547
});
548548
return res;
549549
};
550+
551+
export const transferToFula = (
552+
amount: string,
553+
wallet: string,
554+
chain: string
555+
): Promise<BType.TransferToFulaResponse> => {
556+
console.log('transferToFula in react-native started');
557+
let res = Fula.transferToFula(amount, wallet, chain)
558+
.then((res) => {
559+
try {
560+
let jsonRes: BType.TransferToFulaResponse = JSON.parse(res);
561+
return jsonRes;
562+
} catch (e) {
563+
try {
564+
return JSON.parse(res);
565+
} catch (e1) {
566+
console.error('Error parsing res in transferToFula:', e1);
567+
throw e1; // Rethrow the error to maintain the rejection state
568+
}
569+
}
570+
})
571+
.catch((err) => {
572+
console.error('Error getting transferToFula:', err);
573+
throw err; // Rethrow the error to maintain the rejection state
574+
});
575+
return res;
576+
};

src/types/blockchain.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export interface AssetsBalanceResponse {
2121
amount: string;
2222
}
2323

24+
export interface TransferToFulaResponse {
25+
msg: string;
26+
description: string;
27+
}
28+
2429
export interface PoolJoinResponse {
2530
account: string;
2631
poolID: number;

0 commit comments

Comments
 (0)