Skip to content

Commit

Permalink
Merge pull request #79 from functionland/completing-ios-and-trasnferT…
Browse files Browse the repository at this point in the history
…oFula

Completing ios and trasnfer to fula
  • Loading branch information
ehsan6sha authored Dec 25, 2023
2 parents 4060029 + 01ec42e commit c049800
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 4 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ dependencies {
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation 'com.github.functionland:fula-build-aar:v1.32.0' // From jitpack.io
implementation 'com.github.functionland:fula-build-aar:v1.33.0' // From jitpack.io
implementation 'com.github.functionland:wnfs-android:v1.8.1' // From jitpack.io
implementation 'commons-io:commons-io:20030203.000550'
implementation 'commons-codec:commons-codec:1.15'
Expand Down
15 changes: 15 additions & 0 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,21 @@ public void assetsBalance(String account, String assetId, String classId, Promis
});
}

@ReactMethod
public void transferToFula(String amount, String wallet, String chain, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "transferToFula called ");
try {
byte[] result = this.fula.transferToFula(amount, wallet, chain);
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
promise.reject(e);
}
});
}

@ReactMethod
public void checkAccountExists(String accountString, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Expand Down
2 changes: 1 addition & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const App = () => {
const [value, setValue] = React.useState<string>('');
const [inprogress, setInprogress] = React.useState<boolean>(false);
const [newRootCid, setNewRootCid] = React.useState<string>('');
const root_cid = 'bafyr4id2oxonbgmyg7tul53omvmb7r23et2p2bf3jzi6c2p2zmh4fyi26m';
const root_cid = 'bafyr4igvbqjrqi4ukrj4skydwpdeo4zaof5iduk7jfzdz6bd7z5wkmokwq';
const seed =
'0xmd93c00b5v99f99ti871r8r17r2rt66ee277777ge1be6fb47709b691efb0e777';

Expand Down
5 changes: 5 additions & 0 deletions ios/Fula.mm
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ @interface RCT_EXTERN_MODULE(FulaModule, NSObject)
RCT_EXTERN_METHOD(bloxFreeSpace:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(transferToFula:(NSString *)amount
wallet:(NSString *)wallet
chain:(NSString *)chain
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(eraseBlData:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

Expand Down
15 changes: 14 additions & 1 deletion ios/Fula.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,20 @@ class FulaModule: NSObject {

}

@objc(transferToFula:wallet:chain:withResolver:withRejecter:)
func transferToFula(amount: String, wallet: String, chain: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
DispatchQueue.global(qos: .default).async {
do {
print("ReactNative", "transferToFula called")
let result = try fula!.transferToFula(amount, wallet: wallet, chain: chain)
let resultString = String(data: result!, encoding: .utf8)
resolve(resultString)
} catch let error {
print("ReactNative", "transferToFula failed with Error: \(error.localizedDescription)")
reject("ERR_FULA_TRANSFER", "transferToFula failed", error)
}
}
}


@objc(getAccount:withRejecter:)
Expand Down Expand Up @@ -1273,7 +1287,6 @@ class FulaModule: NSObject {
}
}


}


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@functionland/react-native-fula",
"version": "1.32.0",
"version": "1.33.0",
"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",
Expand Down
14 changes: 14 additions & 0 deletions src/interfaces/fulaNativeModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NativeModules, Platform } from 'react-native';
import { transferToFula } from '../../.history/src/protocols/blockchain_20231223214858';

interface FulaNativeModule {
initFula: (
Expand Down Expand Up @@ -98,6 +99,7 @@ interface FulaNativeModule {
cid: string
) => Promise<string>;

//On Blox calls for chain
//Hardware
bloxFreeSpace: () => Promise<string>;
wifiRemoveall: () => Promise<string>;
Expand All @@ -109,6 +111,18 @@ interface FulaNativeModule {
assetId: string,
classId: string
) => Promise<string>;
transferToFula: (
amount: string,
wallet: string,
chain: string
) => Promise<string>;


//Hardware
bloxFreeSpace: () => Promise<string>;
wifiRemoveall: () => Promise<string>;
reboot: () => Promise<string>;
getAccount: () => Promise<string>;
}

const LINKING_ERROR =
Expand Down
27 changes: 27 additions & 0 deletions src/protocols/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,30 @@ export const assetsBalance = (
});
return res;
};

export const transferToFula = (
amount: string,
wallet: string,
chain: string
): Promise<BType.TransferToFulaResponse> => {
console.log('transferToFula in react-native started');
let res = Fula.transferToFula(amount, wallet, chain)
.then((res) => {
try {
let jsonRes: BType.TransferToFulaResponse = JSON.parse(res);
return jsonRes;
} catch (e) {
try {
return JSON.parse(res);
} catch (e1) {
console.error('Error parsing res in transferToFula:', e1);
throw e1; // Rethrow the error to maintain the rejection state
}
}
})
.catch((err) => {
console.error('Error getting transferToFula:', err);
throw err; // Rethrow the error to maintain the rejection state
});
return res;
};
5 changes: 5 additions & 0 deletions src/types/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export interface AssetsBalanceResponse {
amount: string;
}

export interface TransferToFulaResponse {
msg: string;
description: string;
}

export interface PoolJoinResponse {
account: string;
poolID: number;
Expand Down

0 comments on commit c049800

Please sign in to comment.