Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
68997983e5
commit
fc72443754
|
@ -22,39 +22,23 @@ var StatusHttpProvider = function (host, timeout) {
|
||||||
this.timeout = timeout || 0;
|
this.timeout = timeout || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function syncResponse(payload, result){
|
||||||
|
return {id: payload.id,
|
||||||
|
jsonrpc: "2.0",
|
||||||
|
result: result};
|
||||||
|
}
|
||||||
|
|
||||||
StatusHttpProvider.prototype.send = function (payload) {
|
StatusHttpProvider.prototype.send = function (payload) {
|
||||||
if (typeof StatusBridge == "undefined") {
|
//TODO to be compatible with MM https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#dizzy-all-async---think-of-metamask-as-a-light-client
|
||||||
if (window.location.protocol == "https:") {
|
if (payload.method == "eth_accounts"){
|
||||||
throw new Error('You tried to send "' + payload.method + '" synchronously. Synchronous requests are not supported, sorry.');
|
return syncResponse(payload, [currentAccountAddress])
|
||||||
}
|
} else if (payload.method == "eth_coinbase"){
|
||||||
|
return syncResponse(payload, currentAccountAddress)
|
||||||
var request = this.prepareRequest(false);
|
} else if (payload.method == "net_version"){
|
||||||
|
return syncResponse(payload, networkId)
|
||||||
try {
|
|
||||||
request.send(JSON.stringify(payload));
|
|
||||||
} catch (error) {
|
|
||||||
throw errors.InvalidConnection(this.host);
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = request.responseText;
|
|
||||||
|
|
||||||
try {
|
|
||||||
result = JSON.parse(result);
|
|
||||||
} catch (e) {
|
|
||||||
throw errors.InvalidResponse(request.responseText);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
} else {
|
} else {
|
||||||
result = StatusBridge.sendRequestSync(this.host, JSON.stringify(payload));
|
alert('You tried to send "' + payload.method + '" synchronously. Synchronous requests are not supported, sorry.');
|
||||||
|
return null;
|
||||||
try {
|
|
||||||
result = JSON.parse(result);
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error("InvalidResponse: " + result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,7 +51,6 @@ StatusHttpProvider.prototype.prepareRequest = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
function sendAsync(payload, callback) {
|
function sendAsync(payload, callback) {
|
||||||
|
|
||||||
var messageId = callbackId++;
|
var messageId = callbackId++;
|
||||||
callbacks[messageId] = callback;
|
callbacks[messageId] = callback;
|
||||||
if (typeof StatusBridge == "undefined") {
|
if (typeof StatusBridge == "undefined") {
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
[status-im.ui.components.chat-icon.screen :as chat-icon.screen]
|
[status-im.ui.components.chat-icon.screen :as chat-icon.screen]
|
||||||
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
||||||
[status-im.i18n :as i18n]))
|
[status-im.i18n :as i18n]
|
||||||
|
[status-im.utils.ethereum.core :as ethereum]))
|
||||||
|
|
||||||
(views/defview toolbar-content-dapp [contact-identity]
|
(views/defview toolbar-content-dapp [contact-identity]
|
||||||
(views/letsubs [contact [:get-contact-by-identity contact-identity]]
|
(views/letsubs [contact [:get-contact-by-identity contact-identity]]
|
||||||
|
@ -76,7 +77,8 @@
|
||||||
{:keys [can-go-back? can-go-forward?]} [:get :browser/options]
|
{:keys [can-go-back? can-go-forward?]} [:get :browser/options]
|
||||||
extra-js [:web-view-extra-js]
|
extra-js [:web-view-extra-js]
|
||||||
rpc-url [:get :rpc-url]
|
rpc-url [:get :rpc-url]
|
||||||
unread-messages-number [:get-chats-unread-messages-number]]
|
unread-messages-number [:get-chats-unread-messages-number]
|
||||||
|
network-id [:get-network-id]]
|
||||||
[react/keyboard-avoiding-view styles/browser
|
[react/keyboard-avoiding-view styles/browser
|
||||||
[status-bar/status-bar]
|
[status-bar/status-bar]
|
||||||
[toolbar.view/toolbar {}
|
[toolbar.view/toolbar {}
|
||||||
|
@ -98,7 +100,10 @@
|
||||||
:injected-on-start-loading-java-script (str js-res/web3
|
:injected-on-start-loading-java-script (str js-res/web3
|
||||||
js-res/jquery
|
js-res/jquery
|
||||||
(get-inject-js url)
|
(get-inject-js url)
|
||||||
(js-res/web3-init rpc-url address))
|
(js-res/web3-init
|
||||||
|
rpc-url
|
||||||
|
(ethereum/normalized-address address)
|
||||||
|
(str network-id)))
|
||||||
:injected-java-script (str js-res/webview-js extra-js)}]
|
:injected-java-script (str js-res/webview-js extra-js)}]
|
||||||
[react/view styles/background
|
[react/view styles/background
|
||||||
[react/text (i18n/label :t/enter-dapp-url)]])
|
[react/text (i18n/label :t/enter-dapp-url)]])
|
||||||
|
|
|
@ -37,9 +37,10 @@
|
||||||
(def web3 (str "; if (typeof Web3 == 'undefined') {"
|
(def web3 (str "; if (typeof Web3 == 'undefined') {"
|
||||||
(slurp "node_modules/web3/dist/web3.min.js")
|
(slurp "node_modules/web3/dist/web3.min.js")
|
||||||
"}"))
|
"}"))
|
||||||
(defn web3-init [provider-address current-account-address]
|
(defn web3-init [provider-address current-account-address network-id]
|
||||||
(str "var providerAddress = \"" provider-address "\";"
|
(str "var providerAddress = \"" provider-address "\";"
|
||||||
"var currentAccountAddress = \"" current-account-address "\";"
|
"var currentAccountAddress = \"" current-account-address "\";"
|
||||||
|
"var networkId = \"" network-id "\";"
|
||||||
(slurp "resources/js/web3_init.js")))
|
(slurp "resources/js/web3_init.js")))
|
||||||
|
|
||||||
(defn local-storage-data [data]
|
(defn local-storage-data [data]
|
||||||
|
|
Loading…
Reference in New Issue