Add custom mailservers feature-toggled

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2018-05-21 12:40:50 +02:00
parent 732de57444
commit 735a5b403d
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
30 changed files with 384 additions and 46 deletions

View File

@ -19,3 +19,4 @@ DEBUG_WEBVIEW=1
INSTABUG_SURVEYS=1 INSTABUG_SURVEYS=1
GROUP_CHATS_ENABLED=1 GROUP_CHATS_ENABLED=1
FORCE_SENT_RECEIVED_TRACKING=1 FORCE_SENT_RECEIVED_TRACKING=1
ADD_CUSTOM_MAILSERVERS_ENABLED=0

View File

@ -21,3 +21,4 @@ INSTABUG_SURVEYS=1
GROUP_CHATS_ENABLED=0 GROUP_CHATS_ENABLED=0
FORCE_SENT_RECEIVED_TRACKING=0 FORCE_SENT_RECEIVED_TRACKING=0
USE_SYM_KEY=0 USE_SYM_KEY=0
ADD_CUSTOM_MAILSERVERS_ENABLED=0

View File

@ -9,6 +9,7 @@
status-im.data-store.browser status-im.data-store.browser
status-im.data-store.accounts status-im.data-store.accounts
status-im.data-store.local-storage status-im.data-store.local-storage
status-im.data-store.mailservers
status-im.data-store.requests)) status-im.data-store.requests))
(defn init [encryption-key] (defn init [encryption-key]
@ -19,9 +20,16 @@
(defn change-account [address new-account? encryption-key handler] (defn change-account [address new-account? encryption-key handler]
(data-source/change-account address new-account? encryption-key handler)) (data-source/change-account address new-account? encryption-key handler))
(defn- perform-transactions [transactions realm] (defn- perform-transactions [raw-transactions realm]
(let [success-events (->> raw-transactions
(map :success-event)
(filter identity))
transactions (map (fn [{:keys [transaction] :as f}]
(or transaction f)) raw-transactions)]
(data-source/write realm #(doseq [transaction transactions] (data-source/write realm #(doseq [transaction transactions]
(transaction realm)))) (transaction realm)))
(doseq [event success-events]
(re-frame/dispatch event))))
(re-frame/reg-fx (re-frame/reg-fx
:data-store/base-tx :data-store/base-tx

View File

@ -0,0 +1,19 @@
(ns status-im.data-store.mailservers
(:require [re-frame.core :as re-frame]
[status-im.data-store.realm.core :as core]))
(re-frame/reg-cofx
:data-store/get-all-mailservers
(fn [cofx _]
(assoc cofx :data-store/mailservers (-> @core/account-realm
(core/get-all :mailserver)
(core/all-clj :mailserver)))))
(defn save-mailserver-tx
"Returns tx function for saving a mailserver"
[{:keys [id] :as mailserver}]
(fn [realm]
(core/create realm
:mailserver
mailserver
(core/exists? realm :mailserver :id id))))

View File

@ -59,23 +59,9 @@
(close migrated-realm))) (close migrated-realm)))
(open-realm (last schemas) file-name encryption-key)) (open-realm (last schemas) file-name encryption-key))
(defn reset-realm [file-name schemas encryption-key]
(utils/show-popup "Important: Wallet Upgrade" "The Status Wallet will be upgraded in this release. The 12 mnemonic words will generate different addresses and whisper identities (public key). Given that we changed the algorithm used to generate keys and addresses, it will be impossible to re-import accounts created with the old algorithm in Status. Please create a new account.")
(delete-realm file-name)
(open-realm (last schemas) file-name encryption-key))
(defn open-migrated-realm (defn open-migrated-realm
[file-name schemas encryption-key] [file-name schemas encryption-key]
;; TODO: remove for release 0.9.20
;; delete the realm file if its schema version is higher
;; than existing schema version (this means the previous
;; install has incompatible database schemas)
(if-let [current-version (realm-version file-name encryption-key)]
(if (> current-version
(apply max (map :schemaVersion base/schemas)))
(reset-realm file-name schemas encryption-key)
(migrate-realm file-name schemas encryption-key)) (migrate-realm file-name schemas encryption-key))
(reset-realm file-name schemas encryption-key)))
(defn- index-entity-schemas [all-schemas] (defn- index-entity-schemas [all-schemas]
(into {} (map (juxt :name identity)) (-> all-schemas last :schema))) (into {} (map (juxt :name identity)) (-> all-schemas last :schema)))

