fix fleet settings not being saved to node config
Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
463b4111b2
commit
3528dd809a
|
@ -3,27 +3,15 @@
|
|||
[status-im.multiaccounts.update.core :as multiaccounts.update]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.node.core :as node]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.types :as types]
|
||||
[status-im.utils.fx :as fx])
|
||||
(:require-macros [status-im.utils.slurp :refer [slurp]]))
|
||||
|
||||
(defn current-fleet
|
||||
[db]
|
||||
(keyword (get-in db [:multiaccount :settings :fleet] config/fleet)))
|
||||
[status-im.utils.fx :as fx]))
|
||||
|
||||
(defn current-fleet-sub [settings]
|
||||
(keyword (or (get settings :fleet)
|
||||
config/fleet)))
|
||||
|
||||
(def default-fleets (slurp "resources/config/fleets.json"))
|
||||
|
||||
(defn fleets [{:keys [custom-fleets]}]
|
||||
(as-> [(default-fleets)] $
|
||||
(mapv #(:fleets (types/json->clj %)) $)
|
||||
(conj $ custom-fleets)
|
||||
(reduce merge $)))
|
||||
|
||||
(defn format-mailserver
|
||||
[mailserver address]
|
||||
{:id mailserver
|
||||
|
@ -42,16 +30,18 @@
|
|||
(reduce (fn [acc [fleet node-by-type]]
|
||||
(assoc acc fleet (format-mailservers (:mail node-by-type))))
|
||||
{}
|
||||
(fleets db)))
|
||||
(node/fleets db)))
|
||||
|
||||
(fx/defn show-save-confirmation
|
||||
[{:keys [db] :as cofx} fleet]
|
||||
{:ui/show-confirmation {:title (i18n/label :t/close-app-title)
|
||||
:content (i18n/label :t/change-fleet
|
||||
{:fleet fleet})
|
||||
:confirm-button-text (i18n/label :t/close-app-button)
|
||||
:on-accept #(re-frame/dispatch [:fleet.ui/save-fleet-confirmed (keyword fleet)])
|
||||
:on-cancel nil}})
|
||||
{:ui/show-confirmation
|
||||
{:title (i18n/label :t/close-app-title)
|
||||
:content (i18n/label :t/change-fleet
|
||||
{:fleet fleet})
|
||||
:confirm-button-text (i18n/label :t/close-app-button)
|
||||
:on-accept
|
||||
#(re-frame/dispatch [:fleet.ui/save-fleet-confirmed (keyword fleet)])
|
||||
:on-cancel nil}})
|
||||
|
||||
(defn nodes->fleet [nodes]
|
||||
(letfn [(format-nodes [nodes]
|
||||
|
@ -79,9 +69,15 @@
|
|||
|
||||
(fx/defn save
|
||||
[{:keys [db now] :as cofx} fleet]
|
||||
(let [settings (get-in db [:multiaccount :settings])]
|
||||
(multiaccounts.update/update-settings cofx
|
||||
(if fleet
|
||||
(assoc settings :fleet fleet)
|
||||
(dissoc settings :fleet))
|
||||
{:success-event [:multiaccounts.update.callback/save-settings-success]})))
|
||||
(let [settings (get-in db [:multiaccount :settings])
|
||||
new-settings (if fleet
|
||||
(assoc settings :fleet fleet)
|
||||
(dissoc settings :fleet))]
|
||||
(fx/merge cofx
|
||||
(multiaccounts.update/update-settings new-settings {})
|
||||
(node/prepare-new-config
|
||||
{:on-success
|
||||
#(when (not= fleet
|
||||
(:fleet settings))
|
||||
(re-frame/dispatch
|
||||
[:multiaccounts.update.callback/save-settings-success]))}))))
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
(assoc settings :log-level log-level)
|
||||
(dissoc settings :log-level))]
|
||||
(fx/merge cofx
|
||||
(multiaccounts.update/update-settings new-settings
|
||||
{})
|
||||
(node/prepare-new-config {:on-success #(when (not= (node/get-log-level settings) (node/get-log-level new-settings))
|
||||
(multiaccounts.update/update-settings new-settings {})
|
||||
(node/prepare-new-config {:on-success #(when (not= (node/get-log-level settings)
|
||||
(node/get-log-level new-settings))
|
||||
(re-frame/dispatch [:logout]))}))))
|
||||
|
||||
(fx/defn show-change-log-level-confirmation
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
[re-frame.core :as re-frame]
|
||||
[status-im.data-store.mailservers :as data-store.mailservers]
|
||||
[status-im.ethereum.json-rpc :as json-rpc]
|
||||
[status-im.fleet.core :as fleet]
|
||||
[status-im.node.core :as node]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.mailserver.constants :as constants]
|
||||
[status-im.mailserver.topics :as mailserver.topics]
|
||||
|
@ -44,13 +44,13 @@
|
|||
(= (:mailserver/current-id db) id))
|
||||
|
||||
(defn fetch [{:keys [db] :as cofx} id]
|
||||
(get-in db [:mailserver/mailservers (fleet/current-fleet db) id]))
|
||||
(get-in db [:mailserver/mailservers (node/current-fleet-key db) id]))
|
||||
|
||||
(defn fetch-current [{:keys [db] :as cofx}]
|
||||
(fetch cofx (:mailserver/current-id db)))
|
||||
|
||||
(defn preferred-mailserver-id [{:keys [db] :as cofx}]
|
||||
(get-in db [:multiaccount :settings :mailserver (fleet/current-fleet db)]))
|
||||
(get-in db [:multiaccount :settings :mailserver (node/current-fleet-key db)]))
|
||||
|
||||
(defn- round-robin
|
||||
"Find the choice and pick the next one, default to first if not found"
|
||||
|
@ -71,7 +71,7 @@
|
|||
"Use the preferred mailserver if set & exists, otherwise picks one randomly
|
||||
if current-id is not set, else round-robin"
|
||||
[{:keys [db] :as cofx}]
|
||||
(let [current-fleet (fleet/current-fleet db)
|
||||
(let [current-fleet (node/current-fleet-key db)
|
||||
current-id (:mailserver/current-id db)
|
||||
preference (preferred-mailserver-id cofx)
|
||||
choices (-> db :mailserver/mailservers current-fleet keys)]
|
||||
|
@ -162,7 +162,7 @@
|
|||
|
||||
(fx/defn generate-mailserver-symkey
|
||||
[{:keys [db] :as cofx} {:keys [password id] :as mailserver}]
|
||||
(let [current-fleet (fleet/current-fleet db)]
|
||||
(let [current-fleet (node/current-fleet-key db)]
|
||||
{:db (assoc-in db [:mailserver/mailservers current-fleet id :generating-sym-key?] true)
|
||||
:shh/generate-sym-key-from-password
|
||||
[{:password password
|
||||
|
@ -414,7 +414,7 @@
|
|||
add sym-key to the mailserver in app-db and request messages if
|
||||
mailserver is ready"
|
||||
[{:keys [db] :as cofx} {:keys [id]} sym-key-id]
|
||||
(let [current-fleet (fleet/current-fleet db)]
|
||||
(let [current-fleet (node/current-fleet-key db)]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:mailserver/mailservers current-fleet id :sym-key-id] sym-key-id)
|
||||
|
@ -427,7 +427,7 @@
|
|||
[{:keys [db] :as cofx}]
|
||||
(when-not (zero? (:peers-count db))
|
||||
(if-let [preferred-mailserver (preferred-mailserver-id cofx)]
|
||||
(let [current-fleet (fleet/current-fleet db)]
|
||||
(let [current-fleet (node/current-fleet-key db)]
|
||||
{:db
|
||||
(update-mailserver-state db :error)
|
||||
:ui/show-confirmation
|
||||
|
@ -976,7 +976,7 @@
|
|||
[{{:mailserver.edit/keys [mailserver] :keys [multiaccount] :as db} :db
|
||||
random-id-generator :random-id-generator :as cofx}]
|
||||
(let [{:keys [name url id]} mailserver
|
||||
current-fleet (fleet/current-fleet db)
|
||||
current-fleet (node/current-fleet-key db)
|
||||
mailserver (build
|
||||
(or (:value id)
|
||||
(keyword (string/replace (random-id-generator) "-" "")))
|
||||
|
@ -1008,7 +1008,7 @@
|
|||
[{:keys [db] :as cofx} id]
|
||||
(if (can-delete? cofx id)
|
||||
{:db (update-in db
|
||||
[:mailserver/mailservers (fleet/current-fleet db)]
|
||||
[:mailserver/mailservers (node/current-fleet-key db)]
|
||||
dissoc id)
|
||||
::json-rpc/call
|
||||
[{:method "mailservers_deleteMailserver"
|
||||
|
@ -1020,7 +1020,7 @@
|
|||
|
||||
(fx/defn show-connection-confirmation
|
||||
[{:keys [db]} mailserver-id]
|
||||
(let [current-fleet (fleet/current-fleet db)]
|
||||
(let [current-fleet (node/current-fleet-key db)]
|
||||
{:ui/show-confirmation
|
||||
{:title (i18n/label :t/close-app-title)
|
||||
:content (i18n/label :t/connect-mailserver-content
|
||||
|
@ -1058,7 +1058,7 @@
|
|||
|
||||
(fx/defn unpin
|
||||
[{:keys [db] :as cofx}]
|
||||
(let [current-fleet (fleet/current-fleet db)
|
||||
(let [current-fleet (node/current-fleet-key db)
|
||||
settings (get-in db [:multiaccount :settings])]
|
||||
(fx/merge cofx
|
||||
(multiaccounts.update/update-settings (update settings :mailserver dissoc current-fleet)
|
||||
|
@ -1067,7 +1067,7 @@
|
|||
|
||||
(fx/defn pin
|
||||
[{:keys [db] :as cofx}]
|
||||
(let [current-fleet (fleet/current-fleet db)
|
||||
(let [current-fleet (node/current-fleet-key db)
|
||||
mailserver-id (:mailserver/current-id db)
|
||||
settings (get-in db [:multiaccount :settings])]
|
||||
(fx/merge cofx
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
[status-im.fleet.core :as fleet]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.node.core :as node]
|
||||
[status-im.protocol.core :as protocol]
|
||||
[status-im.stickers.core :as stickers]
|
||||
[status-im.ui.screens.mobile-network-settings.events :as mobile-network]
|
||||
|
@ -34,7 +35,7 @@
|
|||
(def contract-fleet? #{:eth.contract})
|
||||
|
||||
(defn fetch-nodes [current-fleet resolve reject]
|
||||
(let [default-nodes (-> (fleet/fleets {})
|
||||
(let [default-nodes (-> (node/fleets {})
|
||||
(get-in [:eth.beta :mail])
|
||||
vals)]
|
||||
(if config/contract-nodes-enabled?
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.ethereum.json-rpc :as json-rpc]
|
||||
[status-im.fleet.core :as fleet]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.fx :as fx]
|
||||
[status-im.utils.platform :as utils.platform]
|
||||
[status-im.utils.types :as types]))
|
||||
[status-im.utils.types :as types])
|
||||
(:require-macros [status-im.utils.slurp :refer [slurp]]))
|
||||
|
||||
(defn- add-custom-bootnodes [config network all-bootnodes]
|
||||
(let [bootnodes (as-> all-bootnodes $
|
||||
|
@ -28,7 +28,8 @@
|
|||
:LogEnabled true)))
|
||||
|
||||
(defn get-network-genesis-hash-prefix
|
||||
"returns the hex representation of the first 8 bytes of a network's genesis hash"
|
||||
"returns the hex representation of the first 8 bytes of
|
||||
a network's genesis hash"
|
||||
[network]
|
||||
(case network
|
||||
1 "d4e56740f876aef8"
|
||||
|
@ -74,13 +75,30 @@
|
|||
(if utils.platform/desktop? ""
|
||||
config/log-level-status-go)))
|
||||
|
||||
(def default-fleets (slurp "resources/config/fleets.json"))
|
||||
|
||||
(defn fleets [{:keys [custom-fleets]}]
|
||||
(as-> [(default-fleets)] $
|
||||
(mapv #(:fleets (types/json->clj %)) $)
|
||||
(conj $ custom-fleets)
|
||||
(reduce merge $)))
|
||||
|
||||
(defn current-fleet-key [db]
|
||||
(keyword (get-in db [:multiaccount :settings :fleet]
|
||||
config/fleet)))
|
||||
|
||||
(defn get-current-fleet
|
||||
[db]
|
||||
(get (fleets db)
|
||||
(current-fleet-key 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)
|
||||
(let [current-fleet-key (current-fleet-key db)
|
||||
current-fleet (get-current-fleet db)
|
||||
rendezvous-nodes (pick-nodes 3 (vals (:rendezvous current-fleet)))
|
||||
{:keys [installation-id settings bootnodes]
|
||||
:or {settings constants/default-multiaccount-settings}} multiaccount
|
||||
|
@ -98,9 +116,14 @@
|
|||
:Rendezvous (not (empty? rendezvous-nodes))
|
||||
:ClusterConfig {:Enabled true
|
||||
:Fleet (name current-fleet-key)
|
||||
:BootNodes (pick-nodes 4 (vals (:boot current-fleet)))
|
||||
:TrustedMailServers (pick-nodes 6 (vals (:mail current-fleet)))
|
||||
:StaticNodes (into (pick-nodes 2 (vals (:whisper current-fleet))) (vals (:static current-fleet)))
|
||||
:BootNodes
|
||||
(pick-nodes 4 (vals (:boot current-fleet)))
|
||||
:TrustedMailServers
|
||||
(pick-nodes 6 (vals (:mail current-fleet)))
|
||||
:StaticNodes
|
||||
(into (pick-nodes 2
|
||||
(vals (:whisper current-fleet)))
|
||||
(vals (:static current-fleet)))
|
||||
:RendezvousNodes rendezvous-nodes})
|
||||
|
||||
:always
|
||||
|
@ -112,15 +135,16 @@
|
|||
:LightClient true
|
||||
:MinimumPoW 0.001
|
||||
:EnableNTPSync true}
|
||||
:ShhextConfig {:BackupDisabledDataDir (utils.platform/no-backup-directory)
|
||||
:InstallationID installation-id
|
||||
:MaxMessageDeliveryAttempts config/max-message-delivery-attempts
|
||||
:MailServerConfirmations config/mailserver-confirmations-enabled?
|
||||
:DataSyncEnabled (boolean datasync?)
|
||||
:DisableGenericDiscoveryTopic (boolean disable-discovery-topic?)
|
||||
:SendV1Messages (boolean v1-messages?)
|
||||
:PFSEnabled true}
|
||||
:RequireTopics (get-topics current-network)
|
||||
:ShhextConfig
|
||||
{:BackupDisabledDataDir (utils.platform/no-backup-directory)
|
||||
:InstallationID installation-id
|
||||
:MaxMessageDeliveryAttempts config/max-message-delivery-attempts
|
||||
:MailServerConfirmations config/mailserver-confirmations-enabled?
|
||||
:DataSyncEnabled (boolean datasync?)
|
||||
:DisableGenericDiscoveryTopic (boolean disable-discovery-topic?)
|
||||
:SendV1Messages (boolean v1-messages?)
|
||||
:PFSEnabled true}
|
||||
:RequireTopics (get-topics current-network)
|
||||
:StatusAccountsConfig {:Enabled true})
|
||||
|
||||
(and
|
||||
|
@ -138,8 +162,9 @@
|
|||
(fx/defn save-new-config
|
||||
"Saves a new status-go config for the current account
|
||||
This RPC method is the only way to change the node config of an account.
|
||||
NOTE: it is better used indirectly through `prepare-new-config`, which will take
|
||||
care of building up the proper config based on settings in app-db"
|
||||
NOTE: it is better used indirectly through `prepare-new-config`,
|
||||
which will take care of building up the proper config based on settings in
|
||||
app-db"
|
||||
{:events [::save-new-config]}
|
||||
[{:keys [db]} config {:keys [on-success]}]
|
||||
{::json-rpc/call [{:method "settings_saveNodeConfig"
|
||||
|
@ -150,9 +175,10 @@
|
|||
"Use this function to apply settings to the current account node config"
|
||||
[{:keys [db]} {:keys [on-success]}]
|
||||
{::prepare-new-config [(get-new-config db)
|
||||
#(re-frame/dispatch [::save-new-config % {:on-success on-success}])]})
|
||||
#(re-frame/dispatch
|
||||
[::save-new-config % {:on-success on-success}])]})
|
||||
|
||||
(re-frame/reg-fx
|
||||
::prepare-new-config
|
||||
(fn [[config callback]]
|
||||
(status/prepare-dir-and-update-config config callback)))
|
||||
(status/prepare-dir-and-update-config config callback)))
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
[status-im.ui.components.status-bar.view :as status-bar]
|
||||
[status-im.ui.components.toolbar.view :as toolbar]
|
||||
[status-im.ui.screens.fleet-settings.styles :as styles]
|
||||
[status-im.fleet.core :as fleet-core]
|
||||
[status-im.node.core :as node]
|
||||
[status-im.utils.platform :as platform])
|
||||
(:require-macros [status-im.utils.views :as views]))
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
|||
fleet]]]])))
|
||||
|
||||
(defn fleets [custom-fleets]
|
||||
(map name (keys (fleet-core/fleets {:custom-fleets custom-fleets}))))
|
||||
(map name (keys (node/fleets {:custom-fleets custom-fleets}))))
|
||||
|
||||
(views/defview fleet-settings []
|
||||
(views/letsubs [custom-fleets [:fleets/custom-fleets]
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
(ns status-im.test.fleet.core
|
||||
(:require [cljs.test :refer-macros [deftest is testing]]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.fleet.core :as fleet]))
|
||||
[status-im.fleet.core :as fleet]
|
||||
[status-im.node.core :as node]))
|
||||
|
||||
(deftest fleets-test
|
||||
(testing "not passing any extra fleet"
|
||||
|
@ -12,17 +13,17 @@
|
|||
:eth.test
|
||||
:eth.contract}
|
||||
(into #{}
|
||||
(keys (fleet/fleets {})))))))
|
||||
(keys (node/fleets {})))))))
|
||||
(testing "passing a custom fleet"
|
||||
(testing "it sets the custom fleet"
|
||||
(is (= {:mail {"a" "a"}
|
||||
:whisper {"w" "w"}
|
||||
:boot {"b" "b"}}
|
||||
(:custom-fleet
|
||||
(fleet/fleets {:custom-fleets {:custom-fleet
|
||||
{:mail {"a" "a"}
|
||||
:whisper {"w" "w"}
|
||||
:boot {"b" "b"}}}})))))))
|
||||
(node/fleets {:custom-fleets {:custom-fleet
|
||||
{:mail {"a" "a"}
|
||||
:whisper {"w" "w"}
|
||||
:boot {"b" "b"}}}})))))))
|
||||
|
||||
(deftest set-nodes-test
|
||||
(testing "set-nodes"
|
||||
|
@ -47,4 +48,3 @@
|
|||
:password constants/mailserver-password
|
||||
:address "c"}}
|
||||
actual-mailservers))))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue