mirror of
https://github.com/status-im/status-mobile.git
synced 2025-02-07 14:24:20 +00:00
[fix 3806] Provide separate MailServers for each network
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
4de886241c
commit
3612fd8c47
@ -38,7 +38,9 @@
|
||||
|
||||
(def default-account-settings
|
||||
{:wallet {:visible-tokens {:testnet #{:STT}
|
||||
:mainnet #{:SNT}}}})
|
||||
:mainnet #{:SNT}}}
|
||||
:wnode {:testnet "main"
|
||||
:mainnet "main"}})
|
||||
|
||||
(defn- transform-config [networks]
|
||||
(->> networks
|
||||
@ -87,19 +89,17 @@
|
||||
(merge testnet-networks
|
||||
(when config/mainnet-networks-enabled? mainnet-networks))))
|
||||
|
||||
;; adamb's status-cluster enode
|
||||
(def default-wnode "main")
|
||||
|
||||
(def default-wnodes
|
||||
{"main" {:id "main"
|
||||
:name "Status mailserver A"
|
||||
:address "enode://fa63a6cc730468c5456eab365b2a7a68a166845423c8c9acc363e5f8c4699ff6d954e7ec58f13ae49568600cff9899561b54f6fc2b9923136cd7104911f31cce@163.172.168.202:30303"}
|
||||
"backup" {:id "backup"
|
||||
:name "Status mailserver B"
|
||||
:address "enode://90cbf961c87eb837adc1300a0a6722a57134d843f0028a976d35dff387f101a2754842b6b694e50a01093808f304440d4d968bcbc599259e895ff26e5a1a17cf@51.15.194.39:30303"}})
|
||||
{:testnet {"main" {:id "main"
|
||||
:name "Status testnet mailserver A"
|
||||
:address "enode://fa63a6cc730468c5456eab365b2a7a68a166845423c8c9acc363e5f8c4699ff6d954e7ec58f13ae49568600cff9899561b54f6fc2b9923136cd7104911f31cce@163.172.168.202:30303"}
|
||||
"backup" {:id "backup"
|
||||
:name "Status testnet mailserver B"
|
||||
:address "enode://90cbf961c87eb837adc1300a0a6722a57134d843f0028a976d35dff387f101a2754842b6b694e50a01093808f304440d4d968bcbc599259e895ff26e5a1a17cf@51.15.194.39:30303"}}
|
||||
:mainnet {"main" {:id "main"
|
||||
:name "Status mainnet mailserver"
|
||||
:address "enode://b963569aac14785f756ecf97e7549a513dea993a1bc744c4f8efe2b4e9479500dd3f5d18f3da19f6550b8bd0d8770350950c9a7da8168b44865402dcc9a51657@51.15.35.110:30403"}}})
|
||||
|
||||
;; TODO(oskarth): Determine if this is the correct topic or not
|
||||
(def inbox-topic "0xaabb11ee")
|
||||
(def inbox-password "status-offline-inbox")
|
||||
|
||||
;; Used to generate topic for contact discoveries
|
||||
|
@ -18,7 +18,6 @@
|
||||
:network :string
|
||||
:networks {:type :list
|
||||
:objectType :network}
|
||||
:wnode :string
|
||||
:settings {:type :string}
|
||||
:sharing-usage-data? {:type :bool :default false}
|
||||
:dev-mode? {:type :bool :default false}
|
||||
|
@ -5,7 +5,8 @@
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.transport.utils :as web3.utils]
|
||||
[status-im.utils.config :as config]
|
||||
[taoensso.timbre :as log]))
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.utils.ethereum.core :as ethereum]))
|
||||
|
||||
(defn- parse-json
|
||||
;; NOTE(dmitryn) Expects JSON response like:
|
||||
@ -35,14 +36,18 @@
|
||||
(error-fn error)
|
||||
(success-fn result)))))
|
||||
|
||||
(defn get-current-wnode-address [{:accounts/keys [current-account-id accounts] :as db}]
|
||||
(let [network (ethereum/network->chain-keyword (get db :network))
|
||||
wnode-id (get-in accounts [current-account-id :settings :wnode network])]
|
||||
(get-in db [:inbox/wnodes network wnode-id :address])))
|
||||
|
||||
(defn initialize-offline-inbox
|
||||
"Initialises offline inbox by producing `::add-peer` effect if inboxing enabled in config,
|
||||
then the event chan is:
|
||||
add-peer -> fetch-peers -> check-peer-added -> mark-trusted-peer -> get-sym-key -> request-messages"
|
||||
[{:keys [db]}]
|
||||
(when config/offline-inbox-enabled?
|
||||
(let [wnode-id (get db :inbox/wnode)
|
||||
wnode (get-in db [:inbox/wnodes wnode-id :address])]
|
||||
(let [wnode (get-current-wnode-address db)]
|
||||
(log/info "offline inbox: initialize")
|
||||
{::add-peer {:wnode wnode}})))
|
||||
|
||||
@ -91,10 +96,6 @@
|
||||
(success-fn resp)
|
||||
(error-fn err topic))))))))
|
||||
|
||||
(defn get-wnode [db]
|
||||
(let [wnode-id (get db :inbox/wnode)]
|
||||
(get-in db [:inbox/wnodes wnode-id :address])))
|
||||
|
||||
(re-frame/reg-fx
|
||||
::add-peer
|
||||
(fn [{:keys [wnode]}]
|
||||
@ -144,7 +145,7 @@
|
||||
;; if not we dispatch a new fetch-peer event for later
|
||||
(fn [{:keys [db]} [_ peers retries]]
|
||||
(let [web3 (:web3 db)
|
||||
wnode (get-wnode db)]
|
||||
wnode (get-current-wnode-address db)]
|
||||
(log/info "offline inbox: fetch-peers response" peers)
|
||||
(if (registered-peer? peers wnode)
|
||||
{::mark-trusted-peer {:web3 web3
|
||||
@ -163,7 +164,7 @@
|
||||
;; with add-peer
|
||||
(fn [{:keys [db]} [_ response]]
|
||||
(let [web3 (:web3 db)
|
||||
wnode (get-wnode db)
|
||||
wnode (get-current-wnode-address db)
|
||||
password (:inbox/password db)]
|
||||
(log/info "offline inbox: mark-trusted-peer response" wnode response)
|
||||
{:shh/generate-sym-key-from-password {:password password
|
||||
@ -179,7 +180,7 @@
|
||||
(fn [{:keys [db]} [_ sym-key-id]]
|
||||
(log/info "offline inbox: get-sym-key response") sym-key-id
|
||||
(let [web3 (:web3 db)
|
||||
wnode (get-wnode db)
|
||||
wnode (get-current-wnode-address db)
|
||||
topics (map #(:topic %) (vals (:transport/chats db)))
|
||||
to nil
|
||||
from nil]
|
||||
|
@ -49,11 +49,10 @@
|
||||
|
||||
(defn add-account
|
||||
"Takes db and new account, creates map of effects describing adding account to database and realm"
|
||||
[{:keys [network inbox/wnode] :networks/keys [networks] :as db} {:keys [address] :as account}]
|
||||
[{:keys [network] :networks/keys [networks] :as db} {:keys [address] :as account}]
|
||||
(let [enriched-account (assoc account
|
||||
:network network
|
||||
:networks networks
|
||||
:wnode wnode
|
||||
:address address)]
|
||||
{:db (assoc-in db [:accounts/accounts address] enriched-account)
|
||||
:data-store/save-account enriched-account}))
|
||||
@ -106,10 +105,11 @@
|
||||
{:db (assoc-in db [:accounts/accounts id] new-account)
|
||||
:data-store/save-account new-account})))
|
||||
|
||||
(defn update-wallet-settings [{:accounts/keys [current-account-id accounts] :as db} settings]
|
||||
(let [new-account (-> (get accounts current-account-id)
|
||||
(assoc :settings settings))]
|
||||
{:db (assoc-in db [:accounts/accounts current-account-id] new-account)
|
||||
(defn update-settings [settings {:keys [db] :as cofx}]
|
||||
(let [{:accounts/keys [current-account-id accounts]} db
|
||||
new-account (-> (get accounts current-account-id)
|
||||
(assoc :settings settings))]
|
||||
{:db (assoc-in db [:accounts/accounts current-account-id] new-account)
|
||||
:data-store/save-account new-account}))
|
||||
|
||||
(defn account-update
|
||||
|
@ -67,9 +67,6 @@
|
||||
{:network network
|
||||
:config config}))
|
||||
|
||||
(defn get-wnode-by-address [db address]
|
||||
(get-in db [:accounts/accounts address :wnode] constants/default-wnode))
|
||||
|
||||
(defn wrap-with-initialize-geth-fx [db address password]
|
||||
(let [{:keys [network config]} (get-network-by-address db address)]
|
||||
{:initialize-geth-fx config
|
||||
@ -91,9 +88,7 @@
|
||||
:login-account
|
||||
(fn [{{:keys [network status-node-started?] :as db} :db} [_ address password]]
|
||||
(let [{account-network :network} (get-network-by-address db address)
|
||||
wnode (get-wnode-by-address db address)
|
||||
db' (-> db
|
||||
(assoc :inbox/wnode wnode)
|
||||
(assoc-in [:accounts/login :processing] true))
|
||||
wrap-fn (cond (not status-node-started?)
|
||||
wrap-with-initialize-geth-fx
|
||||
|
@ -41,9 +41,7 @@
|
||||
:notifications {}
|
||||
:network constants/default-network
|
||||
:networks/networks constants/default-networks
|
||||
:inbox/wnode constants/default-wnode
|
||||
:inbox/wnodes constants/default-wnodes
|
||||
:inbox/topic constants/inbox-topic
|
||||
:inbox/password constants/inbox-password
|
||||
:my-profile/editing? false
|
||||
:transport/chats {}
|
||||
@ -162,9 +160,7 @@
|
||||
:networks/networks
|
||||
:node/after-start
|
||||
:node/after-stop
|
||||
:inbox/wnode
|
||||
:inbox/wnodes
|
||||
:inbox/topic
|
||||
:inbox/password
|
||||
:browser/browsers
|
||||
:browser/options
|
||||
|
@ -244,10 +244,8 @@
|
||||
(fn [{:keys [accounts/accounts accounts/create contacts/contacts networks/networks
|
||||
network network-status view-id navigation-stack
|
||||
access-scope->commands-responses
|
||||
status-module-initialized? status-node-started?
|
||||
inbox/wnode]
|
||||
:or [network (get app-db :network)
|
||||
wnode (get app-db :inbox/wnode)]} [_ address]]
|
||||
status-module-initialized? status-node-started?]
|
||||
:or [network (get app-db :network)]} [_ address]]
|
||||
(let [console-contact (get contacts constants/console-chat-id)]
|
||||
(cond-> (assoc app-db
|
||||
:access-scope->commands-responses access-scope->commands-responses
|
||||
@ -264,8 +262,7 @@
|
||||
:accounts/create create
|
||||
:networks/networks networks
|
||||
:network-status network-status
|
||||
:network network
|
||||
:inbox/wnode wnode)
|
||||
:network network)
|
||||
console-contact
|
||||
(assoc :contacts/contacts {constants/console-chat-id console-contact})))))
|
||||
|
||||
@ -278,7 +275,7 @@
|
||||
[:load-contacts]
|
||||
[:load-contact-groups]
|
||||
[:initialize-chats]
|
||||
[:initialize-browsers]
|
||||
[:initialize-browsers]
|
||||
[:initialize-debugging {:address address}]
|
||||
[:send-account-update-if-needed]
|
||||
[:update-wallet]
|
||||
|
@ -11,7 +11,5 @@
|
||||
(spec/def :wnode/id ::not-blank-string)
|
||||
(spec/def :wnode/wnode (allowed-keys :req-un [:wnode/address :wnode/name :wnode/id]))
|
||||
|
||||
(spec/def :inbox/topic ::not-blank-string)
|
||||
(spec/def :inbox/password ::not-blank-string)
|
||||
(spec/def :inbox/wnode ::not-blank-string)
|
||||
(spec/def :inbox/wnodes (spec/nilable (spec/map-of :wnode/id :wnode/wnode)))
|
||||
(spec/def :inbox/wnodes (spec/nilable (spec/map-of keyword? (spec/map-of :wnode/id :wnode/wnode))))
|
||||
|
@ -3,22 +3,26 @@
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.ui.screens.accounts.events :as accounts-events]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.transport.core :as transport]))
|
||||
[status-im.transport.core :as transport]
|
||||
[status-im.utils.ethereum.core :as ethereum]))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
::save-wnode
|
||||
(fn [{:keys [db now] :as cofx} [_ wnode]]
|
||||
(handlers/merge-fx cofx
|
||||
{:dispatch [:navigate-to-clean :accounts]}
|
||||
(accounts-events/account-update {:wnode wnode :last-updated now})
|
||||
(transport/stop-whisper))))
|
||||
(let [{:accounts/keys [current-account-id accounts]} db
|
||||
network (ethereum/network->chain-keyword (:network db))
|
||||
settings (get-in accounts [current-account-id :settings])]
|
||||
(handlers/merge-fx cofx
|
||||
{:dispatch [:logout]}
|
||||
(accounts-events/update-settings (assoc-in settings [:wnode network] wnode))))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:connect-wnode
|
||||
(fn [{:keys [db]} [_ wnode]]
|
||||
{:show-confirmation {:title (i18n/label :t/close-app-title)
|
||||
:content (i18n/label :t/connect-wnode-content
|
||||
{:name (get-in db [:inbox/wnodes wnode :name])})
|
||||
:confirm-button-text (i18n/label :t/close-app-button)
|
||||
:on-accept #(dispatch [::save-wnode wnode])
|
||||
:on-cancel nil}}))
|
||||
(let [network (ethereum/network->chain-keyword (:network db))]
|
||||
{:show-confirmation {:title (i18n/label :t/close-app-title)
|
||||
:content (i18n/label :t/connect-wnode-content
|
||||
{:name (get-in db [:inbox/wnodes network wnode :name])})
|
||||
:confirm-button-text (i18n/label :t/close-app-button)
|
||||
:on-accept #(dispatch [::save-wnode wnode])
|
||||
:on-cancel nil}})))
|
||||
|
@ -0,0 +1,17 @@
|
||||
(ns status-im.ui.screens.offline-messaging-settings.subs
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.utils.ethereum.core :as ethereum]))
|
||||
|
||||
(re-frame/reg-sub :settings/current-wnode
|
||||
:<- [:network]
|
||||
:<- [:get-current-account]
|
||||
(fn [[network current-account]]
|
||||
(let [chain (ethereum/network->chain-keyword network)]
|
||||
(get-in current-account [:settings :wnode chain]))))
|
||||
|
||||
(re-frame/reg-sub :settings/network-wnodes
|
||||
:<- [:network]
|
||||
:<- [:get :inbox/wnodes]
|
||||
(fn [[network wnodes]]
|
||||
(let [chain (ethereum/network->chain-keyword network)]
|
||||
(chain wnodes))))
|
@ -26,8 +26,8 @@
|
||||
name]]]])))
|
||||
|
||||
(views/defview offline-messaging-settings []
|
||||
(views/letsubs [current-wnode [:get :inbox/wnode]
|
||||
wnodes [:get :inbox/wnodes]]
|
||||
(views/letsubs [current-wnode [:settings/current-wnode]
|
||||
wnodes [:settings/network-wnodes]]
|
||||
[react/view {:flex 1}
|
||||
[status-bar/status-bar]
|
||||
[toolbar/simple-toolbar (i18n/label :t/offline-messaging-settings)]
|
||||
|
@ -13,6 +13,7 @@
|
||||
status-im.ui.screens.wallet.settings.subs
|
||||
status-im.ui.screens.wallet.transactions.subs
|
||||
status-im.ui.screens.network-settings.subs
|
||||
status-im.ui.screens.offline-messaging-settings.subs
|
||||
status-im.ui.screens.browser.subs
|
||||
status-im.bots.subs
|
||||
status-im.ui.screens.add-new.new-chat.subs
|
||||
|
@ -10,11 +10,8 @@
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:wallet.settings/toggle-visible-token
|
||||
(fn [{{:keys [network] :accounts/keys [current-account-id] :as db} :db} [_ symbol checked?]]
|
||||
(fn [{{:keys [network] :accounts/keys [current-account-id] :as db} :db :as cofx} [_ symbol checked?]]
|
||||
(let [chain (ethereum/network->chain-keyword network)
|
||||
path [:accounts/accounts current-account-id :settings]
|
||||
settings (get-in db path)
|
||||
settings (get-in db [:accounts/accounts current-account-id :settings])
|
||||
new-settings (update-in settings [:wallet :visible-tokens chain] #(toggle-checked % symbol checked?))]
|
||||
(-> db
|
||||
(assoc-in path new-settings)
|
||||
(accounts/update-wallet-settings new-settings)))))
|
||||
(accounts/update-settings new-settings cofx))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user