View File

@ -1,10 +1,14 @@
(ns status-im.data-store.realm.schemas.account.core (ns status-im.data-store.realm.schemas.account.core
(:require [status-im.data-store.realm.schemas.account.v1.core :as v1])) (:require [status-im.data-store.realm.schemas.account.v1.core :as v1]
[status-im.data-store.realm.schemas.account.v2.core :as v2]))
;; TODO(oskarth): Add failing test if directory vXX exists but isn't in schemas. ;; TODO(oskarth): Add failing test if directory vXX exists but isn't in schemas.
;; put schemas ordered by version ;; put schemas ordered by version
(def schemas [{:schema v1/schema (def schemas [{:schema v1/schema
:schemaVersion 1 :schemaVersion 1
:migration v1/migration}]) :migration v1/migration}
{:schema v2/schema
:schemaVersion 2
:migration v2/migration}])

View File

@ -0,0 +1,24 @@
(ns status-im.data-store.realm.schemas.account.v2.core
(:require [status-im.data-store.realm.schemas.account.v1.chat :as chat]
[status-im.data-store.realm.schemas.account.v1.transport :as transport]
[status-im.data-store.realm.schemas.account.v1.contact :as contact]
[status-im.data-store.realm.schemas.account.v1.message :as message]
[status-im.data-store.realm.schemas.account.v1.request :as request]
[status-im.data-store.realm.schemas.account.v1.user-status :as user-status]
[status-im.data-store.realm.schemas.account.v1.local-storage :as local-storage]
[status-im.data-store.realm.schemas.account.v2.mailserver :as mailserver]
[status-im.data-store.realm.schemas.account.v1.browser :as browser]
[taoensso.timbre :as log]))
(def schema [chat/schema
transport/schema
contact/schema
message/schema
request/schema
mailserver/schema
user-status/schema
local-storage/schema
browser/schema])
(defn migration [old-realm new-realm]
(log/debug "migrating v2 account database: " old-realm new-realm))

View File

@ -0,0 +1,11 @@
(ns status-im.data-store.realm.schemas.account.v2.mailserver
(:require [taoensso.timbre :as log]))
(def schema {:name :mailserver
:primaryKey :id
:properties {:id :string
:name {:type :string}
:address {:type :string}
:password {:type :string
:optional true}
:chain {:type :string}}})

View File

@ -9,6 +9,7 @@
[status-im.utils.handlers-macro :as handlers-macro] [status-im.utils.handlers-macro :as handlers-macro]
[status-im.utils.web3-provider :as web3-provider] [status-im.utils.web3-provider :as web3-provider]
[status-im.transport.core :as transport] [status-im.transport.core :as transport]
[status-im.transport.inbox :as transport.inbox]
[status-im.utils.ethereum.core :as ethereum])) [status-im.utils.ethereum.core :as ethereum]))
;;;; COFX ;;;; COFX
@ -35,19 +36,23 @@
(fn [] (fn []
(status/init-jail))) (status/init-jail)))
;;; INITIALIZE PROTOCOL (defn initialize-protocol
(handlers/register-handler-fx [{:data-store/keys [transport mailservers] :keys [db web3] :as cofx} [current-account-id ethereum-rpc-url]]
:initialize-protocol
[re-frame/trim-v
(re-frame/inject-cofx ::get-web3)
(re-frame/inject-cofx :data-store/transport)]
(fn [{:data-store/keys [transport] :keys [db web3] :as cofx} [current-account-id ethereum-rpc-url]]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:db (assoc db {:db (assoc db
:web3 web3 :web3 web3
:rpc-url (or ethereum-rpc-url constants/ethereum-rpc-url) :rpc-url (or ethereum-rpc-url constants/ethereum-rpc-url)
:transport/chats transport)} :transport/chats transport)}
(transport/init-whisper current-account-id)))) (transport.inbox/add-custom-mailservers mailservers)
(transport/init-whisper current-account-id)))
;;; INITIALIZE PROTOCOL
(handlers/register-handler-fx
:initialize-protocol
[re-frame/trim-v
(re-frame/inject-cofx ::get-web3)
(re-frame/inject-cofx :data-store/get-all-mailservers)
(re-frame/inject-cofx :data-store/transport)]
initialize-protocol)
;;; NODE SYNC STATE ;;; NODE SYNC STATE

View File

