Fix network id lookup

This commit is contained in:
janherich 2018-05-21 15:20:00 +02:00
parent 85389a3101
commit efdd6debb0
No known key found for this signature in database
GPG Key ID: C23B473AFBE94D13
6 changed files with 27 additions and 25 deletions

View File

@ -37,7 +37,7 @@
[{:keys [db get-local-storage-data]} commands-resource whisper-identity] [{:keys [db get-local-storage-data]} commands-resource whisper-identity]
(let [data (get-local-storage-data whisper-identity) (let [data (get-local-storage-data whisper-identity)
local-storage-snippet (js-resources/local-storage-data data) local-storage-snippet (js-resources/local-storage-data data)
network-id (get-in db [:account/account :networks (:network db) :raw-config :NetworkId]) network-id (get-in db [:account/account :networks (:network db) :config :NetworkId])
ethereum-id-snippet (js-resources/network-id network-id) ethereum-id-snippet (js-resources/network-id network-id)
commands-snippet (str local-storage-snippet ethereum-id-snippet commands-resource)] commands-snippet (str local-storage-snippet ethereum-id-snippet commands-resource)]
{::evaluate-jail-n [{:jail-id whisper-identity {::evaluate-jail-n [{:jail-id whisper-identity

View File

@ -34,14 +34,6 @@
;; TODO(jeluard) Restore once we support postponing transaction ;; TODO(jeluard) Restore once we support postponing transaction
#_{:id :postponed :label (i18n/label :t/postponed) :checked? true}]}}) #_{:id :postponed :label (i18n/label :t/postponed) :checked? true}]}})
(defn- transform-config [networks]
(->> networks
(map (fn [[network-name {:keys [config] :as data}]]
[network-name (assoc data
:config (types/clj->json config)
:raw-config config)]))
(into {})))
(def mainnet-networks (def mainnet-networks
{"mainnet" {:id "mainnet", {"mainnet" {:id "mainnet",
:name "Mainnet", :name "Mainnet",
@ -77,9 +69,8 @@
:URL "https://rinkeby.infura.io/z6GCTmjdP3FETEJmMBI4"}}}}) :URL "https://rinkeby.infura.io/z6GCTmjdP3FETEJmMBI4"}}}})
(def default-networks (def default-networks
(transform-config (merge testnet-networks
(merge testnet-networks mainnet-networks))
mainnet-networks)))
(def default-wnodes (def default-wnodes
{:testnet {"mailserver-a" {:id "mailserver-a" {:testnet {"mailserver-a" {:id "mailserver-a"

View File

@ -1,6 +1,7 @@
(ns status-im.data-store.accounts (ns status-im.data-store.accounts
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.data-store.realm.core :as core])) [status-im.data-store.realm.core :as core]
[status-im.utils.types :as types]))
;; TODO janherich: define as cofx once debug handlers are refactored ;; TODO janherich: define as cofx once debug handlers are refactored
(defn get-by-address [address] (defn get-by-address [address]
@ -9,6 +10,15 @@
(core/single-clj :account) (core/single-clj :account)
(update :settings core/deserialize))) (update :settings core/deserialize)))
(defn- deserialize-account [account]
(-> account
(update :settings core/deserialize)
(update :networks (partial reduce-kv
(fn [acc network-id props]
(assoc acc network-id
(update props :config types/json->clj)))
{}))))
(re-frame/reg-cofx (re-frame/reg-cofx
:data-store/get-all-accounts :data-store/get-all-accounts
(fn [coeffects _] (fn [coeffects _]
@ -16,16 +26,20 @@
(core/get-all :account) (core/get-all :account)
(core/all-clj :account) (core/all-clj :account)
(as-> accounts (as-> accounts
(map #(update % :settings core/deserialize) accounts)))))) (map deserialize-account accounts))))))
(defn- serialize-account [account]
(-> account
(update :settings core/serialize)
(update :networks (partial map (fn [[_ props]]
(update props :config types/clj->json))))))
(defn save-account-tx (defn save-account-tx
"Returns tx function for saving account" "Returns tx function for saving account"
[{:keys [after-update-event] :as account}] [{:keys [after-update-event] :as account}]
(fn [realm] (fn [realm]
(let [account-to-save (-> account (let [account-to-save (-> (serialize-account account)
(dissoc :after-update-event) (dissoc :after-update-event))]
(update :settings core/serialize)
(update :networks vals))]
(core/create realm :account account-to-save true) (core/create realm :account account-to-save true)
(when after-update-event (when after-update-event
(re-frame/dispatch after-update-event))))) (re-frame/dispatch after-update-event)))))

View File

@ -165,7 +165,7 @@
(if should-move? (if should-move?
(re-frame/dispatch [:request-permissions {:permissions [:read-external-storage] (re-frame/dispatch [:request-permissions {:permissions [:read-external-storage]
:on-allowed #(move-to-internal-storage config)}]) :on-allowed #(move-to-internal-storage config)}])
(status/start-node config)))))) (status/start-node (types/clj->json config)))))))
(re-frame/reg-fx (re-frame/reg-fx
::status-module-initialized-fx ::status-module-initialized-fx

View File

@ -4,7 +4,7 @@
(spec/def :networks/id string?) (spec/def :networks/id string?)
(spec/def :networks/name string?) (spec/def :networks/name string?)
(spec/def :networks/config string?) (spec/def :networks/config map?)
(spec/def :networks/network (spec/def :networks/network
(spec/keys :req-un [:networks/id :networks/name :networks/config])) (spec/keys :req-un [:networks/id :networks/name :networks/config]))

View File

@ -22,11 +22,8 @@
(defn testnet? [id] (defn testnet? [id]
(contains? #{(chain-keyword->chain-id :testnet) (chain-keyword->chain-id :rinkeby)} id)) (contains? #{(chain-keyword->chain-id :testnet) (chain-keyword->chain-id :rinkeby)} id))
(defn network-config [network]
(or (:raw-config network) (types/json->clj (:config network))))
(defn network-with-upstream-rpc? [network] (defn network-with-upstream-rpc? [network]
(get-in (network-config network) [:UpstreamConfig :Enabled])) (get-in network [:config :UpstreamConfig :Enabled]))
(def hex-prefix "0x") (def hex-prefix "0x")
@ -41,7 +38,7 @@
(.isAddress dependencies/Web3.prototype s))) (.isAddress dependencies/Web3.prototype s)))
(defn network->chain-id [network] (defn network->chain-id [network]
(:NetworkId (network-config network))) (get-in network [:config :NetworkId]))
(defn network->chain-keyword [network] (defn network->chain-keyword [network]
(chain-id->chain-keyword (network->chain-id network))) (chain-id->chain-keyword (network->chain-id network)))