mirror of
https://github.com/status-im/status-mobile.git
synced 2025-02-03 04:14:02 +00:00
utilise CallRPC in react-native-status module
This commit is contained in:
parent
6d62a21af7
commit
0ada614d62
@ -15,5 +15,5 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.facebook.react:react-native:+'
|
compile 'com.facebook.react:react-native:+'
|
||||||
compile 'com.instabug.library:instabug:3+'
|
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')
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
|
|||||||
private ServiceConnector status = null;
|
private ServiceConnector status = null;
|
||||||
private ExecutorService executor = null;
|
private ExecutorService executor = null;
|
||||||
private boolean debug;
|
private boolean debug;
|
||||||
private Web3Bridge w3Bridge = new Web3Bridge();
|
|
||||||
|
|
||||||
StatusModule(ReactApplicationContext reactContext, boolean debug) {
|
StatusModule(ReactApplicationContext reactContext, boolean debug) {
|
||||||
super(reactContext);
|
super(reactContext);
|
||||||
@ -294,7 +293,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.w3Bridge = new Web3Bridge();
|
|
||||||
Thread thread = new Thread() {
|
Thread thread = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -596,7 +594,8 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
|
|||||||
Thread thread = new Thread() {
|
Thread thread = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
w3Bridge.sendRequest(host, payload, callback);
|
String res = Statusgo.CallRPC(payload);
|
||||||
|
callback.invoke(res);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -400,32 +400,12 @@ RCT_EXPORT_METHOD(clearStorageAPIs) {
|
|||||||
RCT_EXPORT_METHOD(sendWeb3Request:(NSString *)host
|
RCT_EXPORT_METHOD(sendWeb3Request:(NSString *)host
|
||||||
password:(NSString *)payload
|
password:(NSString *)payload
|
||||||
callback:(RCTResponseSenderBlock)callback) {
|
callback:(RCTResponseSenderBlock)callback) {
|
||||||
|
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
NSData *postData = [payload dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
|
char * result = CallRPC((char *) [payload UTF8String]);
|
||||||
|
dispatch_async( dispatch_get_main_queue(), ^{
|
||||||
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
|
callback(@[[NSString stringWithUTF8String: result]]);
|
||||||
|
});
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>status-im</groupId>
|
<groupId>status-im</groupId>
|
||||||
<artifactId>status-go-ios-simulator</artifactId>
|
<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>
|
<type>zip</type>
|
||||||
<overWrite>true</overWrite>
|
<overWrite>true</overWrite>
|
||||||
<outputDirectory>./</outputDirectory>
|
<outputDirectory>./</outputDirectory>
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -4791,7 +4791,7 @@
|
|||||||
"integrity": "sha1-dELADh/Nn8oykRncuvdE0SvNG1o="
|
"integrity": "sha1-dELADh/Nn8oykRncuvdE0SvNG1o="
|
||||||
},
|
},
|
||||||
"react-native-mapbox-gl": {
|
"react-native-mapbox-gl": {
|
||||||
"version": "github:mapbox/react-native-mapbox-gl#64a51561d21cc2f5538afad1c0618219286db3b3",
|
"version": "github:mapbox/react-native-mapbox-gl#5a1983ac9c5c6ce985f0f987928eeefe017ae0c5",
|
||||||
"requires": {
|
"requires": {
|
||||||
"babel-eslint": "6.1.2",
|
"babel-eslint": "6.1.2",
|
||||||
"lodash": "4.17.4"
|
"lodash": "4.17.4"
|
||||||
@ -4916,7 +4916,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"react-native-webview-bridge": {
|
"react-native-webview-bridge": {
|
||||||
"version": "github:status-im/react-native-webview-bridge#fd3fff1783854b713e56dcad235dc8b2988a5012",
|
"version": "github:status-im/react-native-webview-bridge#6e46b3c931c6d3c0c76507ee512b419ecb85973c",
|
||||||
"requires": {
|
"requires": {
|
||||||
"invariant": "2.2.0",
|
"invariant": "2.2.0",
|
||||||
"keymirror": "0.1.1"
|
"keymirror": "0.1.1"
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
"react-native-tcp": "^3.2.1",
|
"react-native-tcp": "^3.2.1",
|
||||||
"react-native-udp": "^2.0.0",
|
"react-native-udp": "^2.0.0",
|
||||||
"react-native-vector-icons": "^4.0.1",
|
"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",
|
"readable-stream": "1.0.33",
|
||||||
"realm": "^0.14.3",
|
"realm": "^0.14.3",
|
||||||
"stream-browserify": "^1.0.0",
|
"stream-browserify": "^1.0.0",
|
||||||
|
@ -188,12 +188,10 @@
|
|||||||
|
|
||||||
(register-handler :app-state-change
|
(register-handler :app-state-change
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [webview-bridge] :as db} [_ state]]
|
(fn [db [_ state]]
|
||||||
(case state
|
(case state
|
||||||
"background" (status/stop-rpc-server)
|
"background" (status/stop-rpc-server)
|
||||||
"active" (do (status/start-rpc-server)
|
"active" (status/start-rpc-server)
|
||||||
(when webview-bridge
|
|
||||||
(.resetOkHttpClient webview-bridge)))
|
|
||||||
nil))))
|
nil))))
|
||||||
|
|
||||||
(register-handler :request-permissions
|
(register-handler :request-permissions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user