@ -587,6 +587,9 @@
:delete-network-confirmation "Are you sure you want to delete this network?" :delete-network-confirmation "Are you sure you want to delete this network?"
;; TODO(dmitryn): come up with better description/naming. Suggested namings: Mailbox and Master Node ;; TODO(dmitryn): come up with better description/naming. Suggested namings: Mailbox and Master Node
:existing-wnodes "Existing mailservers" :existing-wnodes "Existing mailservers"
:add-mailserver "Add Mailserver"
:mailserver-address "Mailserver address"
:specify-mailserver-address "Specify a mailserver address"
:add-json-file "Add a JSON file" :add-json-file "Add a JSON file"
:paste-json-as-text "Paste JSON as text" :paste-json-as-text "Paste JSON as text"
:paste-json "Paste JSON" :paste-json "Paste JSON"
@ -601,8 +604,8 @@
:network-details "Network details" :network-details "Network details"
:remove-network "Remove network" :remove-network "Remove network"
:network-settings "Network settings" :network-settings "Network settings"
:offline-messaging "Offline messages" :offline-messaging "Mailserver"
:offline-messaging-settings "Offline messages settings" :offline-messaging-settings "Mailserver settings"
:edit-network-warning "Be careful, editing the network data may disable this network for you" :edit-network-warning "Be careful, editing the network data may disable this network for you"
:delete-network-error "Please connect to a different network before deleting this one" :delete-network-error "Please connect to a different network before deleting this one"
:connecting-requires-login "Connecting to another network requires login" :connecting-requires-login "Connecting to another network requires login"

View File

@ -3,6 +3,7 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.utils.handlers :as handlers] [status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.transport.utils :as transport.utils] [status-im.transport.utils :as transport.utils]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@ -179,6 +180,15 @@
(def ^:private ^:const max-retries 10) (def ^:private ^:const max-retries 10)
(def ^:private ^:const retries-interval-change-threshold 3) (def ^:private ^:const retries-interval-change-threshold 3)
(defn add-custom-mailservers [mailservers {:keys [db]}]
{:db (reduce (fn [db {:keys [id chain] :as mailserver}]
(assoc-in db [:inbox/wnodes (keyword chain) id]
(-> mailserver
(dissoc :chain)
(assoc :user-defined true))))
db
mailservers)})
(handlers/register-handler-fx (handlers/register-handler-fx
:inbox/check-peer-added :inbox/check-peer-added
;; We check if the wnode is part of the peers list ;; We check if the wnode is part of the peers list
@ -205,7 +215,8 @@
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
(let [web3 (:web3 db) (let [web3 (:web3 db)
wnode (get-current-wnode-address db) wnode (get-current-wnode-address db)
password (:inbox/password db)] password (or (:password wnode)
(:inbox/password db))]
{:shh/generate-sym-key-from-password {:password password {:shh/generate-sym-key-from-password {:password password
:web3 web3 :web3 web3
:on-success (fn [_ sym-key-id] :on-success (fn [_ sym-key-id]

View File

@ -107,10 +107,13 @@
{:db (assoc-in db [:accounts/accounts id] new-account) {:db (assoc-in db [:accounts/accounts id] new-account)
:data-store/base-tx [(accounts-store/save-account-tx new-account)]}))) :data-store/base-tx [(accounts-store/save-account-tx new-account)]})))
(defn update-settings [settings {{:keys [account/account] :as db} :db :as cofx}] (defn update-settings
([settings cofx] (update-settings settings nil cofx))
([settings success-event {{:keys [account/account] :as db} :db :as cofx}]
(let [new-account (assoc account :settings settings)] (let [new-account (assoc account :settings settings)]
{:db (assoc db :account/account new-account) {:db (assoc db :account/account new-account)
:data-store/base-tx [(accounts-store/save-account-tx new-account)]})) :data-store/base-tx [{:transaction (accounts-store/save-account-tx new-account)
:success-event success-event}]})))
(handlers/register-handler-fx (handlers/register-handler-fx
:send-account-update-if-needed :send-account-update-if-needed

View File

@ -164,6 +164,7 @@
:networks/selected-network :networks/selected-network
:networks/networks :networks/networks
:networks/manage :networks/manage
:mailservers/manage
:node/after-start :node/after-start
:node/after-stop :node/after-stop
:inbox/wnodes :inbox/wnodes

View File

@ -12,7 +12,7 @@
status-im.ui.screens.contacts.events status-im.ui.screens.contacts.events
status-im.ui.screens.group.chat-settings.events status-im.ui.screens.group.chat-settings.events
status-im.ui.screens.group.events status-im.ui.screens.group.events
status-im.ui.screens.navigation [status-im.ui.screens.navigation :as navigation]
status-im.ui.screens.add-new.new-chat.navigation status-im.ui.screens.add-new.new-chat.navigation
status-im.ui.screens.network-settings.events status-im.ui.screens.network-settings.events
status-im.ui.screens.profile.events status-im.ui.screens.profile.events
@ -263,6 +263,7 @@
[:load-accounts] [:load-accounts]
[:listen-to-network-status] [:listen-to-network-status]
[:navigate-to :accounts]]} [:navigate-to :accounts]]}
(navigation/navigate-to-clean nil)
(transport/stop-whisper))) (transport/stop-whisper)))
{::get-encryption-key-fx this-event}))) {::get-encryption-key-fx this-event})))

