mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 11:34:45 +00:00
move network-id verification
This commit is contained in:
parent
b28c521b2b
commit
7d813149eb
@ -691,13 +691,6 @@
|
|||||||
(log/debug :event-str event-str)
|
(log/debug :event-str event-str)
|
||||||
(signals/process cofx event-str)))
|
(signals/process cofx event-str)))
|
||||||
|
|
||||||
;; protocol module
|
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
|
||||||
:protocol.ui/close-app-confirmed
|
|
||||||
(fn [cofx _]
|
|
||||||
(protocol/handle-close-app-confirmed cofx)))
|
|
||||||
|
|
||||||
;; notifications module
|
;; notifications module
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
|
@ -5,18 +5,15 @@
|
|||||||
[status-im.chat.models :as chat-model]
|
[status-im.chat.models :as chat-model]
|
||||||
[status-im.chat.models.loading :as chat.loading]
|
[status-im.chat.models.loading :as chat.loading]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
[status-im.data-store.core :as data-store]
|
|
||||||
[status-im.contact.core :as contact]
|
[status-im.contact.core :as contact]
|
||||||
[status-im.ethereum.core :as ethereum]
|
[status-im.data-store.core :as data-store]
|
||||||
[status-im.ethereum.json-rpc :as json-rpc]
|
[status-im.ethereum.json-rpc :as json-rpc]
|
||||||
[status-im.ethereum.transactions.core :as transactions]
|
[status-im.ethereum.transactions.core :as transactions]
|
||||||
[status-im.fleet.core :as fleet]
|
[status-im.fleet.core :as fleet]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
[status-im.native-module.core :as status]
|
[status-im.native-module.core :as status]
|
||||||
[status-im.node.core :as node]
|
|
||||||
[status-im.notifications.core :as notifications]
|
[status-im.notifications.core :as notifications]
|
||||||
[status-im.stickers.core :as stickers]
|
[status-im.stickers.core :as stickers]
|
||||||
[status-im.ui.screens.db :refer [app-db]]
|
|
||||||
[status-im.ui.screens.mobile-network-settings.events :as mobile-network]
|
[status-im.ui.screens.mobile-network-settings.events :as mobile-network]
|
||||||
[status-im.ui.screens.navigation :as navigation]
|
[status-im.ui.screens.navigation :as navigation]
|
||||||
[status-im.utils.config :as config]
|
[status-im.utils.config :as config]
|
||||||
@ -27,6 +24,7 @@
|
|||||||
[status-im.utils.security :as security]
|
[status-im.utils.security :as security]
|
||||||
[status-im.utils.types :as types]
|
[status-im.utils.types :as types]
|
||||||
[status-im.utils.universal-links.core :as universal-links]
|
[status-im.utils.universal-links.core :as universal-links]
|
||||||
|
[status-im.utils.utils :as utils]
|
||||||
[status-im.wallet.core :as wallet]
|
[status-im.wallet.core :as wallet]
|
||||||
[taoensso.timbre :as log]))
|
[taoensso.timbre :as log]))
|
||||||
|
|
||||||
@ -105,6 +103,26 @@
|
|||||||
[cofx address password]
|
[cofx address password]
|
||||||
{:keychain/save-user-password [address password]})
|
{:keychain/save-user-password [address password]})
|
||||||
|
|
||||||
|
(fx/defn handle-close-app-confirmed
|
||||||
|
{:events [::close-app-confirmed]}
|
||||||
|
[_]
|
||||||
|
{:ui/close-application nil})
|
||||||
|
|
||||||
|
(fx/defn check-network-version
|
||||||
|
[cofx network-id]
|
||||||
|
{::json-rpc/call
|
||||||
|
[{:method "net_version"
|
||||||
|
:on-success
|
||||||
|
(fn [fetched-network-id]
|
||||||
|
(when (not= network-id fetched-network-id)
|
||||||
|
;;TODO: this shouldn't happen but in case it does
|
||||||
|
;;we probably want a better error message
|
||||||
|
(utils/show-popup (i18n/label :t/ethereum-node-started-incorrectly-title)
|
||||||
|
(i18n/label :t/ethereum-node-started-incorrectly-description
|
||||||
|
{:network-id network-id
|
||||||
|
:fetched-network-id fetched-network-id})
|
||||||
|
#(re-frame/dispatch [::close-app-confirmed]))))}]})
|
||||||
|
|
||||||
(defn deserialize-config
|
(defn deserialize-config
|
||||||
[{:keys [multiaccount current-network networks]}]
|
[{:keys [multiaccount current-network networks]}]
|
||||||
[(types/deserialize multiaccount)
|
[(types/deserialize multiaccount)
|
||||||
@ -114,13 +132,15 @@
|
|||||||
(fx/defn get-config-callback
|
(fx/defn get-config-callback
|
||||||
{:events [::get-config-callback]}
|
{:events [::get-config-callback]}
|
||||||
[{:keys [db] :as cofx} config stored-pns]
|
[{:keys [db] :as cofx} config stored-pns]
|
||||||
(let [[{:keys [address] :as multiaccount} current-network networks] (deserialize-config config)]
|
(let [[{:keys [address] :as multiaccount} current-network networks] (deserialize-config config)
|
||||||
|
network-id (str (get-in networks [current-network :config :NetworkId]))]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (assoc db
|
{:db (assoc db
|
||||||
:networks/current-network current-network
|
:networks/current-network current-network
|
||||||
:networks/networks networks
|
:networks/networks networks
|
||||||
:multiaccount multiaccount)
|
:multiaccount multiaccount)
|
||||||
:notifications/request-notifications-permissions nil}
|
:notifications/request-notifications-permissions nil}
|
||||||
|
(check-network-version network-id)
|
||||||
(chat.loading/initialize-chats)
|
(chat.loading/initialize-chats)
|
||||||
(contact/initialize-contacts)
|
(contact/initialize-contacts)
|
||||||
(stickers/init-stickers-packs)
|
(stickers/init-stickers-packs)
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
(ns status-im.protocol.core
|
(ns status-im.protocol.core
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [status-im.constants :as constants]
|
||||||
[status-im.constants :as constants]
|
|
||||||
[status-im.ethereum.core :as ethereum]
|
|
||||||
[status-im.ethereum.json-rpc :as json-rpc]
|
|
||||||
[status-im.i18n :as i18n]
|
|
||||||
[status-im.mailserver.core :as mailserver]
|
[status-im.mailserver.core :as mailserver]
|
||||||
[status-im.node.core :as node]
|
[status-im.node.core :as node]
|
||||||
[status-im.transport.core :as transport]
|
[status-im.transport.core :as transport]
|
||||||
[status-im.tribute-to-talk.core :as tribute-to-talk]
|
[status-im.tribute-to-talk.core :as tribute-to-talk]
|
||||||
[status-im.utils.fx :as fx]
|
[status-im.utils.fx :as fx]))
|
||||||
[status-im.utils.utils :as utils]))
|
|
||||||
|
|
||||||
;;TODO move this logic to status-go
|
;;TODO move this logic to status-go
|
||||||
(fx/defn update-sync-state
|
(fx/defn update-sync-state
|
||||||
@ -40,33 +35,12 @@
|
|||||||
(node/update-sync-state error sync)))
|
(node/update-sync-state error sync)))
|
||||||
|
|
||||||
(fx/defn initialize-protocol
|
(fx/defn initialize-protocol
|
||||||
[{:data-store/keys [mailserver-topics mailservers]
|
[{:data-store/keys [mailserver-topics mailservers] :keys [db] :as cofx}]
|
||||||
:keys [db] :as cofx}]
|
(fx/merge cofx
|
||||||
(let [{:networks/keys [networks current-network]} db
|
{:db (assoc db
|
||||||
network-id (str (get-in networks [current-network :config :NetworkId]))]
|
:rpc-url constants/ethereum-rpc-url
|
||||||
(fx/merge cofx
|
:mailserver/topics mailserver-topics)}
|
||||||
{:db (assoc db
|
(tribute-to-talk/init)
|
||||||
:rpc-url constants/ethereum-rpc-url
|
(mailserver/initialize-ranges)
|
||||||
:mailserver/topics mailserver-topics)
|
(mailserver/initialize-mailserver mailservers)
|
||||||
::json-rpc/call
|
(transport/init-whisper)))
|
||||||
[{:method "net_version"
|
|
||||||
:on-success
|
|
||||||
(fn [fetched-network-id]
|
|
||||||
(when (and network-id
|
|
||||||
;; TODO fix once realm is removed
|
|
||||||
;; protocol should be initialized after network-id is known
|
|
||||||
(not= network-id fetched-network-id))
|
|
||||||
(utils/show-popup
|
|
||||||
(i18n/label :t/ethereum-node-started-incorrectly-title)
|
|
||||||
(i18n/label :t/ethereum-node-started-incorrectly-description
|
|
||||||
{:network-id network-id
|
|
||||||
:fetched-network-id fetched-network-id})
|
|
||||||
#(re-frame/dispatch [:protocol.ui/close-app-confirmed]))))}]}
|
|
||||||
(tribute-to-talk/init)
|
|
||||||
(mailserver/initialize-ranges)
|
|
||||||
(mailserver/initialize-mailserver mailservers)
|
|
||||||
(transport/init-whisper))))
|
|
||||||
|
|
||||||
(fx/defn handle-close-app-confirmed
|
|
||||||
[_]
|
|
||||||
{:ui/close-application nil})
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user