mirror of
https://github.com/status-im/status-mobile.git
synced 2025-02-25 06:46:37 +00:00
* Switching networks (#845) * pass RPC host to webview bridge
This commit is contained in:
parent
e7926c8b37
commit
874bf16f97
@ -70,6 +70,7 @@ var TopLevel = {
|
|||||||
"getCardId" : function () {},
|
"getCardId" : function () {},
|
||||||
"getExample" : function () {},
|
"getExample" : function () {},
|
||||||
"getInitialOrientation" : function () {},
|
"getInitialOrientation" : function () {},
|
||||||
|
"getIPAddress" : function () {},
|
||||||
"getLayout" : function () {},
|
"getLayout" : function () {},
|
||||||
"getNumber" : function () {},
|
"getNumber" : function () {},
|
||||||
"getSyncing" : function () {},
|
"getSyncing" : function () {},
|
||||||
|
@ -73,7 +73,7 @@
|
|||||||
"react-native-tcp": "^2.0.4",
|
"react-native-tcp": "^2.0.4",
|
||||||
"react-native-udp": "^1.2.6",
|
"react-native-udp": "^1.2.6",
|
||||||
"react-native-vector-icons": "^2.0.3",
|
"react-native-vector-icons": "^2.0.3",
|
||||||
"react-native-webview-bridge": "github:status-im/react-native-webview-bridge#0.33.7",
|
"react-native-webview-bridge": "github:status-im/react-native-webview-bridge#0.33.8",
|
||||||
"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",
|
||||||
|
@ -46,7 +46,7 @@ StatusHttpProvider.prototype.send = function (payload) {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
result = StatusBridge.sendRequestSync(JSON.stringify(payload));
|
result = StatusBridge.sendRequestSync(this.host, JSON.stringify(payload));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = JSON.parse(result);
|
result = JSON.parse(result);
|
||||||
@ -61,7 +61,7 @@ StatusHttpProvider.prototype.send = function (payload) {
|
|||||||
StatusHttpProvider.prototype.prepareRequest = function () {
|
StatusHttpProvider.prototype.prepareRequest = function () {
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
|
|
||||||
request.open('POST', "http://localhost:8545", false);
|
request.open('POST', this.host, false);
|
||||||
request.setRequestHeader('Content-Type', 'application/json');
|
request.setRequestHeader('Content-Type', 'application/json');
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
@ -73,12 +73,13 @@ function sendAsync(payload, callback) {
|
|||||||
if (typeof StatusBridge == "undefined") {
|
if (typeof StatusBridge == "undefined") {
|
||||||
var data = {
|
var data = {
|
||||||
payload: JSON.stringify(payload),
|
payload: JSON.stringify(payload),
|
||||||
callbackId: JSON.stringify(messageId)
|
callbackId: JSON.stringify(messageId),
|
||||||
|
host: this.host
|
||||||
};
|
};
|
||||||
|
|
||||||
webkit.messageHandlers.sendRequest.postMessage(JSON.stringify(data));
|
webkit.messageHandlers.sendRequest.postMessage(JSON.stringify(data));
|
||||||
} else {
|
} else {
|
||||||
StatusBridge.sendRequest(JSON.stringify(messageId), JSON.stringify(payload));
|
StatusBridge.sendRequest(this.host, JSON.stringify(messageId), JSON.stringify(payload));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -107,13 +108,14 @@ StatusHttpProvider.prototype.isConnected = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var protocol = window.location.protocol
|
var protocol = window.location.protocol
|
||||||
|
var address = providerAddress || "http://localhost:8545";
|
||||||
console.log(protocol);
|
console.log(protocol);
|
||||||
if (typeof web3 === "undefined") {
|
if (typeof web3 === "undefined") {
|
||||||
if (protocol == "https:") {
|
if (protocol == "https:") {
|
||||||
console.log("StatusHttpProvider");
|
console.log("StatusHttpProvider");
|
||||||
web3 = new Web3(new StatusHttpProvider("http://localhost:8545"));
|
web3 = new Web3(new StatusHttpProvider(address));
|
||||||
} else if (protocol == "http:") {
|
} else if (protocol == "http:") {
|
||||||
console.log("HttpProvider");
|
console.log("HttpProvider");
|
||||||
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
|
web3 = new Web3(new Web3.providers.HttpProvider(address));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,8 @@
|
|||||||
|
|
||||||
(defview suggestions-web-view []
|
(defview suggestions-web-view []
|
||||||
[url [:web-view-url]
|
[url [:web-view-url]
|
||||||
extra-js [:web-view-extra-js]]
|
extra-js [:web-view-extra-js]
|
||||||
|
rpc-url [:get :rpc-url]]
|
||||||
(when url
|
(when url
|
||||||
[webview-bridge
|
[webview-bridge
|
||||||
{:ref #(dispatch [:set-webview-bridge %])
|
{:ref #(dispatch [:set-webview-bridge %])
|
||||||
@ -139,7 +140,9 @@
|
|||||||
:source {:uri url}
|
:source {:uri url}
|
||||||
:render-error web-view-error
|
:render-error web-view-error
|
||||||
:java-script-enabled true
|
:java-script-enabled true
|
||||||
:injected-on-start-loading-java-script (str js-res/web3 js-res/jquery js-res/web3-init)
|
:injected-on-start-loading-java-script (str js-res/web3
|
||||||
|
js-res/jquery
|
||||||
|
(js-res/web3-init rpc-url))
|
||||||
:injected-java-script (str js-res/webview-js extra-js)
|
:injected-java-script (str js-res/webview-js extra-js)
|
||||||
:bounces false
|
:bounces false
|
||||||
:on-navigation-state-change on-navigation-change
|
:on-navigation-state-change on-navigation-change
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
"/add-dapp" (dispatch [:debug-add-dapp obj])
|
"/add-dapp" (dispatch [:debug-add-dapp obj])
|
||||||
"/remove-dapp" (dispatch [:debug-remove-dapp obj])
|
"/remove-dapp" (dispatch [:debug-remove-dapp obj])
|
||||||
"/dapp-changed" (dispatch [:debug-dapp-changed obj])
|
"/dapp-changed" (dispatch [:debug-dapp-changed obj])
|
||||||
|
"/switch-node" (dispatch [:debug-switch-node obj])
|
||||||
:default))
|
:default))
|
||||||
(catch js/Error e
|
(catch js/Error e
|
||||||
(log/debug "Error: " e))))))
|
(log/debug "Error: " e))))))
|
||||||
@ -80,3 +81,8 @@
|
|||||||
webview-bridge)
|
webview-bridge)
|
||||||
(.reload webview-bridge)))))
|
(.reload webview-bridge)))))
|
||||||
|
|
||||||
|
(register-handler :debug-switch-node
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [{:keys [current-account-id]} [_ {:keys [url]}]]
|
||||||
|
(dispatch [:initialize-protocol current-account-id url]))))
|
||||||
|
|
||||||
|
@ -21,37 +21,39 @@
|
|||||||
[status-im.utils.scheduler :as s]))
|
[status-im.utils.scheduler :as s]))
|
||||||
|
|
||||||
(register-handler :initialize-protocol
|
(register-handler :initialize-protocol
|
||||||
(fn [db [_ current-account-id]]
|
(fn [db [_ current-account-id ethereum-rpc-url]]
|
||||||
(let [{:keys [public-key status updates-public-key
|
(let [{:keys [public-key status updates-public-key
|
||||||
updates-private-key]}
|
updates-private-key]}
|
||||||
(get-in db [:accounts current-account-id])]
|
(get-in db [:accounts current-account-id])]
|
||||||
(if public-key
|
(if public-key
|
||||||
(let [groups (chats/get-active-group-chats)
|
(let [rpc-url (or ethereum-rpc-url c/ethereum-rpc-url)
|
||||||
w3 (protocol/init-whisper!
|
groups (chats/get-active-group-chats)
|
||||||
{:rpc-url c/ethereum-rpc-url
|
w3 (protocol/init-whisper!
|
||||||
:identity public-key
|
{:rpc-url rpc-url
|
||||||
:groups groups
|
:identity public-key
|
||||||
:callback #(dispatch [:incoming-message %1 %2])
|
:groups groups
|
||||||
:ack-not-received-s-interval 125
|
:callback #(dispatch [:incoming-message %1 %2])
|
||||||
:default-ttl 120
|
:ack-not-received-s-interval 125
|
||||||
:send-online-s-interval 180
|
:default-ttl 120
|
||||||
:ttl-config {:public-group-message 2400}
|
:send-online-s-interval 180
|
||||||
:max-attempts-number 3
|
:ttl-config {:public-group-message 2400}
|
||||||
:delivery-loop-ms-interval 500
|
:max-attempts-number 3
|
||||||
:profile-keypair {:public updates-public-key
|
:delivery-loop-ms-interval 500
|
||||||
:private updates-private-key}
|
:profile-keypair {:public updates-public-key
|
||||||
:hashtags (u/get-hashtags status)
|
:private updates-private-key}
|
||||||
:pending-messages (pending-messages/get-all)
|
:hashtags (u/get-hashtags status)
|
||||||
:contacts (keep (fn [{:keys [whisper-identity
|
:pending-messages (pending-messages/get-all)
|
||||||
public-key
|
:contacts (keep (fn [{:keys [whisper-identity
|
||||||
private-key]}]
|
public-key
|
||||||
(when (and public-key private-key)
|
private-key]}]
|
||||||
{:identity whisper-identity
|
(when (and public-key private-key)
|
||||||
:keypair {:public public-key
|
{:identity whisper-identity
|
||||||
:private private-key}}))
|
:keypair {:public public-key
|
||||||
(contacts/get-all))
|
:private private-key}}))
|
||||||
:post-error-callback #(dispatch [::post-error %])})]
|
(contacts/get-all))
|
||||||
(assoc db :web3 w3))
|
:post-error-callback #(dispatch [::post-error %])})]
|
||||||
|
(assoc db :web3 w3
|
||||||
|
:rpc-url rpc-url))
|
||||||
db))))
|
db))))
|
||||||
|
|
||||||
(register-handler :update-sync-state
|
(register-handler :update-sync-state
|
||||||
|
@ -18,4 +18,6 @@
|
|||||||
(def web3 (str "; if (typeof Web3 == 'undefined') {"
|
(def web3 (str "; if (typeof Web3 == 'undefined') {"
|
||||||
(slurp "resources/web3.0_16_0.min.js")
|
(slurp "resources/web3.0_16_0.min.js")
|
||||||
"}"))
|
"}"))
|
||||||
(def web3-init (slurp "resources/web3_init.js"))
|
(defn web3-init [provider-address]
|
||||||
|
(str "var providerAddress = \"" provider-address "\";"
|
||||||
|
(slurp "resources/web3_init.js")))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user