View File

@ -2,6 +2,7 @@
(:require [re-frame.core :refer [dispatch dispatch-sync after] :as re-frame] (:require [re-frame.core :refer [dispatch dispatch-sync after] :as re-frame]
[status-im.utils.handlers :refer [register-handler] :as handlers] [status-im.utils.handlers :refer [register-handler] :as handlers]
status-im.ui.screens.network-settings.edit-network.events status-im.ui.screens.network-settings.edit-network.events
status-im.ui.screens.offline-messaging-settings.edit-mailserver.events
[status-im.utils.handlers-macro :as handlers-macro] [status-im.utils.handlers-macro :as handlers-macro]
[status-im.ui.screens.accounts.utils :as accounts.utils] [status-im.ui.screens.accounts.utils :as accounts.utils]
[status-im.i18n :as i18n] [status-im.i18n :as i18n]

View File

@ -1,15 +1,18 @@
(ns status-im.ui.screens.offline-messaging-settings.db (ns status-im.ui.screens.offline-messaging-settings.db
(:require-macros [status-im.utils.db :refer [allowed-keys]]) (:require-macros [status-im.utils.db :refer [allowed-keys]])
(:require [cljs.spec.alpha :as spec])) (:require
[cljs.spec.alpha :as spec]
(def enode-address-regex #"enode://[a-zA-Z0-9]+\@\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b:(\d{1,5})") [status-im.utils.inbox :as utils.inbox]))
(spec/def ::not-blank-string (spec/and string? seq)) (spec/def ::not-blank-string (spec/and string? seq))
(spec/def :wnode/address (spec/and string? #(re-matches enode-address-regex %))) (spec/def :wnode/address (spec/and string? utils.inbox/valid-enode-address?))
(spec/def :wnode/name ::not-blank-string) (spec/def :wnode/name ::not-blank-string)
(spec/def :wnode/id ::not-blank-string) (spec/def :wnode/id ::not-blank-string)
(spec/def :wnode/wnode (allowed-keys :req-un [:wnode/address :wnode/name :wnode/id])) (spec/def :wnode/user-defined boolean?)
(spec/def :wnode/password (spec/nilable string?))
(spec/def :wnode/wnode (allowed-keys :req-un [:wnode/address :wnode/name :wnode/id]
:opt-un [:wnode/user-defined :wnode/password]))
(spec/def :inbox/password ::not-blank-string) (spec/def :inbox/password ::not-blank-string)
(spec/def :inbox/wnodes (spec/nilable (spec/map-of keyword? (spec/map-of :wnode/id :wnode/wnode)))) (spec/def :inbox/wnodes (spec/nilable (spec/map-of keyword? (spec/map-of :wnode/id :wnode/wnode))))

View File

@ -0,0 +1,53 @@
(ns status-im.ui.screens.offline-messaging-settings.edit-mailserver.events
(:require [clojure.string :as string]
[re-frame.core :as re-frame]
[status-im.utils.handlers :refer [register-handler] :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.ui.screens.accounts.utils :as accounts.utils]
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.types :as types]
[status-im.utils.inbox :as utils.inbox]
[status-im.data-store.mailservers :as data-store.mailservers]))
(defn- new-mailserver [id mailserver-name address]
(assoc (utils.inbox/address->mailserver address)
:id (string/replace id "-" "")
:name mailserver-name))
(defn save-new-mailserver [{{:mailservers/keys [manage] :account/keys [account] :as db} :db :as cofx} _]
(let [{:keys [name url]} manage
network (get (:networks (:account/account db)) (:network db))
chain (ethereum/network->chain-keyword network)
mailserver (new-mailserver
(string/replace (:random-id cofx) "-" "")
(:value name)
(:value url))]
{:db (-> db
(dissoc :mailservers/manage)
(assoc-in [:inbox/wnodes chain (:id mailserver)] mailserver))
:data-store/tx [(data-store.mailservers/save-mailserver-tx (assoc
mailserver
:chain
chain))]
:dispatch [:navigate-back]}))
(handlers/register-handler-fx
:save-new-mailserver
[(re-frame/inject-cofx :random-id)]
save-new-mailserver)
(handlers/register-handler-fx
:mailserver-set-input
(fn [{db :db} [_ input-key value]]
{:db (update db :mailservers/manage assoc input-key {:value value
:error (if (= input-key :name)
(string/blank? value)
(not (utils.inbox/valid-enode-address? value)))})}))
(handlers/register-handler-fx
:edit-mailserver
(fn [{db :db} _]
{:db (update-in db [:mailservers/manage] assoc
:name {:error true}
:url {:error true})
:dispatch [:navigate-to :edit-mailserver]}))

View File

@ -0,0 +1,15 @@
(ns status-im.ui.screens.offline-messaging-settings.edit-mailserver.styles
(:require-macros [status-im.utils.styles :refer [defstyle]]))
(def edit-mailserver-view
{:flex 1
:margin-horizontal 16
:margin-vertical 15})
(def input-container
{:margin-bottom 15})
(def bottom-container
{:flex-direction :row
:margin-horizontal 12
:margin-vertical 15})

View File

@ -0,0 +1,14 @@
(ns status-im.ui.screens.offline-messaging-settings.edit-mailserver.subs
(:require [re-frame.core :refer [reg-sub]]))
(reg-sub
:get-manage-mailserver
:<- [:get :mailservers/manage]
(fn [manage]
manage))
(reg-sub
:manage-mailserver-valid?
:<- [:get-manage-mailserver]
(fn [manage]
(not-any? :error (vals manage))))

View File

@ -0,0 +1,43 @@
(ns status-im.ui.screens.offline-messaging-settings.edit-mailserver.views
(:require-macros [status-im.utils.views :as views])
(:require
[re-frame.core :as re-frame]
[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.ui.components.status-bar.view :as status-bar]
[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.ui.screens.offline-messaging-settings.edit-mailserver.styles :as styles]))
(views/defview edit-mailserver []
(views/letsubs [manage-mailserver [:get-manage-mailserver]
is-valid? [:manage-mailserver-valid?]]
[react/view components.styles/flex
[status-bar/status-bar]
[react/keyboard-avoiding-view components.styles/flex
[toolbar/simple-toolbar (i18n/label :t/add-mailserver)]
[react/scroll-view
[react/view styles/edit-mailserver-view
[text-input/text-input-with-label
{:label (i18n/label :t/name)
:placeholder (i18n/label :t/specify-name)
:container styles/input-container
:default-value (get-in manage-mailserver [:name :value])
:on-change-text #(re-frame/dispatch [:mailserver-set-input :name %])
:auto-focus true}]
[text-input/text-input-with-label
{:label (i18n/label :t/mailserver-address)
:placeholder (i18n/label :t/specify-mailserver-address)
:container styles/input-container
:default-value (get-in manage-mailserver [:url :value])
:on-change-text #(re-frame/dispatch [:mailserver-set-input :url %])}]]]
[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 [:save-new-mailserver])}]]]]))

View File

@ -1,5 +1,5 @@
(ns status-im.ui.screens.offline-messaging-settings.events (ns status-im.ui.screens.offline-messaging-settings.events
(:require [re-frame.core :refer [dispatch]] (:require [re-frame.core :as re-frame]
[status-im.utils.handlers :as handlers] [status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro] [status-im.utils.handlers-macro :as handlers-macro]
[status-im.ui.screens.accounts.events :as accounts-events] [status-im.ui.screens.accounts.events :as accounts-events]
@ -12,8 +12,9 @@
(fn [{:keys [db now] :as cofx} [_ chain wnode]] (fn [{:keys [db now] :as cofx} [_ chain wnode]]
(let [settings (get-in db [:account/account :settings])] (let [settings (get-in db [:account/account :settings])]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:dispatch [:logout]} (accounts-events/update-settings
(accounts-events/update-settings (assoc-in settings [:wnode chain] wnode)))))) (assoc-in settings [:wnode chain] wnode)
[:logout])))))
(handlers/register-handler-fx (handlers/register-handler-fx
:connect-wnode :connect-wnode
@ -24,5 +25,6 @@
:content (i18n/label :t/connect-wnode-content :content (i18n/label :t/connect-wnode-content
{:name (get-in db [:inbox/wnodes chain wnode :name])}) {:name (get-in db [:inbox/wnodes chain wnode :name])})
:confirm-button-text (i18n/label :t/close-app-button) :confirm-button-text (i18n/label :t/close-app-button)
:on-accept #(dispatch [::save-wnode chain wnode]) :on-accept #(re-frame/dispatch [::save-wnode chain wnode])
:on-cancel nil}}))) :on-cancel nil}})))

