move networks out of multiaccount

This commit is contained in:
yenda 2019-08-23 16:11:23 +02:00
parent d183cfe125
commit d4a396bedf
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
33 changed files with 485 additions and 657 deletions

View File

@ -129,8 +129,6 @@
"status_im.network.ui.edit_network.styles"
"status_im.network.ui.views"
"status_im.network.ui.styles"
"status_im.network.events"
"status_im.network.subs"
"status_im.network.core"}
:output-to "status-modules/cljs/network-raw.js"}}}
:warning-handlers [status-im.utils.build/warning-handler]}
@ -159,8 +157,6 @@
"status_im.network.ui.edit_network.styles"
"status_im.network.ui.views"
"status_im.network.ui.styles"
"status_im.network.events"
"status_im.network.subs"
"status_im.network.core"}
:output-to "status-modules/cljs/network-raw.js"}}}
:warning-handlers [status-im.utils.build/warning-handler]}
@ -187,8 +183,6 @@
"status_im.network.ui.edit_network.styles"
"status_im.network.ui.views"
"status_im.network.ui.styles"
"status_im.network.events"
"status_im.network.subs"
"status_im.network.core"}
:output-to "status-modules/cljs/network-raw.js"}}}
:warning-handlers [status-im.utils.build/warning-handler]}}}}})

View File

