utilise CallRPC in react-native-status module

This commit is contained in:
Roman Volosovskyi 2017-08-01 21:42:16 +03:00
parent 6d62a21af7
commit 0ada614d62
8 changed files with 15 additions and 74 deletions

View File

@ -15,5 +15,5 @@ android {
dependencies {
compile 'com.facebook.react:react-native:+'
compile 'com.instabug.library:instabug:3+'
compile(group: 'status-im', name: 'status-go', version: 'whisper-on-geth1.6.1', ext: 'aar')
compile(group: 'status-im', name: 'status-go', version: 'bug-whisper-on-geth1.6.1-g3f6f0fa+', ext: 'aar')
}

View File

@ -38,7 +38,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
private ServiceConnector status = null;
private ExecutorService executor = null;
private boolean debug;
private Web3Bridge w3Bridge = new Web3Bridge();
StatusModule(ReactApplicationContext reactContext, boolean debug) {
super(reactContext);
@ -294,7 +293,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
return;
}
this.w3Bridge = new Web3Bridge();
Thread thread = new Thread() {
@Override
public void run() {
@ -596,7 +594,8 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
Thread thread = new Thread() {
@Override
public void run() {
w3Bridge.sendRequest(host, payload, callback);
String res = Statusgo.CallRPC(payload);
callback.invoke(res);
}
};

View File

@ -1,36 +0,0 @@
package im.status.ethereum.module;
import android.os.Build;
import com.facebook.react.bridge.Callback;
import okhttp3.*;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class Web3Bridge {
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
private OkHttpClient client;
public Web3Bridge() {
OkHttpClient.Builder b = new OkHttpClient.Builder();
b.readTimeout(310, TimeUnit.SECONDS);
client = b.build();
}
public void sendRequest(final String host, final String json, final Callback callback) {
RequestBody body = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.url(host)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
String rpcResponse = response.body().string().trim();
callback.invoke(rpcResponse);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -400,32 +400,12 @@ RCT_EXPORT_METHOD(clearStorageAPIs) {
RCT_EXPORT_METHOD(sendWeb3Request:(NSString *)host
password:(NSString *)payload
callback:(RCTResponseSenderBlock)callback) {
NSData *postData = [payload dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:host]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[request setTimeoutInterval:310];
NSError *error;
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString *strResponse = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *trimmedResponse = [strResponse stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
callback(@[trimmedResponse]);
}];
[postDataTask resume];
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
char * result = CallRPC((char *) [payload UTF8String]);
dispatch_async( dispatch_get_main_queue(), ^{
callback(@[[NSString stringWithUTF8String: result]]);
});
});
}

View File

@ -25,7 +25,7 @@
<artifactItem>
<groupId>status-im</groupId>
<artifactId>status-go-ios-simulator</artifactId>
<version>whisper-on-geth1.6.1</version>
<version>bug-whisper-on-geth1.6.1-g3f6f0fa+</version>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>./</outputDirectory>

4
package-lock.json generated
View File

@ -4791,7 +4791,7 @@
"integrity": "sha1-dELADh/Nn8oykRncuvdE0SvNG1o="
},
"react-native-mapbox-gl": {
"version": "github:mapbox/react-native-mapbox-gl#64a51561d21cc2f5538afad1c0618219286db3b3",
"version": "github:mapbox/react-native-mapbox-gl#5a1983ac9c5c6ce985f0f987928eeefe017ae0c5",
"requires": {
"babel-eslint": "6.1.2",
"lodash": "4.17.4"
@ -4916,7 +4916,7 @@
}
},
"react-native-webview-bridge": {
"version": "github:status-im/react-native-webview-bridge#fd3fff1783854b713e56dcad235dc8b2988a5012",
"version": "github:status-im/react-native-webview-bridge#6e46b3c931c6d3c0c76507ee512b419ecb85973c",
"requires": {
"invariant": "2.2.0",
"keymirror": "0.1.1"

View File

@ -76,7 +76,7 @@
"react-native-tcp": "^3.2.1",
"react-native-udp": "^2.0.0",
"react-native-vector-icons": "^4.0.1",
"react-native-webview-bridge": "github:status-im/react-native-webview-bridge#0.33.14",
"react-native-webview-bridge": "github:status-im/react-native-webview-bridge#0.33.15",
"readable-stream": "1.0.33",
"realm": "^0.14.3",
"stream-browserify": "^1.0.0",

View File

@ -188,12 +188,10 @@
(register-handler :app-state-change
(u/side-effect!
(fn [{:keys [webview-bridge] :as db} [_ state]]
(fn [db [_ state]]
(case state
"background" (status/stop-rpc-server)
"active" (do (status/start-rpc-server)
(when webview-bridge
(.resetOkHttpClient webview-bridge)))
"active" (status/start-rpc-server)
nil))))
(register-handler :request-permissions