From 99931c24b924aff2d339a46c7a7ae321f288daac Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 22 Feb 2017 16:54:32 +0200 Subject: [PATCH] upgrade react-native-webview-bridge (fix preloading of js on the first page, Android) ensure that preloaded js in webview is executed only once --- package.json | 2 +- resources/web3_init.js | 18 +++++++++++++----- src/status_im/chat/views/response.cljs | 2 +- src/status_im/utils/js_resources.cljs | 8 +++++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 77847340e1..d5b00f51d8 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "react-native-tcp": "^2.0.4", "react-native-udp": "^1.2.6", "react-native-vector-icons": "^2.0.3", - "react-native-webview-bridge": "github:status-im/react-native-webview-bridge#0.33.6", + "react-native-webview-bridge": "github:status-im/react-native-webview-bridge#0.33.7", "readable-stream": "^1.0.33", "realm": "^0.14.3", "status-dev-cli": "^1.1.3", diff --git a/resources/web3_init.js b/resources/web3_init.js index 0f4e54dbc7..35fc2fe2fd 100644 --- a/resources/web3_init.js +++ b/resources/web3_init.js @@ -1,3 +1,4 @@ +if(typeof StatusHttpProvider === "undefined"){ var callbackId = 0; var callbacks = {}; @@ -103,9 +104,16 @@ StatusHttpProvider.prototype.isConnected = function () { return false; } }; - -if (window.location.protocol == "https:") { - web3 = new Web3(new StatusHttpProvider("http://localhost:8545")); -} else { - web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); +} + +var protocol = window.location.protocol +console.log(protocol); +if (typeof web3 === "undefined") { + if (protocol == "https:") { + console.log("StatusHttpProvider"); + web3 = new Web3(new StatusHttpProvider("http://localhost:8545")); + } else if (protocol == "http:") { + console.log("HttpProvider"); + web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); + } } diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 623b5d8373..63eaebdf1a 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -139,7 +139,7 @@ :source {:uri url} :render-error web-view-error :java-script-enabled true - :injected-on-start-loading-java-script (str js-res/web3 js-res/web3-init) + :injected-on-start-loading-java-script (str js-res/web3 js-res/jquery js-res/web3-init) :injected-java-script (str js-res/webview-js extra-js) :bounces false :on-navigation-state-change on-navigation-change diff --git a/src/status_im/utils/js_resources.cljs b/src/status_im/utils/js_resources.cljs index 200d7a2c5f..71656ff098 100644 --- a/src/status_im/utils/js_resources.cljs +++ b/src/status_im/utils/js_resources.cljs @@ -11,9 +11,11 @@ (def dapp-js (str (slurp "resources/dapp.js"))) (def webview-js (slurp "resources/webview.js")) -(def jquery (slurp "resources/jquery-3.1.1.min.js")) -(def web3 (str jquery - "; if (typeof Web3 == 'undefined') {" +(def jquery (str + " if (typeof jQuery2 == 'undefined') {" + (slurp "resources/jquery-3.1.1.min.js") + "}")) +(def web3 (str "; if (typeof Web3 == 'undefined') {" (slurp "resources/web3.0_16_0.min.js") "}")) (def web3-init (slurp "resources/web3_init.js"))