[#4935] Prevent connecting to the network with wrong id
This commit is contained in:
parent
738521092b
commit
d4d6757c69
|
@ -139,18 +139,29 @@
|
||||||
(if-let [config (get-in db [:account/account :networks network-id :config])]
|
(if-let [config (get-in db [:account/account :networks network-id :config])]
|
||||||
(if-let [upstream-url (get-in config [:UpstreamConfig :URL])]
|
(if-let [upstream-url (get-in config [:UpstreamConfig :URL])]
|
||||||
{:http-post {:url upstream-url
|
{:http-post {:url upstream-url
|
||||||
:data (types/clj->json {:jsonrpc "2.0"
|
:data (types/clj->json [{:jsonrpc "2.0"
|
||||||
:method "web3_clientVersion"
|
:method "web3_clientVersion"
|
||||||
:id 1})
|
:id 1}
|
||||||
|
{:jsonrpc "2.0"
|
||||||
|
:method "net_version"
|
||||||
|
:id 2}])
|
||||||
:opts {:headers {"Content-Type" "application/json"}}
|
:opts {:headers {"Content-Type" "application/json"}}
|
||||||
:success-event-creator (fn [{:keys [response-body]}]
|
:success-event-creator (fn [{:keys [response-body]}]
|
||||||
(if-let [client-version (:result (http/parse-payload response-body))]
|
(let [responses (http/parse-payload response-body)
|
||||||
[::connect-success {:network-id network-id
|
client-version (:result (first responses))
|
||||||
:on-success on-success
|
expected-network-id (:NetworkId config)
|
||||||
:client-version client-version}]
|
rpc-network-id (when-let [res (:result (second responses))]
|
||||||
[::connect-failure {:network-id network-id
|
(js/parseInt res))]
|
||||||
:on-failure on-failure
|
(if (and client-version network-id
|
||||||
:reason (i18n/label :t/network-invalid-url)}]))
|
(= expected-network-id rpc-network-id))
|
||||||
|
[::connect-success {:network-id network-id
|
||||||
|
:on-success on-success
|
||||||
|
:client-version client-version}]
|
||||||
|
[::connect-failure {:network-id network-id
|
||||||
|
:on-failure on-failure
|
||||||
|
:reason (if (not= expected-network-id rpc-network-id)
|
||||||
|
(i18n/label :t/network-invalid-network-id)
|
||||||
|
(i18n/label :t/network-invalid-url))}])))
|
||||||
:failure-event-creator (fn [{:keys [response-body status-code]}]
|
:failure-event-creator (fn [{:keys [response-body status-code]}]
|
||||||
(let [reason (if status-code
|
(let [reason (if status-code
|
||||||
(i18n/label :t/network-invalid-status-code {:code status-code})
|
(i18n/label :t/network-invalid-status-code {:code status-code})
|
||||||
|
|
|
@ -935,6 +935,7 @@
|
||||||
"share-public-chat-text": "Check out this public chat on the Status app: {{link}}",
|
"share-public-chat-text": "Check out this public chat on the Status app: {{link}}",
|
||||||
"share-dapp-text": "Check out this DApp I'm using on Status: {{link}}",
|
"share-dapp-text": "Check out this DApp I'm using on Status: {{link}}",
|
||||||
"network-invalid-url": "Network URL is invalid",
|
"network-invalid-url": "Network URL is invalid",
|
||||||
|
"network-invalid-network-id": "Specified network id doesn't correspond to network id by RPC url",
|
||||||
"network-invalid-status-code": "Invalid status code: {{code}}",
|
"network-invalid-status-code": "Invalid status code: {{code}}",
|
||||||
"extension-is-already-added": "The extension is already installed",
|
"extension-is-already-added": "The extension is already installed",
|
||||||
"extension-uninstalled": "The extension was uninstalled",
|
"extension-uninstalled": "The extension was uninstalled",
|
||||||
|
|
Loading…
Reference in New Issue