View File

@ -1,5 +1,6 @@
(ns status-im.ui.screens.offline-messaging-settings.subs (ns status-im.ui.screens.offline-messaging-settings.subs
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
status-im.ui.screens.offline-messaging-settings.edit-mailserver.subs
[status-im.utils.ethereum.core :as ethereum])) [status-im.utils.ethereum.core :as ethereum]))
(re-frame/reg-sub :settings/current-wnode (re-frame/reg-sub :settings/current-wnode

View File

@ -2,17 +2,22 @@
(:require-macros [status-im.utils.views :as views]) (:require-macros [status-im.utils.views :as views])
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.i18n :as i18n] [status-im.i18n :as i18n]
[status-im.utils.config :as config]
[status-im.ui.components.icons.vector-icons :as vector-icons] [status-im.ui.components.icons.vector-icons :as vector-icons]
[status-im.ui.components.list.views :as list] [status-im.ui.components.list.views :as list]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im.ui.components.status-bar.view :as status-bar] [status-im.ui.components.status-bar.view :as status-bar]
[status-im.ui.components.toolbar.view :as toolbar] [status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.components.toolbar.actions :as toolbar.actions]
[status-im.ui.screens.offline-messaging-settings.styles :as styles])) [status-im.ui.screens.offline-messaging-settings.styles :as styles]))
(defn- wnode-icon [connected?] (defn- wnode-icon [connected?]
[react/view (styles/wnode-icon connected?) [react/view (styles/wnode-icon connected?)
[vector-icons/icon :icons/wnode {:color (if connected? :white :gray)}]]) [vector-icons/icon :icons/wnode {:color (if connected? :white :gray)}]])
(defn navigate-to-add-mailserver []
(re-frame/dispatch [:edit-mailserver]))
(defn- render-row [current-wnode] (defn- render-row [current-wnode]
(fn [{:keys [name id]}] (fn [{:keys [name id]}]
(let [connected? (= id current-wnode)] (let [connected? (= id current-wnode)]
@ -30,7 +35,12 @@
wnodes [:settings/network-wnodes]] wnodes [:settings/network-wnodes]]
[react/view {:flex 1} [react/view {:flex 1}
[status-bar/status-bar] [status-bar/status-bar]
[toolbar/simple-toolbar (i18n/label :t/offline-messaging-settings)] [toolbar/toolbar {}
toolbar/default-nav-back
[toolbar/content-title (i18n/label :t/offline-messaging-settings)]
(when config/add-custom-mailservers-enabled?
[toolbar/actions
[(toolbar.actions/add false navigate-to-add-mailserver)]])]
[react/view styles/wrapper [react/view styles/wrapper
[list/flat-list {:data (vals wnodes) [list/flat-list {:data (vals wnodes)
:default-separator? false :default-separator? false

View File

@ -38,6 +38,7 @@
[status-im.ui.screens.network-settings.network-details.views :refer [network-details]] [status-im.ui.screens.network-settings.network-details.views :refer [network-details]]
[status-im.ui.screens.network-settings.edit-network.views :refer [edit-network]] [status-im.ui.screens.network-settings.edit-network.views :refer [edit-network]]
[status-im.ui.screens.offline-messaging-settings.views :refer [offline-messaging-settings]] [status-im.ui.screens.offline-messaging-settings.views :refer [offline-messaging-settings]]
[status-im.ui.screens.offline-messaging-settings.edit-mailserver.views :refer [edit-mailserver]]
[status-im.ui.screens.currency-settings.views :refer [currency-settings]] [status-im.ui.screens.currency-settings.views :refer [currency-settings]]
[status-im.ui.screens.browser.views :refer [browser]] [status-im.ui.screens.browser.views :refer [browser]]
[status-im.ui.screens.add-new.open-dapp.views :refer [open-dapp dapp-description]] [status-im.ui.screens.add-new.open-dapp.views :refer [open-dapp dapp-description]]
@ -148,6 +149,7 @@
:network-details network-details :network-details network-details
:edit-network edit-network :edit-network edit-network
:offline-messaging-settings offline-messaging-settings :offline-messaging-settings offline-messaging-settings
:edit-mailserver edit-mailserver
:currency-settings currency-settings :currency-settings currency-settings
:recent-recipients recent-recipients :recent-recipients recent-recipients
:recipient-qr-code recipient-qr-code :recipient-qr-code recipient-qr-code

View File

@ -27,7 +27,7 @@
string/lower-case string/lower-case
keyword)) keyword))
(def queue-message-enabled? (enabled? (get-config :QUEUE_MESSAGE_ENABLED 0))) (def add-custom-mailservers-enabled? (enabled? (get-config :ADD_CUSTOM_MAILSERVERS_ENABLED "1")))
(def rn-bridge-threshold-warnings-enabled? (enabled? (get-config :RN_BRIDGE_THRESHOLD_WARNINGS 0))) (def rn-bridge-threshold-warnings-enabled? (enabled? (get-config :RN_BRIDGE_THRESHOLD_WARNINGS 0)))
(def compile-views-enabled? (enabled? (get-config :COMPILE_VIEWS_ENABLED 0))) (def compile-views-enabled? (enabled? (get-config :COMPILE_VIEWS_ENABLED 0)))
(def mixpanel-token (get-config :MIXPANEL_TOKEN)) (def mixpanel-token (get-config :MIXPANEL_TOKEN))

View File

@ -0,0 +1,17 @@
(ns status-im.utils.inbox)
(def enode-address-regex #"enode://[a-zA-Z0-9]+:?(.*)\@\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b:(\d{1,5})")
(defn- extract-url-components [address]
(rest (re-matches #"enode://(.*?):(.*)@(.*)" address)))
(defn address->mailserver [address]
(let [[enode password url :as response] (extract-url-components address)]
(cond-> {:address (if (seq response)
(str "enode://" enode "@" url)
address)
:user-defined true}
password (assoc :password password))))
(defn valid-enode-address? [address]
(re-matches enode-address-regex address))

View File

@ -0,0 +1,24 @@
(ns status-im.test.offline-messaging-settings.events
(:require [cljs.test :refer-macros [deftest is testing]]
[status-im.ui.screens.offline-messaging-settings.edit-mailserver.events :as events]))
(deftest save-new-mailserver
(testing "save a new mailserver"
(let [cofx {:random-id "random-id"
:db {:network "mainnet_rpc"
:account/account {:networks {"mainnet_rpc"
{:config {:NetworkId 1}}}}
:mailservers/manage {:name {:value "test-name"}
:url {:value "enode://test-id:test-password@url:port"}}
:inbox/wnodes {}}}
actual (events/save-new-mailserver cofx nil)]
(testing "it adds the enode to inbox/wnodes"
(is (= {:mainnet {"randomid" {:password "test-password"
:address "enode://test-id@url:port"
:name "test-name"
:id "randomid"
:user-defined true}}}
(get-in actual [:db :inbox/wnodes]))))
(testing "it stores it in the db"
(is (= 1 (count (:data-store/tx actual))))))))

View File

@ -10,6 +10,8 @@
[status-im.test.wallet.transactions.views] [status-im.test.wallet.transactions.views]
[status-im.test.profile.events] [status-im.test.profile.events]
[status-im.test.bots.events] [status-im.test.bots.events]
[status-im.test.offline-messaging-settings.events]
[status-im.test.transport.core]
[status-im.test.chat.models] [status-im.test.chat.models]
[status-im.test.chat.models.input] [status-im.test.chat.models.input]
[status-im.test.chat.models.message] [status-im.test.chat.models.message]
@ -20,6 +22,7 @@
[status-im.test.utils.utils] [status-im.test.utils.utils]
[status-im.test.utils.money] [status-im.test.utils.money]
[status-im.test.utils.clocks] [status-im.test.utils.clocks]
[status-im.test.utils.inbox]
[status-im.test.utils.ethereum.eip681] [status-im.test.utils.ethereum.eip681]
[status-im.test.utils.ethereum.core] [status-im.test.utils.ethereum.core]
[status-im.test.utils.random] [status-im.test.utils.random]
@ -49,7 +52,9 @@
'status-im.test.contacts.subs 'status-im.test.contacts.subs
'status-im.test.profile.events 'status-im.test.profile.events
'status-im.test.data-store.realm.core 'status-im.test.data-store.realm.core
'status-im.test.offline-messaging-settings.events
'status-im.test.bots.events 'status-im.test.bots.events
'status-im.test.transport.core
'status-im.test.wallet.subs 'status-im.test.wallet.subs
'status-im.test.wallet.transactions.subs 'status-im.test.wallet.transactions.subs
'status-im.test.wallet.transactions.views 'status-im.test.wallet.transactions.views
@ -61,6 +66,7 @@
'status-im.test.utils.utils 'status-im.test.utils.utils
'status-im.test.utils.money 'status-im.test.utils.money
'status-im.test.utils.clocks 'status-im.test.utils.clocks
'status-im.test.utils.inbox
'status-im.test.utils.ethereum.eip681 'status-im.test.utils.ethereum.eip681
'status-im.test.utils.ethereum.core 'status-im.test.utils.ethereum.core
'status-im.test.utils.random 'status-im.test.utils.random

View File

@ -0,0 +1,43 @@
(ns status-im.test.transport.core
(:require [cljs.test :refer-macros [deftest is testing]]
[status-im.protocol.handlers :as protocol.handlers]
[status-im.transport.core :as transport]))
(deftest init-whisper
(let [cofx {:db {:account/account {:public-key "1"}}}]
(testing "it adds the discover filter"
(is (= (:shh/add-discovery-filter (protocol.handlers/initialize-protocol cofx [])))))
(testing "it restores the sym-keys"
(is (= (:shh/restore-sym-keys (protocol.handlers/initialize-protocol cofx [])))))
(testing "custom mailservers"
(let [ms-1 {:id "1"
:chain "mainnet"
:name "name-1"
:address "address-1"
:password "password-1"}
ms-2 {:id "2"
:chain "mainnet"
:name "name-2"
:address "address-2"
:password "password-2"}
ms-3 {:id "3"
:chain "rinkeby"
:name "name-3"
:address "address-3"
:password "password-3"}
expected-wnodes {:mainnet {"1" (-> ms-1
(dissoc :chain)
(assoc :user-defined true))
"2" (-> ms-2
(dissoc ms-2 :chain)
(assoc :user-defined true))}
:rinkeby {"3" (-> ms-3
(dissoc :chain)
(assoc :user-defined true))}}
cofx-with-ms (assoc cofx
:data-store/mailservers
[ms-1
ms-2
ms-3])]
(is (= expected-wnodes
(get-in (protocol.handlers/initialize-protocol cofx-with-ms []) [:db :inbox/wnodes])))))))

View File

@ -0,0 +1,26 @@
(ns status-im.test.utils.inbox
(:require [cljs.test :refer-macros [deftest is testing]]
[status-im.utils.inbox :as inbox]))
(deftest address->mailserver
(testing "with password"
(let [address "enode://some-id:the-password@206.189.56.154:30504"]
(is (= {:address "enode://some-id@206.189.56.154:30504"
:password "the-password"
:user-defined true}
(inbox/address->mailserver address)))))
(testing "without password"
(let [address "enode://some-id@206.189.56.154:30504"]
(is (= {:address "enode://some-id@206.189.56.154:30504"
:user-defined true}
(inbox/address->mailserver address))))))
(deftest valid-enode-address
(testing "a valid url without password"
(let [address "enode://1da276e34126e93babf24ec88aac1a7602b4cbb2e11b0961d0ab5e989ca9c261aa7f7c1c85f15550a5f1e5a5ca2305b53b9280cf5894d5ecf7d257b173136d40@167.99.209.61:30504"]
(is (inbox/valid-enode-address? address))))
(testing "a valid url with password"
(let [address "enode://1da276e34126e93babf24ec88aac1a7602b4cbb2e11b0961d0ab5e989ca9c261aa7f7c1c85f15550a5f1e5a5ca2305b53b9280cf5894d5ecf7d257b173136d40:somepasswordwith@and:@@167.99.209.61:30504"]
(is (inbox/valid-enode-address? address)))
(testing "invalid url"
(is (not (inbox/valid-enode-address? "something not valid"))))))