@ -85,10 +85,10 @@
(fx/defn toggle-custom-bootnodes
[{:keys [db] :as cofx} value]
(let [network (get-in db [:multiaccount :network])
(let [current-network (:networks/current-network db)
settings (get-in db [:multiaccount :settings])]
(multiaccounts.update/update-settings cofx
(assoc-in settings [:bootnodes network] value)
(assoc-in settings [:bootnodes current-network] value)
{:success-event [:multiaccounts.update.callback/save-settings-success]})))
(fx/defn set-bootnodes-from-qr

View File

@ -204,7 +204,7 @@
(defview send-preview
[{:keys [content timestamp-str outgoing group-chat]}]
(letsubs [network [:network-name]
(letsubs [network [:chain-name]
all-tokens [:wallet/all-tokens]]
(let [{{:keys [amount fiat-amount tx-hash asset currency] send-network :network} :params} content
recipient-name (get-in content [:params :bot-db :public :recipient])
@ -389,7 +389,7 @@
(defview request-preview
[{:keys [message-id content outgoing timestamp timestamp-str group-chat]}]
(letsubs [id->command [:chats/id->command]
network [:network-name]
network [:chain-name]
prices [:prices]]
(let [{:keys [amount asset fiat-amount currency answered?] request-network :network} (:params content)
network-mismatch? (and request-network (not= request-network network))

View File

@ -97,10 +97,8 @@
name))
(defn chain-keyword
[db]
(let [network-id (get-in db [:multiaccount :network])
network (get-in db [:multiaccount :networks/networks network-id])]
(network->chain-keyword network)))
[{:networks/keys [current-network networks]}]
(network->chain-keyword (get networks current-network)))
(defn snt-symbol [db]
(case (chain-keyword db)

View File

@ -68,7 +68,9 @@
"permissions_deleteDappPermissions" {}
"settings_saveConfig" {}
"settings_getConfig" {}
"settings_saveNodeConfig" {}})
"settings_getConfigs" {}
"settings_saveNodeConfig" {}
"accounts_getAccounts" {}})
(defn call
[{:keys [method params on-success on-error] :as p}]

View File

@ -21,22 +21,11 @@
(fx/defn initialize-app-db
"Initialize db to initial state"
[{{:keys [view-id hardwallet :multiaccounts/multiaccounts
initial-props desktop/desktop
network-status network peers-count peers-summary device-UUID
supported-biometric-auth push-notifications/stored network/type]
:node/keys [status]
:or {network (get app-db :network)}} :db}]
[{{:keys [view-id hardwallet initial-props desktop/desktop
device-UUID supported-biometric-auth push-notifications/stored network/type]} :db}]
{:db (assoc app-db
:multiaccounts/multiaccounts multiaccounts
:contacts/contacts {}
:initial-props initial-props
:desktop/desktop (merge desktop (:desktop/desktop app-db))
:network-status network-status
:peers-count (or peers-count 0)
:peers-summary (or peers-summary [])
:node/status status
:network network
:network/type type
:hardwallet hardwallet
:device-UUID device-UUID

View File

@ -146,7 +146,7 @@
[multiaccount]
[(let [{:keys [publicKey address]}
(get-in multiaccount [:derived constants/path-default-wallet-keyword])]
{:public-key publicKey
{:publicKey publicKey
:address address
:color colors/blue
:wallet true
@ -154,7 +154,7 @@
:name "Status account"})
(let [{:keys [publicKey address]}
(get-in multiaccount [:derived constants/path-whisper-keyword])]
{:public-key publicKey
{:publicKey publicKey
:address address
:path constants/path-whisper
:chat true})])
@ -164,30 +164,32 @@
{:keys [address publicKey keycard-instance-uid keycard-key-uid keycard-pairing keycard-paired-on mnemonic] :as multiaccount}
password
{:keys [seed-backed-up? login?] :or {login? true}}]
(let [[wallet-account {:keys [public-key]} :as subaccounts-data] (prepare-subaccounts-data multiaccount)
name (gfycat/generate-gfy public-key)
photo-path (identicon/identicon public-key)
(let [[wallet-account {:keys [publicKey]} :as subaccounts-data] (prepare-subaccounts-data multiaccount)
name (gfycat/generate-gfy publicKey)
photo-path (identicon/identicon publicKey)
account-data {:name name :address address :photo-path photo-path}
new-multiaccount {:address address
:name name
:public-key public-key
:photo-path photo-path
:public-key publicKey
:latest-derived-path 0
:accounts [wallet-account]
:installation-id (random-guid-generator)
:signing-phrase signing-phrase
:installation-id (random-guid-generator)
:mnemonic mnemonic
:settings constants/default-multiaccount-settings
:network constants/default-network
:networks/networks constants/default-networks}
db (-> db
(assoc :multiaccounts/login {:address address
:name name
:photo-path photo-path
:password password
:creating? true
:processing true}
:multiaccount new-multiaccount))]
:settings constants/default-multiaccount-settings}
db (assoc db
:multiaccounts/login {:address address
:name name
:photo-path photo-path
:password password
:creating? true
:processing true}
:multiaccount new-multiaccount
:networks/current-network constants/default-network
:networks/networks constants/default-networks)]
(fx/merge cofx
{:db (cond-> db
seed-backed-up?

View File

@ -24,8 +24,6 @@
(spec/def :multiaccount/photo-path (spec/nilable string?))
(spec/def :multiaccount/debug? (spec/nilable boolean?))
(spec/def :multiaccount/chaos-mode? (spec/nilable boolean?))
(spec/def :multiaccount/network (spec/nilable string?))
(spec/def :multiaccount/networks (spec/nilable :networks/networks))
(spec/def :multiaccount/bootnodes (spec/nilable :bootnodes/bootnodes))
(spec/def :multiaccount/mailserver (spec/nilable string?))
(spec/def :multiaccount/settings (spec/nilable (spec/map-of keyword? any?)))
@ -48,8 +46,8 @@
:multiaccount/signing-phrase
:multiaccount/installation-id
:multiaccount/debug? :multiaccount/last-updated :multiaccount/public-key
:multiaccount/email :multiaccount/signed-up? :multiaccount/network
:multiaccount/networks :multiaccount/settings :multiaccount/mailserver
:multiaccount/email :multiaccount/signed-up?
:multiaccount/settings :multiaccount/mailserver
:multiaccount/sharing-usage-data?
:multiaccount/seed-backed-up? :multiaccount/mnemonic :multiaccount/desktop-notifications?
:multiaccount/chaos-mode?

View File

@ -94,48 +94,6 @@
all-stored-browsers)]
{:db (assoc db :browser/browsers browsers)}))
(fx/defn get-config-callback
{:events [::get-config-callback]}
[{:keys [db] :as cofx} config stored-pns]
(let [{:keys [network networks/networks address] :as multiaccount} (types/deserialize config)]
(fx/merge cofx
{:db (assoc db
:network network
:networks/networks networks
:chain (ethereum/network->chain-name network)
:multiaccount multiaccount)
:notifications/request-notifications-permissions nil}
(stickers/init-stickers-packs)
(mobile-network/on-network-status-change)
(chaos-mode/check-chaos-mode)
(when-not platform/desktop?
(initialize-wallet))
(when stored-pns
(notifications/process-stored-event address stored-pns)))))
(fx/defn initialize-multiaccount-db
[{:keys [db]} address]
(let [{:universal-links/keys [url]
:keys [network-status peers-count peers-summary view-id multiaccount
desktop/desktop hardwallet custom-fleets supported-biometric-auth
device-UUID semaphores intro-wizard]} db]
{:db (cond-> (assoc app-db
:view-id view-id
:node/status (:node/status db)
:desktop/desktop (merge desktop (:desktop/desktop app-db))
:network-status network-status
:network/type (:network/type db)
:universal-links/url url
:custom-fleets custom-fleets
:peers-summary peers-summary
:peers-count peers-count
:device-UUID device-UUID
:intro-wizard {:step (:step intro-wizard)}
:supported-biometric-auth supported-biometric-auth
:semaphores semaphores
:hardwallet hardwallet)
multiaccount (assoc :multiaccount multiaccount))}))
(fx/defn initialize-web3-client-version
{:events [::initialize-web3-client-version]}
[{:keys [db]} resp]
@ -147,6 +105,32 @@
[cofx address password]
{:keychain/save-user-password [address password]})
(defn deserialize-config
[{:keys [multiaccount current-network networks]}]
[(types/deserialize multiaccount)
current-network
(types/deserialize networks)])
(fx/defn get-config-callback
{:events [::get-config-callback]}
[{:keys [db] :as cofx} config stored-pns]
(let [[{:keys [address] :as multiaccount} current-network networks] (deserialize-config config)]
(fx/merge cofx
{:db (assoc db
:networks/current-network current-network
:networks/networks networks
:multiaccount multiaccount)
:notifications/request-notifications-permissions nil}
(chat.loading/initialize-chats)
(contact/initialize-contacts)
(stickers/init-stickers-packs)
(mobile-network/on-network-status-change)
(chaos-mode/check-chaos-mode)
(when-not platform/desktop?
(initialize-wallet))
(when stored-pns
(notifications/process-stored-event address stored-pns)))))
(fx/defn login-only-events
[{:keys [db] :as cofx} address password save-password?]
(let [stored-pns (:push-notifications/stored db)]
@ -158,15 +142,12 @@
:on-success #(re-frame/dispatch [::initialize-browsers %])}
{:method "permissions_getDappPermissions"
:on-success #(re-frame/dispatch [::initialize-dapp-permissions %])}
{:method "settings_getConfig"
:params ["multiaccount"]
{:method "settings_getConfigs"
:params [["multiaccount" "current-network" "networks"]]
:on-success #(re-frame/dispatch [::get-config-callback % stored-pns])}]}
(when save-password?
(save-user-password address password))
(navigation/navigate-to-cofx :home nil)
(stickers/init-stickers-packs)
(chat.loading/initialize-chats)
(contact/initialize-contacts)
(universal-links/process-stored-event)
(when platform/desktop?
(chat-model/update-dock-badge-label)))))
@ -176,7 +157,7 @@
(fx/defn create-only-events
[{:keys [db] :as cofx} address password]
(let [{:keys [multiaccount]} db]
(let [{:keys [multiaccount :networks/networks :networks/current-network]} db]
(fx/merge cofx
{:db (assoc db
;;NOTE when login the filters are initialized twice
@ -194,6 +175,12 @@
::json-rpc/call
[{:method "settings_saveConfig"
:params ["multiaccount" (types/serialize multiaccount)]
:on-success #()}
{:method "settings_saveConfig"
:params ["networks" (types/serialize networks)]
:on-success #()}
{:method "settings_saveConfig"
:params ["current-network" current-network]
:on-success #()}]}
(finish-keycard-setup)
(mobile-network/on-network-status-change)
@ -228,7 +215,6 @@
;;FIXME
(when nodes
(fleet/set-nodes :eth.contract nodes))
(initialize-multiaccount-db address)
(if login-only?
(login-only-events address password save-password?)
(create-only-events address password))

View File

@ -1,22 +1,15 @@
(ns status-im.network.core
(:require [clojure.string :as string]
[re-frame.core :as re-frame]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.chaos-mode.core :as chaos-mode]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.fleet.core :as fleet-core]
[status-im.i18n :as i18n]
[status-im.mailserver.core :as mailserver]
[status-im.native-module.core :as status]
[status-im.ui.screens.mobile-network-settings.events :as mobile-network]
[status-im.node.core :as node]
[status-im.ui.screens.navigation :as navigation]
[status-im.utils.fx :as fx]
[status-im.utils.handlers :as handlers]
[status-im.utils.http :as http]
[status-im.utils.types :as types]
status-im.network.subs
[status-im.node.core :as node]
[taoensso.timbre :as log]))
[status-im.utils.types :as types]))
(def url-regex
#"https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)")
@ -55,96 +48,48 @@
(map :error)
(not-any? identity)))
(defn get-network-id-for-chain-id [{:keys [db]} chain-id]
(let [networks (get-in db [:multiaccount :networks/networks])
filtered (filter #(= chain-id (get-in % [1 :config :NetworkId])) networks)]
(first (keys filtered))))
(defn chain-id-available? [current-networks network]
(let [chain-id (get-in network [:config :NetworkId])]
(every? #(not= chain-id (get-in % [1 :config :NetworkId])) current-networks)))
(defn new-network [random-id network-name upstream-url type chain-id]
(let [data-dir (str "/ethereum/" (name type) "_rpc")
config {:NetworkId (or (when chain-id (int chain-id))
(ethereum/chain-keyword->chain-id type))
:DataDir data-dir
:UpstreamConfig {:Enabled true
:URL upstream-url}}]
{:id (string/replace random-id "-" "")
:name network-name
:config config}))
(defn get-network [{:keys [db]} network-id]
(get-in db [:multiaccount :networks/networks network-id]))
(get-in db [:networks/networks network-id]))
(fx/defn set-input
{:events [::input-changed]}
[{:keys [db]} input-key value]
{:db (-> db
(update-in [:networks/manage input-key] assoc :value value)
(update-in [:networks/manage] validate-manage))})
(defn- action-handler
([handler]
(action-handler handler nil nil))
([handler data cofx]
(when handler
(handler data cofx))))
(fx/defn save
[{{:networks/keys [manage] :keys [multiaccount] :as db} :db
random-id-generator :random-id-generator :as cofx}
{:keys [data success-event on-success on-failure network-id chain-id-unique?]}]
(let [data (or data manage)]
(if (valid-manage? data)
;; rename network-id from UI to chain-id
(let [{:keys [name url chain] chain-id :network-id} data
;; network-id overrides random id
network (new-network (or network-id (random-id-generator))
(:value name)
(:value url)
(:value chain)
(:value chain-id))
current-networks (:networks/networks multiaccount)
new-networks (merge {(:id network) network} current-networks)]
(if (or (not chain-id-unique?)
(chain-id-available? current-networks network))
(fx/merge cofx
{:db (dissoc db :networks/manage)}
#(action-handler on-success (:id network) %)
(multiaccounts.update/multiaccount-update
{:networks/networks new-networks}
{:success-event success-event}))
(action-handler on-failure "chain-id already defined" nil)))
(action-handler on-failure "invalid network parameters" nil))))
;; No edit functionality actually implemented
(fx/defn edit
{:events [::add-network-pressed]}
[{db :db}]
{:db (assoc db :networks/manage (validate-manage default-manage))
:dispatch [:navigate-to :edit-network]})
(fx/defn connect-success [{:keys [db] :as cofx}
{:keys [network-id on-success client-version]}]
(let [current-network (get-in db [:multiaccount :networks/networks (:network db)])]
(fx/merge
cofx
{:ui/show-confirmation
{:title (i18n/label :t/close-app-title)
:content (i18n/label :t/logout-app-content)
:confirm-button-text (i18n/label :t/close-app-button)
:on-accept #(re-frame/dispatch [::save-network-settings-pressed network-id])
:on-cancel nil}}
#(action-handler on-success {:network-id network-id
:client-version client-version} %))))
(fx/defn connect-success
{:events [::connect-success]}
[_ network-id]
{:ui/show-confirmation
{:title (i18n/label :t/close-app-title)
:content (i18n/label :t/logout-app-content)
:confirm-button-text (i18n/label :t/close-app-button)
:on-accept #(re-frame/dispatch [::save-network-settings-pressed network-id])
:on-cancel nil}})
(defn connect-failure [{:keys [network-id on-failure reason]}]
(action-handler on-failure
{:network-id network-id :reason reason}
nil))
(fx/defn connect-failure
{:events [::connect-failure]}
[_ reason]
{:utils/show-popup
{:title (i18n/label :t/error)
:content (str reason)}})
(fx/defn connect [{:keys [db] :as cofx} {:keys [network-id on-success on-failure]}]
(if-let [config (get-in db [:multiaccount :networks/networks network-id :config])]
(fx/defn connect
{:events [::connect-network-pressed]}
[{:keys [db] :as cofx} network-id]
(if-let [config (get-in db [:networks/networks network-id :config])]
(if-let [upstream-url (get-in config [:UpstreamConfig :URL])]
{:http-post {:url upstream-url
:data (types/clj->json [{:jsonrpc "2.0"
@ -162,74 +107,88 @@
(js/parseInt res))]
(if (and client-version network-id
(= 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))}])))
[::connect-success network-id]
[::connect-failure (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]}]
(let [reason (if status-code
(i18n/label :t/network-invalid-status-code {:code status-code})
(str response-body))]
[::connect-failure {:network-id network-id
:on-failure on-failure
:reason reason}]))}}
(connect-success cofx {:network-id network-id
:on-success on-success
:client-version ""}))
(connect-failure {:network-id network-id
:on-failure on-failure
:reason "A network with the specified id doesn't exist"})))
(handlers/register-handler-fx
::connect-success
(fn [cofx [_ data]]
(connect-success cofx data)))
(handlers/register-handler-fx
::connect-failure
(fn [_ [_ data]]
(connect-failure data)))
[::connect-failure reason]))}}
(connect-success cofx network-id))
(connect-failure cofx "A network with the specified id doesn't exist")))
(fx/defn delete
[{{:keys [multiaccount]} :db :as cofx} {:keys [network on-success on-failure]}]
(let [current-network? (= (:network multiaccount) network)]
{:events [::delete-network-pressed]}
[{:keys [db]} network]
(let [current-network? (= (:networks/current-network db) network)]
(if (or current-network?
(not (get-in multiaccount [:networks/networks network])))
(fx/merge cofx
{:ui/show-error (i18n/label :t/delete-network-error)}
#(action-handler on-failure network %))
(fx/merge cofx
{:ui/show-confirmation {:title (i18n/label :t/delete-network-title)
:content (i18n/label :t/delete-network-confirmation)
:confirm-button-text (i18n/label :t/delete)
:on-accept #(re-frame/dispatch [:network.ui/remove-network-confirmed network])
:on-cancel nil}}
#(action-handler on-success network %)))))
(not (get-in db [:networks/networks network])))
{:ui/show-error (i18n/label :t/delete-network-error)}
{:ui/show-confirmation {:title (i18n/label :t/delete-network-title)
:content (i18n/label :t/delete-network-confirmation)
:confirm-button-text (i18n/label :t/delete)
:on-accept #(re-frame/dispatch [::remove-network-confirmed network])
:on-cancel nil}})))
(fx/defn save-network-settings
{:events [::save-network-settings-pressed]}
[{:keys [now] :as cofx} network]
[{:keys [db] :as cofx} network]
(fx/merge cofx
(multiaccounts.update/multiaccount-update {:network network :last-updated now} {})
{:db (assoc db :networks/current-network network)
::json-rpc/call [{:method "settings_saveConfig"
:params ["current-network" network]
:on-success #()}]}
(node/prepare-new-config {:on-success #(re-frame/dispatch [:logout])})))
(fx/defn remove-network
[{:keys [db now] :as cofx} network success-event]
(let [networks (dissoc (get-in db [:multiaccount :networks/networks]) network)]
(multiaccounts.update/multiaccount-update cofx
{:networks/networks networks
:last-updated now}
{:success-event success-event})))
{:events [::remove-network-confirmed]}
[{:keys [db] :as cofx} network]
(let [networks (dissoc (:networks/networks db) network)]
{:db (assoc db :networks/networks networks)
::json-rpc/call [{:method "settings_saveConfig"
:params ["networks" (types/serialize networks)]
:on-success #(re-frame/dispatch [:navigate-back])}]}))
(fx/defn save-network
[cofx]
(save cofx
{:data (get-in cofx [:db :networks/manage])
:success-event [:navigate-back]}))
(defn new-network
[random-id network-name upstream-url chain-type chain-id]
(let [data-dir (str "/ethereum/" (name chain-type) "_rpc")
config {:NetworkId (or (when chain-id (int chain-id))
(ethereum/chain-keyword->chain-id chain-type))
:DataDir data-dir
:UpstreamConfig {:Enabled true
:URL upstream-url}}]
{:id random-id
:name network-name
:config config}))
(fx/defn save
{:events [::save-network-pressed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]}
[{{:networks/keys [manage networks] :as db} :db
random-id-generator :random-id-generator :as cofx}]
(if (valid-manage? manage)
;; rename network-id from UI to chain-id
(let [{:keys [name url chain network-id]} manage
random-id (string/replace (random-id-generator) "-" "")
network (new-network random-id
(:value name)
(:value url)
(:value chain)
(:value network-id))
custom-chain-type? (= :custom (:value chain))
new-networks (assoc networks random-id network)]
(if (or (not custom-chain-type?)
(chain-id-available? networks network))
{:db (-> db
(dissoc :networks/manage)
(assoc :networks/networks new-networks))
::json-rpc/call [{:method "settings_saveConfig"
:params ["networks" (types/serialize new-networks)]
:on-success #(re-frame/dispatch [:navigate-back])}]}
{:ui/show-error "chain-id already defined"}))
{:ui/show-error "invalid network parameters"}))
(defn- navigate-to-network-details
[cofx network show-warning?]
@ -245,6 +204,7 @@
(map name fleet-core/fleets-with-les)))
(fx/defn open-network-details
{:events [::network-entry-pressed]}
[cofx network]
(let [db (:db cofx)
rpc-network? (get-in network [:config :UpstreamConfig :Enabled] false)

View File

@ -1,43 +0,0 @@
(ns status-im.network.events
(:require [status-im.network.core :as network]
[status-im.utils.handlers :as handlers]
[re-frame.core :as re-frame]
[status-im.utils.utils :as utils]))
(handlers/register-handler-fx
:network.ui/save-network-pressed
[(re-frame/inject-cofx :random-id-generator)]
(fn [cofx]
(network/save-network cofx)))
(handlers/register-handler-fx
:network.ui/input-changed
(fn [cofx [_ input-key value]]
(network/set-input cofx input-key value)))
(handlers/register-handler-fx
:network.ui/add-network-pressed
(fn [cofx]
(network/edit cofx)))
(handlers/register-handler-fx
:network.ui/remove-network-confirmed
(fn [cofx [_ network]]
(network/remove-network cofx network [:navigate-back])))
(handlers/register-handler-fx
:network.ui/connect-network-pressed
(fn [cofx [_ network-id]]
(network/connect cofx {:network-id network-id
:on-failure (fn [{:keys [reason]} _]
(utils/show-popup "Error" (str reason)))})))
(handlers/register-handler-fx
:network.ui/delete-network-pressed
(fn [cofx [_ network]]
(network/delete cofx {:network network})))
(handlers/register-handler-fx
:network.ui/network-entry-pressed
(fn [cofx [_ network]]
(network/open-network-details cofx network)))

View File

@ -6,34 +6,10 @@
[status-im.ethereum.core :as ethereum]))
(modules/defmodule network
{:save 'status-im.network.core/save
:connect 'status-im.network.core/connect
:delete 'status-im.network.core/delete
:get-network-id-for-chain-id 'status-im.network.core/get-network-id-for-chain-id
:get-network 'status-im.network.core/get-network
:remove-network 'status-im.network.core/remove-network
:edit-network-view 'status-im.network.ui.edit-network.views/edit-network
{:edit-network-view 'status-im.network.ui.edit-network.views/edit-network
:network-settings-view 'status-im.network.ui.views/network-settings
:network-details-view 'status-im.network.ui.network-details.views/network-details})
(defn save [& args]
(apply (get-symbol :save) args))
(defn connect [& args]
(apply (get-symbol :connect) args))
(defn delete [& args]
(apply (get-symbol :delete) args))
(defn get-network-id-for-chain-id [& args]
(apply (get-symbol :get-network-id-for-chain-id) args))
(defn get-network [& args]
(apply (get-symbol :get-network) args))
(defn remove-network [& args]
(apply (get-symbol :remove-network) args))
(defn edit-network-view []
[(get-symbol :edit-network-view)])
@ -42,11 +18,3 @@
(defn network-details-view []
[(get-symbol :network-details-view)])
;; Preloaded handlers, subs, functions
(re-frame/reg-sub
:get-network-id
:<- [:network]
(fn [network]
(ethereum/network->chain-id network)))

View File

@ -1,41 +0,0 @@
(ns status-im.network.subs
(:require [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]))
(defn- filter-networks [network-type]
(fn [network]
(let [chain-id (ethereum/network->chain-id network)
testnet? (ethereum/testnet? chain-id)
custom? (:custom? network)]
(case network-type
:custom custom?
:mainnet (and (not custom?) (not testnet?))
:testnet (and (not custom?) testnet?)))))
(defn- label-networks [default-networks]
(fn [network]
(let [custom? (not (contains? default-networks (:id network)))]
(assoc network :custom? custom?))))
(re-frame/reg-sub
:get-networks
:<- [:multiaccount]
:<- [:networks/networks]
(fn [[{:keys [:networks/networks]} default-networks]]
(let [networks (map (label-networks default-networks) (sort-by :name (vals networks)))
types [:mainnet :testnet :custom]]
(zipmap
types
(map #(filter (filter-networks %) networks) types)))))
(re-frame/reg-sub
:get-manage-network
:<- [:networks/manage]
(fn [manage]
manage))
(re-frame/reg-sub
:manage-network-valid?
:<- [:get-manage-network]
(fn [manage]
(not-any? :error (vals manage))))

View File

@ -10,6 +10,7 @@
[status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.components.list.views :as list]
[status-im.ui.components.text-input.view :as text-input]
[status-im.network.core :as network]
[status-im.network.ui.edit-network.styles :as styles]
[clojure.string :as string]))
@ -21,12 +22,12 @@
:custom (i18n/label :t/custom))]
[list/list-item-with-radio-button
{:checked? (= (get-in manage-network [:chain :value]) type)
:on-value-change #(re-frame/dispatch [:network.ui/input-changed :chain type])}
:on-value-change #(re-frame/dispatch [::network/input-changed :chain type])}
[list/item
nil [list/item-primary-only name]]]))
(views/defview edit-network []
(views/letsubs [manage-network [:get-manage-network]
(views/letsubs [manage-network [:networks/manage]
is-valid? [:manage-network-valid?]]
(let [custom? (= (get-in manage-network [:chain :value]) :custom)]
[react/view styles/container
@ -40,14 +41,14 @@
:placeholder (i18n/label :t/specify-name)
:container styles/input-container
:default-value (get-in manage-network [:name :value])
:on-change-text #(re-frame/dispatch [:network.ui/input-changed :name %])
:on-change-text #(re-frame/dispatch [::network/input-changed :name %])
:auto-focus true}]
[text-input/text-input-with-label
{:label (i18n/label :t/rpc-url)
:placeholder (i18n/label :t/specify-rpc-url)
:container styles/input-container
:default-value (get-in manage-network [:url :value])
:on-change-text #(re-frame/dispatch [:network.ui/input-changed :url (string/lower-case %)])}]
:on-change-text #(re-frame/dispatch [::network/input-changed :url (string/lower-case %)])}]
[react/i18n-text {:key :network-chain}]
[react/view styles/network-type
[list/flat-list {:data [:mainnet :testnet :rinkeby :custom]
@ -59,11 +60,11 @@
{:label (i18n/label :t/network-id)
:container styles/input-container
:placeholder (i18n/label :t/specify-network-id)
:on-change-text #(re-frame/dispatch [:network.ui/input-changed :network-id %])}])]]
:on-change-text #(re-frame/dispatch [::network/input-changed :network-id %])}])]]
[react/view styles/bottom-container
[react/view components.styles/flex]
[components.common/bottom-button
{:forward? true
:label (i18n/label :t/save)
:disabled? (not is-valid?)
:on-press #(re-frame/dispatch [:network.ui/save-network-pressed])}]]]])))
:on-press #(re-frame/dispatch [::network/save-network-pressed])}]]]])))

View File

@ -1,22 +1,22 @@
(ns status-im.network.ui.network-details.views
(:require-macros [status-im.utils.views :as views])
(:require
[re-frame.core :as rf]
[status-im.ui.components.status-bar.view :as status-bar]
[status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.components.react :as react]
[status-im.i18n :as i18n]
[status-im.ui.components.styles :as components.styles]
[status-im.ui.components.common.common :as components.common]
[status-im.network.ui.styles :as st]
[status-im.network.ui.views :as network-settings]))
(:require [re-frame.core :as re-frame]
[status-im.ui.components.status-bar.view :as status-bar]
[status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.components.react :as react]
[status-im.i18n :as i18n]
[status-im.ui.components.styles :as components.styles]
[status-im.ui.components.common.common :as components.common]
[status-im.network.ui.styles :as st]
[status-im.network.core :as network]
[status-im.network.ui.views :as network-settings]))
(views/defview network-details []
(views/letsubs [{:keys [networks/selected-network]} [:get-screen-params]
{:keys [network]} [:multiaccount]
current-network [:networks/current-network]
networks [:get-networks]]
(let [{:keys [id name config]} selected-network
connected? (= id network)
connected? (= id current-network)
custom? (seq (filter #(= (:id %) id) (:custom networks)))]
[react/view st/container
[status-bar/status-bar]
@ -27,7 +27,7 @@
{:name name
:connected? connected?}]
(when-not connected?
[react/touchable-highlight {:on-press #(rf/dispatch [:network.ui/connect-network-pressed id])}
[react/touchable-highlight {:on-press #(re-frame/dispatch [::network/connect-network-pressed id])}
[react/view st/connect-button-container
[react/view {:style st/connect-button
:accessibility-label :network-connect-button}
@ -45,4 +45,4 @@
[components.common/button {:label (i18n/label :t/delete)
:button-style st/delete-button
:label-style st/delete-button-text
:on-press #(rf/dispatch [:network.ui/delete-network-pressed id])}]]])]])))
:on-press #(re-frame/dispatch [::network/delete-network-pressed id])}]]])]])))

View File

@ -1,16 +1,16 @@
(ns status-im.network.ui.views
(:require-macros [status-im.utils.views :as views])
(:require [re-frame.core :as re-frame]
[status-im.i18n :as i18n]
[status-im.ui.components.react :as react]
[status-im.network.core :as network]
[status-im.network.ui.styles :as styles]
[status-im.ui.components.icons.vector-icons :as vector-icons]
[status-im.ui.components.list.views :as list]
[status-im.ui.components.react :as react]
[status-im.ui.components.status-bar.view :as status-bar]
[status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.components.toolbar.actions :as toolbar.actions]
[status-im.ui.components.styles :as components.styles]
[status-im.network.ui.styles :as styles]
status-im.network.events))
[status-im.ui.components.toolbar.actions :as toolbar.actions]
[status-im.ui.components.toolbar.view :as toolbar])
(:require-macros [status-im.utils.views :as views]))
(defn- network-icon [connected? size]
[react/view (styles/network-icon connected? size)
@ -30,7 +30,7 @@
#{"mainnet" "mainnet_rpc"})
(defn navigate-to-network [network]
(re-frame/dispatch [:network.ui/network-entry-pressed network]))
(re-frame/dispatch [::network/network-entry-pressed network]))
(defn render-network [current-network]
(fn [{:keys [id name] :as network}]
@ -48,15 +48,15 @@
(i18n/label :t/connected)])]]])))
(views/defview network-settings []
(views/letsubs [{:keys [network]} [:multiaccount]
networks [:get-networks]]
(views/letsubs [current-network [:networks/current-network]
networks [:get-networks]]
[react/view components.styles/flex
[status-bar/status-bar]
[toolbar/toolbar {}
toolbar/default-nav-back
[toolbar/content-title (i18n/label :t/network-settings)]
[toolbar/actions
[(toolbar.actions/add false #(re-frame/dispatch [:network.ui/add-network-pressed]))]]]
[(toolbar.actions/add false #(re-frame/dispatch [::network/add-network-pressed]))]]]
[react/view styles/wrapper
[list/section-list {:sections [{:title (i18n/label :t/main-networks)
:key :mainnet
@ -69,4 +69,4 @@
:data (:custom networks)}]
:key-fn :id
:default-separator? true
:render-fn (render-network network)}]]]))
:render-fn (render-network current-network)}]]]))

View File

@ -52,9 +52,6 @@
(cond-> {"whisper" {:Min 2, :Max 2}}
les-topic (assoc les-topic {:Min 2, :Max 2}))))
(defn get-multiaccount-network [db address]
(get-in db [:multiaccount address :network]))
(defn- get-base-node-config [config]
(let [initial-props @(re-frame/subscribe [:initial-props])
status-node-port (get initial-props :STATUS_NODE_PORT)]
@ -89,21 +86,22 @@
(assoc-in [:LightEthConfig :MinTrustedFraction] 50))
config))
(defn- get-multiaccount-node-config [db]
(let [multiaccount (:multiaccount db)
current-fleet-key (fleet/current-fleet db)
(defn- get-multiaccount-node-config
[{:keys [multiaccount :networks/networks :networks/current-network]
:or {current-network config/default-network
networks constants/default-networks}
:as db}]
(let [current-fleet-key (fleet/current-fleet db)
current-fleet (get (fleet/fleets db) current-fleet-key)
rendezvous-nodes (pick-nodes 3 (vals (:rendezvous current-fleet)))
{:keys [network installation-id settings bootnodes :networks/networks]
:or {network config/default-network
networks (:networks/networks db)
settings constants/default-multiaccount-settings}} multiaccount
use-custom-bootnodes (get-in settings [:bootnodes network])
{:keys [installation-id settings bootnodes]
:or {settings constants/default-multiaccount-settings}} multiaccount
use-custom-bootnodes (get-in settings [:bootnodes current-network])
log-level (get-log-level settings)
datasync? (:datasync? settings)
disable-discovery-topic? (:disable-discovery-topic? settings)
v1-messages? (:v1-messages? settings)]
(cond-> (get-in networks [network :config])
(cond-> (get-in networks [current-network :config])
:always
(get-base-node-config)
@ -133,13 +131,13 @@
:DisableGenericDiscoveryTopic (boolean disable-discovery-topic?)
:SendV1Messages (boolean v1-messages?)
:PFSEnabled true}
:RequireTopics (get-topics network)
:RequireTopics (get-topics current-network)
:StatusAccountsConfig {:Enabled true})
(and
config/bootnodes-settings-enabled?
use-custom-bootnodes)
(add-custom-bootnodes network bootnodes)
(add-custom-bootnodes current-network bootnodes)
:always
(add-ulc-trusted-nodes (vals (:static current-fleet)))

View File

@ -55,10 +55,10 @@
(semaphores/free cofx :check-sync-state?)))
(fx/defn start-check-sync-state
[{{:keys [network multiaccount] :as db} :db :as cofx}]
[{{:keys [:networks/current-network :networks/networks] :as db} :db :as cofx}]
(when (and (not (semaphores/locked? cofx :check-sync-state?))
(not (ethereum/network-with-upstream-rpc?
(get-in multiaccount [:networks/networks network]))))
(get networks current-network))))
(fx/merge cofx
(check-sync-state)
(semaphores/lock :check-sync-state?))))
@ -66,8 +66,8 @@
(fx/defn initialize-protocol
[{:data-store/keys [mailserver-topics mailservers]
:keys [db] :as cofx}]
(let [network (get-in db [:multiaccount :network])
network-id (str (get-in db [:multiaccount :networks/networks network :config :NetworkId]))]
(let [{:networks/keys [networks current-network]} db
network-id (str (get-in networks [current-network :config :NetworkId]))]
(fx/merge cofx
{:db (assoc db
:rpc-url constants/ethereum-rpc-url
@ -76,14 +76,16 @@
[{:method "net_version"
:on-success
(fn [fetched-network-id]
;;FIXME
#_(when (not= network-id fetched-network-id) 3
(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]))))}]}
(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)
(start-check-sync-state)
(mailserver/initialize-ranges)

View File

@ -80,7 +80,6 @@
(reg-root-key-sub :desktop/desktop :desktop/desktop)
(reg-root-key-sub :desktop :desktop)
(reg-root-key-sub :animations :animations)
(reg-root-key-sub :get-network :network)
(reg-root-key-sub :ui/search :ui/search)
(reg-root-key-sub :web3-node-version :web3-node-version)
(reg-root-key-sub :keyboard-height :keyboard-height)
@ -90,13 +89,17 @@
(reg-root-key-sub :qr-modal :qr-modal)
(reg-root-key-sub :content-layout-height :content-layout-height)
(reg-root-key-sub :bootnodes/manage :bootnodes/manage)
(reg-root-key-sub :networks/current-network :networks/current-network)
(reg-root-key-sub :networks/networks :networks/networks)
(reg-root-key-sub :networks/manage :networks/manage)
(reg-root-key-sub :get-pairing-installations :pairing/installations)
(reg-root-key-sub :network/type :network/type)
(reg-root-key-sub :tooltips :tooltips)
(reg-root-key-sub :supported-biometric-auth :supported-biometric-auth)
;;NOTE this one is not related to ethereum network
;; it is about cellular network/ wifi network
(reg-root-key-sub :network/type :network/type)
;;profile
(reg-root-key-sub :my-profile/seed :my-profile/seed)
(reg-root-key-sub :my-profile/advanced? :my-profile/advanced?)
@ -191,18 +194,38 @@
(fn [desktop _]
(get desktop :logging-enabled false)))
;;TODO we have network in two different places see :multiaccount/network, what's the difference?
(re-frame/reg-sub
:network
:<- [:multiaccount]
(fn [current-multiaccount]
(get (:networks/networks current-multiaccount) (:network current-multiaccount))))
:current-network
:<- [:networks/networks]
:<- [:networks/current-network]
(fn [[networks current-network]]
(when-let [network (get networks current-network)]
(assoc network
:rpc-network? (get-in network [:config :UpstreamConfig :Enabled])))))
(re-frame/reg-sub
:chain-name
:<- [:current-network]
(fn [network]
(ethereum/network->chain-name network)))
(re-frame/reg-sub
:chain-id
:<- [:current-network]
(fn [network]
(ethereum/network->chain-id network)))
(re-frame/reg-sub
:mainnet?
:<- [:chain-id]
(fn [chain-id]
(= 1 chain-id)))
(re-frame/reg-sub
:network-name
:<- [:network]
:<- [:current-network]
(fn [network]
(ethereum/network->chain-keyword network)))
(:name network)))
(re-frame/reg-sub
:disconnected?
@ -313,7 +336,7 @@
(re-frame/reg-sub
:ethereum/chain-keyword
:<- [:network]
:<- [:current-network]
(fn [network]
(ethereum/network->chain-keyword network)))
@ -356,26 +379,6 @@
(fn [acc]
(get acc :settings)))
;;TODO we have network in two different places see :network, what's the difference?
(re-frame/reg-sub
:multiaccount/network
:<- [:multiaccount]
:<- [:get-network]
(fn [[multiaccount network]]
(get-in multiaccount [:networks/networks network])))
(re-frame/reg-sub
:current-network-initialized?
:<- [:multiaccount/network]
(fn [network]
(boolean network)))
(re-frame/reg-sub
:current-network-uses-rpc?
:<- [:multiaccount/network]
(fn [network]
(get-in network [:config :UpstreamConfig :Enabled])))
(re-frame/reg-sub
:latest-block-number
(fn [{:node/keys [latest-block-number]} _]
@ -800,15 +803,16 @@
(re-frame/reg-sub
:settings/bootnodes-enabled
:<- [:multiaccount]
(fn [multiaccount]
(let [{:keys [network settings]} multiaccount]
(get-in settings [:bootnodes network]))))
:<- [:networks/current-network]
(fn [{:keys [settings]} current-network]
(get-in settings [:bootnodes current-network])))
(re-frame/reg-sub
:settings/network-bootnodes
:<- [:multiaccount]
(fn [multiaccount]
(get-in multiaccount [:bootnodes (:network multiaccount)])))
:<- [:networks/current-network]
(fn [multiaccount current-network]
(get-in multiaccount [:bootnodes current-network])))
(re-frame/reg-sub
:get-manage-bootnode
@ -1776,7 +1780,7 @@
(re-frame/reg-sub
:ens.stateofus/registrar
:<- [:multiaccount/network]
:<- [:current-network]
(fn [network]
(let [chain (ethereum/network->chain-keyword network)]
(get stateofus/registrars chain))))
@ -1898,3 +1902,36 @@
(get-sufficient-funds-error balance (:symbol token) amount-bn))]
(or amount-error (get-sufficient-gas-error balance (:symbol token) amount-bn gas gasPrice)))
(get-sufficient-gas-error balance nil nil gas gasPrice))))
;; NETWORK SETTINGS
(defn- filter-networks [network-type]
(fn [network]
(let [chain-id (ethereum/network->chain-id network)
testnet? (ethereum/testnet? chain-id)
custom? (:custom? network)]
(case network-type
:custom custom?
:mainnet (and (not custom?) (not testnet?))
:testnet (and (not custom?) testnet?)))))
(defn- label-networks [default-networks]
(fn [network]
(let [custom? (not (contains? default-networks (:id network)))]
(assoc network :custom? custom?))))
(re-frame/reg-sub
:get-networks
:<- [:networks/networks]
(fn [networks]
(let [networks (map (label-networks constants/default-networks) (sort-by :name (vals networks)))
types [:mainnet :testnet :custom]]
(zipmap
types
(map #(filter (filter-networks %) networks) types)))))
(re-frame/reg-sub
:manage-network-valid?
:<- [:networks/manage]
(fn [manage]
(not-any? :error (vals manage))))

View File

@ -42,7 +42,7 @@
[top-shadow]])
(defview network-info [{:keys [text-color]}]
(letsubs [network-id [:get-network-id]]
(letsubs [network-id [:chain-id]]
[react/view
[react/view styles/network-container
[react/view styles/network-icon

View File

@ -155,7 +155,7 @@
{:keys [accounts settings]} [:multiaccount]
{:keys [browser-id dapp? name unsafe?] :as browser} [:get-current-browser]
{:keys [url error? loading? url-editing? show-tooltip show-permission resolving?]} [:browser/options]
network-id [:get-network-id]]
network-id [:chain-id]]
(let [can-go-back? (browser/can-go-back? browser)
can-go-forward? (browser/can-go-forward? browser)
url-original (browser/get-current-url browser)

View File

@ -178,7 +178,7 @@
(defview input-container []
(letsubs [margin [:chats/input-margin]
network [:get-network]
mainnet? [:mainnet?]
{:keys [input-text]} [:chats/current-chat]
result-box [:chats/current-chat-ui-prop :result-box]
show-stickers? [:chats/current-chat-ui-prop :show-stickers?]
@ -202,7 +202,7 @@
[reply-message-view]
[react/view {:style style/input-container}
[input-view {:single-line-input? single-line-input? :set-text set-text :state-text state-text}]
(when (and input-text-empty? (string/starts-with? network "mainnet"))
(when (and input-text-empty? mainnet?)
[stickers/button show-stickers?])
(if input-text-empty?
[commands-button]

View File

@ -178,7 +178,7 @@
[vector-icons/icon :main-icons/warning {:color colors/red}]]]])
(defview command-status [{{:keys [network]} :params}]
(letsubs [current-network [:network-name]]
(letsubs [current-network [:chain-name]]
(when (and network (not= current-network network))
[react/view style/not-sent-view
[react/text {:style style/not-sent-text}

View File

@ -39,8 +39,6 @@
:peers-summary []
:notifications {}
:semaphores #{}
:network constants/default-network
:networks/networks constants/default-networks
:my-profile/editing? false
:transport/filters {}
:transport/message-envelopes {}

View File

@ -24,9 +24,8 @@
(views/defview les-debug-info []
(views/letsubs [sync-state [:chain-sync-state]
latest-block-number [:latest-block-number]
rpc-network? [:current-network-uses-rpc?]
network-initialized? [:current-network-initialized?]]
(when (and network-initialized? (not rpc-network?))
{:keys [rpc-network?] :as network} [:current-network]]
(when (and network (not rpc-network?))
[react/view {:style styles/sync-wrapper}
[react/touchable-highlight {:on-press #(re-frame/dispatch [:home.ui/sync-info-pressed])}
[react/text {:style styles/sync-info}

View File

@ -129,13 +129,13 @@
:action-fn #(re-frame/dispatch [:multiaccounts.logout.ui/logout-pressed])}]]]]))
(defview advanced-settings
[{:keys [network :networks/networks chaos-mode? dev-mode? settings]} on-show supported-biometric-auth]
[{:keys [chaos-mode? dev-mode? settings]} network-name on-show supported-biometric-auth]
{:component-did-mount on-show}
[react/view
(when dev-mode?
[profile.components/settings-item
{:label-kw :t/network
:value (get-in networks [network :name])
:value network-name
:action-fn #(re-frame/dispatch [:navigate-to :network-settings])
:accessibility-label :network-button}])
[profile.components/settings-item-separator]
@ -206,7 +206,7 @@
:active? (some? supported-biometric-auth)
:action-fn #(re-frame/dispatch [:multiaccounts.ui/biometric-auth-switched %])}])])
(defview advanced [params on-show]
(defview advanced [multiaccount network-name on-show]
(letsubs [advanced? [:my-profile/advanced?]
supported-biometric-auth [:supported-biometric-auth]]
{:component-will-unmount #(re-frame/dispatch [:set :my-profile/advanced? false])}
@ -220,7 +220,7 @@
(i18n/label :t/advanced)]
[icons/icon (if advanced? :main-icons/dropdown-up :main-icons/dropdown) {:color colors/blue}]]]]]
(when advanced?
[advanced-settings params on-show supported-biometric-auth])]))
[advanced-settings multiaccount network-name on-show supported-biometric-auth])]))
(defn contacts-list-item [active-contacts-count]
[list.views/big-list-item
@ -287,6 +287,7 @@
(letsubs [list-ref (reagent/atom nil)
{:keys [public-key photo-path preferred-name]
:as current-multiaccount} [:multiaccount]
network-name [:network-name]
changed-multiaccount [:my-profile/profile]
currency [:wallet/currency]
login-data [:multiaccounts/login]
@ -311,7 +312,7 @@
(when tribute-to-talk [tribute-to-talk-item tribute-to-talk])
[my-profile-settings current-multiaccount shown-multiaccount
currency (nil? login-data)]
(when (nil? login-data) [advanced shown-multiaccount on-show-advanced])]]
(when (nil? login-data) [advanced shown-multiaccount network-name on-show-advanced])]]
[(react/safe-area-view) {:style {:flex 1}}
[status-bar/status-bar {:type :main}]
[large-toolbar/minimized-toolbar header-in-toolbar nil toolbar-action-items]

View File

@ -64,7 +64,7 @@
(views/defview share-address []
(views/letsubs [{:keys [address]} [:popover/popover]
chain-id [:get-network-id]
chain-id [:chain-id]
width (reagent/atom nil)]
[react/view
[react/view {:style {:padding-top 16 :padding-left 16 :padding-right 16}}

View File

@ -1,170 +0,0 @@
(ns status-im.test.models.network
(:require [cljs.test :refer-macros [deftest is testing]]
[status-im.network.core :as model]
[reagent.core :as reagent]))
(deftest valid-rpc-url-test
(testing "nil?"
(is (not (model/valid-rpc-url? nil))))
(testing "a blank url"
(is (not (model/valid-rpc-url? ""))))
(testing "a url without a protocol"
(is (not (model/valid-rpc-url? "something"))))
(testing "a url without a protocol"
(is (not (model/valid-rpc-url? "http://something with space"))))
(testing "a url without a hostname"
(is (not (model/valid-rpc-url? "https://"))))
(testing "an uppercase HTTP url"
(is (not (model/valid-rpc-url? "HTTP://valid.com"))))
(testing "an http url"
(is (model/valid-rpc-url? "http://valid.com")))
(testing "an https url"
(is (model/valid-rpc-url? "https://valid.something.else")))
(testing "a fully qualified url"
(is (model/valid-rpc-url? "https://mainnet.infura.io:6523/v3/f315575765b14720b32382a61a89341a")))
(testing "an ip address"
(is (model/valid-rpc-url? "https://192.168.1.1")))
(testing "localhost"
(is (model/valid-rpc-url? "https://localhost")))
(testing "a fully qualified url, ip address"
(is (model/valid-rpc-url? "https://192.168.1.1:6523/z6GCTmjdP3FETEJmMBI4")))
(testing "an https url not on the default port"
(is (model/valid-rpc-url? "https://valid.something.else:65323"))))
(deftest new-network-test
(let [actual (model/new-network "random-id"
"network-name"
"upstream-url"
:mainnet
nil)]
(is (= {:id "randomid"
:name "network-name"
:config {:NetworkId 1
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}
actual))))
(deftest new-network-id-test
(let [actual (model/new-network "random-id"
"network-name"
"upstream-url"
:mainnet
"5777")]
(is (= {:id "randomid"
:name "network-name"
:config {:NetworkId 5777
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}
actual))))
(deftest valid-manage-test
(testing "a valid manage"
(is (model/valid-manage? {:url {:value "http://valid.com"}
:name {:value "valid"}
:chain {:value "valid"}})))
(testing "invalid url"
(is (not (model/valid-manage? {:url {:value "invalid"}
:name {:value "valid"}
:chain {:value "valid"}}))))
(testing "invalid name"
(is (not (model/valid-manage? {:url {:value "http://valid.com"}
:name {:value ""}
:chain {:value "valid"}}))))
(testing "invalid chain"
(is (not (model/valid-manage? {:url {:value "http://valid.com"}
:name {:value "valid"}
:chain {:value ""}})))))
(deftest set-input-test
(testing "it updates and validate a field"
(is (= {:db {:networks/manage {:url {:value "http://valid.com"
:error false}
:name {:value ""
:error true}
:chain {:value "mainnet"
:error false}
:network-id {:value nil
:error false}}}}
(model/set-input {:db {:networks/manage {:url {:value "something"
:error true}
:name {:value ""
:error false}
:chain {:value "mainnet"
:error false}}}}
:url "http://valid.com")))))
(deftest not-save-invalid-url
(testing "it does not save a network with an invalid url"
(is (nil? (model/save {:random-id-generator (constantly "random")
:db {:networks/manage {:url {:value "wrong"}
:chain {:value "1"}
:name {:value "empty"}}
:multiaccount {}}}
{})))))
(deftest save-valid-network
(testing "save a valid network"
(is (some? (model/save {:random-id-generator (constantly "random")
:db {:networks/manage {:url {:value "http://valid.com"}
:chain {:value "mainnet"}
:name {:value "valid"}}
:multiaccount {}}}
{})))))
(deftest not-save-non-unique-id
(testing "it does not save a network with network-id already defined"
(let [failure (reagent/atom false)]
(do (model/save {:random-id-generator (constantly "random")
:db {:networks/manage {:url {:value "http://valid.com"}
:chain {:value :mainnet}
:name {:value "valid"}}
:multiaccount {:networks/networks {"randomid"
{:id "randomid"
:name "network-name"
:config {:NetworkId 1
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}}}}}
{:chain-id-unique? true
:on-failure #(reset! failure true)})
(is @failure)))))
(deftest save-valid-network-with-unique-check
(testing "save a valid network with network-id not already defined"
(is (some? (model/save {:random-id-generator (constantly "random")
:db {:networks/manage {:url {:value "http://valid.com"}
:chain {:value :mainnet}
:name {:value "valid"}}
:multiaccount {:networks/networks {"randomid"
{:id "randomid"
:name "network-name"
:config {:NetworkId 3
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}}}}}
{:chain-id-unique? true})))))
(deftest save-with-id-override
(testing "save a valid network with id override"
(let [result (model/save {:random-id-generator (constantly "random")
:db {:networks/manage {:url {:value "http://valid.com"}
:chain {:value :mainnet}
:name {:value "valid"}}
:multiaccount {}}}
{:network-id "override"})]
(is (some? (get-in result [:db :multiaccount :networks/networks "override"]))))))
(deftest get-network-id-for-chain-id
(testing "get the first network id for the given chain-id"
(is (= "randomid" (model/get-network-id-for-chain-id {:db {:multiaccount {:networks/networks {"randomid"
{:id "randomid"
:name "network-name"
:config {:NetworkId 1
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}}}}}
1)))))

View File

@ -1,11 +0,0 @@
(ns status-im.test.multiaccounts.login.core
(:require [cljs.test :refer-macros [deftest is testing]]
[status-im.multiaccounts.login.core :as login]
[clojure.string :as string]))
(deftest initialize-multiaccount-db
(testing "it preserves universal-links/url"
(is (= "some-url" (get-in (login/initialize-multiaccount-db
{:db {:universal-links/url "some-url"}}
"address")
[:db :universal-links/url])))))

View File

@ -0,0 +1,162 @@
(ns status-im.test.network.core
(:require [cljs.test :refer-macros [deftest is testing]]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.network.core :as network.core]
[reagent.core :as reagent]))
(deftest valid-rpc-url-test
(testing "nil?"
(is (not (network.core/valid-rpc-url? nil))))
(testing "a blank url"
(is (not (network.core/valid-rpc-url? ""))))
(testing "a url without a protocol"
(is (not (network.core/valid-rpc-url? "something"))))
(testing "a url without a protocol"
(is (not (network.core/valid-rpc-url? "http://something with space"))))
(testing "a url without a hostname"
(is (not (network.core/valid-rpc-url? "https://"))))
(testing "an uppercase HTTP url"
(is (not (network.core/valid-rpc-url? "HTTP://valid.com"))))
(testing "an http url"
(is (network.core/valid-rpc-url? "http://valid.com")))
(testing "an https url"
(is (network.core/valid-rpc-url? "https://valid.something.else")))
(testing "a fully qualified url"
(is (network.core/valid-rpc-url? "https://mainnet.infura.io:6523/v3/f315575765b14720b32382a61a89341a")))
(testing "an ip address"
(is (network.core/valid-rpc-url? "https://192.168.1.1")))
(testing "localhost"
(is (network.core/valid-rpc-url? "https://localhost")))
(testing "a fully qualified url, ip address"
(is (network.core/valid-rpc-url? "https://192.168.1.1:6523/z6GCTmjdP3FETEJmMBI4")))
(testing "an https url not on the default port"
(is (network.core/valid-rpc-url? "https://valid.something.else:65323"))))
(deftest new-network-test
(let [actual (network.core/new-network "randomid"
"network-name"
"upstream-url"
:mainnet
nil)]
(is (= {:id "randomid"
:name "network-name"
:config {:NetworkId 1
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}
actual))))
(deftest new-network-id-test
(let [actual (network.core/new-network "randomid"
"network-name"
"upstream-url"
:mainnet
"5777")]
(is (= {:id "randomid"
:name "network-name"
:config {:NetworkId 5777
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}
actual))))
(deftest valid-manage-test
(testing "a valid manage"
(is (network.core/valid-manage? {:url {:value "http://valid.com"}
:name {:value "valid"}
:chain {:value "valid"}})))
(testing "invalid url"
(is (not (network.core/valid-manage? {:url {:value "invalid"}
:name {:value "valid"}
:chain {:value "valid"}}))))
(testing "invalid name"
(is (not (network.core/valid-manage? {:url {:value "http://valid.com"}
:name {:value ""}
:chain {:value "valid"}}))))
(testing "invalid chain"
(is (not (network.core/valid-manage? {:url {:value "http://valid.com"}
:name {:value "valid"}
:chain {:value ""}})))))
(deftest set-input-test
(testing "it updates and validate a field"
(is (= {:db {:networks/manage {:url {:value "http://valid.com"
:error false}
:name {:value ""
:error true}
:chain {:value "mainnet"
:error false}
:network-id {:value nil
:error false}}}}
(network.core/set-input {:db {:networks/manage {:url {:value "something"
:error true}
:name {:value ""
:error false}
:chain {:value "mainnet"
:error false}}}}
:url "http://valid.com")))))
(deftest not-save-invalid-url
(testing "it does not save a network with an invalid url"
(is (:ui/show-error (network.core/save {:random-id-generator (constantly "random")
:db {:networks/manage {:url {:value "wrong"}
:chain {:value "1"}
:name {:value "empty"}}
:multiaccount {}}})))))
(deftest save-valid-network
(testing "save a valid network"
(let [fx (network.core/save {:random-id-generator (constantly "random-id")
:db {:networks/manage {:url {:value "http://valid.com"}
:chain {:value :mainnet}
:name {:value "valid"}}
:multiaccount {}
:networks/networks {"random2"
{:id "random2"
:name "network-name"
:config {:NetworkId 1
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}}}})]
(is (= "settings_saveConfig" (:method (first (::json-rpc/call fx)))))
(is (nil? (:networks/manage (:db fx))))
(testing "and check that it has an id with `-` and the correct mainnet NetworkId"
(is (= 1 (get-in fx [:db :networks/networks "randomid" :config :NetworkId])))))))
(deftest not-save-custom-chain-with-non-unique-id
(testing "it does not save a custom chain with network-id already defined"
(let [result (network.core/save {:random-id-generator (constantly "already-defined")
:db {:networks/manage {:url {:value "http://valid.com"}
:chain {:value :custom}
:name {:value "valid"}
:network-id {:value 1}}
:multiaccount {}
:networks/networks {"random"
{:id "random"
:name "network-name"
:config {:NetworkId 1
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}}}})]
(is (:ui/show-error result)))))
(deftest save-valid-network-with-unique-chain-id-check
(testing "save a valid network with chain-id not already defined"
(let [fx (network.core/save {:random-id-generator (constantly "random")
:db {:networks/manage {:url {:value "http://valid.com"}
:chain {:value :mainnet}
:name {:value "valid"}
:network-id {:value 5}}
:multiaccount {}
:networks/networks {"randomid"
{:id "randomid"
:name "network-name"
:config {:NetworkId 3
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}}}})]
(is (= "settings_saveConfig" (:method (first (::json-rpc/call fx)))))
(is (nil? (:networks/manage (:db fx))))
(is (get-in fx [:db :networks/networks "random"])))))

View File

@ -34,11 +34,10 @@
[status-im.test.mailserver.topics]
[status-im.test.models.bootnode]
[status-im.test.models.contact]
[status-im.test.models.network]
[status-im.test.multiaccounts.model]
[status-im.test.multiaccounts.login.core]
[status-im.test.multiaccounts.recover.core]
[status-im.test.multiaccounts.update.core]
[status-im.test.network.core]
[status-im.test.pairing.core]
[status-im.test.search.core]
[status-im.test.sign-in.flow]
@ -117,11 +116,10 @@
'status-im.test.mailserver.topics
'status-im.test.models.bootnode
'status-im.test.models.contact
'status-im.test.models.network
'status-im.test.multiaccounts.model
'status-im.test.multiaccounts.recover.core
'status-im.test.multiaccounts.login.core
'status-im.test.multiaccounts.update.core
'status-im.test.network.core
'status-im.test.pairing.core
'status-im.test.search.core
'status-im.test.sign-in.flow

View File

@ -85,12 +85,12 @@
{public-key {:tribute-to-talk {}
:system-tags #{}}}
:multiaccount
{:public-key my-public-key
:network "mainnet_rpc"
:networks/networks {"mainnet_rpc" {:id "mainnet_rpc"
:config {:NetworkId 1}}
"testnet_rpc" {:id "testnet_rpc"
:config {:NetworkId 3}}}}})
{:public-key my-public-key}
:networks/current-network "mainnet_rpc"
:networks/networks {"mainnet_rpc" {:id "mainnet_rpc"
:config {:NetworkId 1}}
"testnet_rpc" {:id "testnet_rpc"
:config {:NetworkId 3}}}})
(deftest check-tribute
(testing "No contract in network, own public key"
@ -106,8 +106,8 @@
(get-in result [:db :contacts/contacts public-key :tribute-to-talk])))))
(testing "Contract in network, another public key"
(let [result (tribute-to-talk/check-tribute {:db
(assoc-in test-db [:multiaccount :network] "testnet_rpc")} public-key)]
(let [result (tribute-to-talk/check-tribute {:db (assoc test-db :networks/current-network "testnet_rpc")}
public-key)]
(is (= "0xC61aa0287247a0398589a66fCD6146EC0F295432"
(get-in result [:tribute-to-talk/get-tribute :contract])))))

View File

@ -68,9 +68,9 @@
(def sender-address "0xdff1a5e4e57d9723b3294e0f4413372e3ea9a8ff")
(def ttt-enabled-multiaccount
{:db {:multiaccount {:network "testnet_rpc"
:networks/networks {"testnet_rpc" {:config {:NetworkId 3}}}
:settings {:tribute-to-talk {:testnet {:snt-amount "1000000000000000000"}}}}
{:db {:multiaccount {:settings {:tribute-to-talk {:testnet {:snt-amount "1000000000000000000"}}}}
:networks/current-network "testnet_rpc"
:networks/networks {"testnet_rpc" {:config {:NetworkId 3}}}
:contacts/contacts user-contacts
:wallet {:transactions
{"transaction-hash-1"
@ -80,9 +80,9 @@
:ethereum/current-block 8}})
(def ttt-disabled-multiaccount
{:db {:multiaccount {:network "testnet_rpc"
:networks/networks {"testnet_rpc" {:config {:NetworkId 3}}}
:settings {:tribute-to-talk {}}}
{:db {:multiaccount {:settings {:tribute-to-talk {}}}
:networks/current-network "testnet_rpc"
:networks/networks {"testnet_rpc" {:config {:NetworkId 3}}}
:contacts/contacts user-contacts}})
(deftest enable-whitelist