mirror of
https://github.com/status-im/status-mobile.git
synced 2025-01-14 10:46:21 +00:00
Allow scanning qr codes for custom mailservers
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
e2cc3123b2
commit
446ae1b30d
@ -4,7 +4,7 @@
|
|||||||
[status-im.ui.components.colors :as colors]
|
[status-im.ui.components.colors :as colors]
|
||||||
[status-im.ui.components.tooltip.views :as tooltip]))
|
[status-im.ui.components.tooltip.views :as tooltip]))
|
||||||
|
|
||||||
(defn text-input-with-label [{:keys [label error style height container] :as props}]
|
(defn text-input-with-label [{:keys [label content error style height container] :as props}]
|
||||||
[react/view
|
[react/view
|
||||||
(when label
|
(when label
|
||||||
[react/text {:style styles/label}
|
[react/text {:style styles/label}
|
||||||
@ -16,6 +16,7 @@
|
|||||||
:placeholder-text-color colors/gray
|
:placeholder-text-color colors/gray
|
||||||
:auto-focus true
|
:auto-focus true
|
||||||
:auto-capitalize :none}
|
:auto-capitalize :none}
|
||||||
(dissoc props :style :height))]]
|
(dissoc props :style :height))]
|
||||||
|
(when content content)]
|
||||||
(when error
|
(when error
|
||||||
[tooltip/tooltip error (styles/error label)])])
|
[tooltip/tooltip error (styles/error label)])])
|
||||||
|
@ -31,6 +31,12 @@
|
|||||||
chain))]
|
chain))]
|
||||||
:dispatch [:navigate-back]}))
|
:dispatch [:navigate-back]}))
|
||||||
|
|
||||||
|
(defn set-input [input-key value {:keys [db]}]
|
||||||
|
{: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
|
(handlers/register-handler-fx
|
||||||
:save-new-mailserver
|
:save-new-mailserver
|
||||||
[(re-frame/inject-cofx :random-id)]
|
[(re-frame/inject-cofx :random-id)]
|
||||||
@ -38,11 +44,8 @@
|
|||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:mailserver-set-input
|
:mailserver-set-input
|
||||||
(fn [{db :db} [_ input-key value]]
|
(fn [cofx [_ input-key value]]
|
||||||
{:db (update db :mailservers/manage assoc input-key {:value value
|
(set-input input-key value cofx)))
|
||||||
:error (if (= input-key :name)
|
|
||||||
(string/blank? value)
|
|
||||||
(not (utils.inbox/valid-enode-address? value)))})}))
|
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:edit-mailserver
|
:edit-mailserver
|
||||||
@ -51,3 +54,9 @@
|
|||||||
:name {:error true}
|
:name {:error true}
|
||||||
:url {:error true})
|
:url {:error true})
|
||||||
:dispatch [:navigate-to :edit-mailserver]}))
|
:dispatch [:navigate-to :edit-mailserver]}))
|
||||||
|
|
||||||
|
(handlers/register-handler-fx
|
||||||
|
:set-mailserver-from-qr
|
||||||
|
(fn [cofx [_ _ contact-identity]]
|
||||||
|
(assoc (set-input :url contact-identity cofx)
|
||||||
|
:dispatch [:navigate-back])))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
(ns status-im.ui.screens.offline-messaging-settings.edit-mailserver.styles
|
(ns status-im.ui.screens.offline-messaging-settings.edit-mailserver.styles
|
||||||
(:require-macros [status-im.utils.styles :refer [defstyle]]))
|
(:require-macros [status-im.utils.styles :refer [defstyle]])
|
||||||
|
(:require [status-im.ui.components.styles :as styles]))
|
||||||
|
|
||||||
(def edit-mailserver-view
|
(def edit-mailserver-view
|
||||||
{:flex 1
|
{:flex 1
|
||||||
@ -7,7 +8,21 @@
|
|||||||
:margin-vertical 15})
|
:margin-vertical 15})
|
||||||
|
|
||||||
(def input-container
|
(def input-container
|
||||||
{:margin-bottom 15})
|
{:flex-direction :row
|
||||||
|
:align-items :center
|
||||||
|
:justify-content :space-between
|
||||||
|
:border-radius styles/border-radius
|
||||||
|
:height 52
|
||||||
|
:margin-top 15})
|
||||||
|
|
||||||
|
(defstyle input
|
||||||
|
{:flex 1
|
||||||
|
:font-size 15
|
||||||
|
:letter-spacing -0.2
|
||||||
|
:android {:padding 0}})
|
||||||
|
|
||||||
|
(def qr-code
|
||||||
|
{:margin-right 14})
|
||||||
|
|
||||||
(def bottom-container
|
(def bottom-container
|
||||||
{:flex-direction :row
|
{:flex-direction :row
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.ui.components.react :as react]
|
[status-im.ui.components.react :as react]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
|
[status-im.ui.components.colors :as colors]
|
||||||
|
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
||||||
[status-im.ui.components.styles :as components.styles]
|
[status-im.ui.components.styles :as components.styles]
|
||||||
[status-im.ui.components.common.common :as components.common]
|
[status-im.ui.components.common.common :as components.common]
|
||||||
[status-im.ui.components.status-bar.view :as status-bar]
|
[status-im.ui.components.status-bar.view :as status-bar]
|
||||||
@ -12,6 +14,14 @@
|
|||||||
[status-im.ui.components.text-input.view :as text-input]
|
[status-im.ui.components.text-input.view :as text-input]
|
||||||
[status-im.ui.screens.offline-messaging-settings.edit-mailserver.styles :as styles]))
|
[status-im.ui.screens.offline-messaging-settings.edit-mailserver.styles :as styles]))
|
||||||
|
|
||||||
|
(def qr-code
|
||||||
|
[react/touchable-highlight {:on-press #(re-frame/dispatch [:scan-qr-code
|
||||||
|
{:toolbar-title (i18n/label :t/add-mailserver)}
|
||||||
|
:set-mailserver-from-qr])
|
||||||
|
:style styles/qr-code}
|
||||||
|
[react/view
|
||||||
|
[vector-icons/icon :icons/qr {:color colors/blue}]]])
|
||||||
|
|
||||||
(views/defview edit-mailserver []
|
(views/defview edit-mailserver []
|
||||||
(views/letsubs [manage-mailserver [:get-manage-mailserver]
|
(views/letsubs [manage-mailserver [:get-manage-mailserver]
|
||||||
is-valid? [:manage-mailserver-valid?]]
|
is-valid? [:manage-mailserver-valid?]]
|
||||||
@ -24,6 +34,7 @@
|
|||||||
[text-input/text-input-with-label
|
[text-input/text-input-with-label
|
||||||
{:label (i18n/label :t/name)
|
{:label (i18n/label :t/name)
|
||||||
:placeholder (i18n/label :t/specify-name)
|
:placeholder (i18n/label :t/specify-name)
|
||||||
|
:style styles/input
|
||||||
:container styles/input-container
|
:container styles/input-container
|
||||||
:default-value (get-in manage-mailserver [:name :value])
|
:default-value (get-in manage-mailserver [:name :value])
|
||||||
:on-change-text #(re-frame/dispatch [:mailserver-set-input :name %])
|
:on-change-text #(re-frame/dispatch [:mailserver-set-input :name %])
|
||||||
@ -31,6 +42,8 @@
|
|||||||
[text-input/text-input-with-label
|
[text-input/text-input-with-label
|
||||||
{:label (i18n/label :t/mailserver-address)
|
{:label (i18n/label :t/mailserver-address)
|
||||||
:placeholder (i18n/label :t/specify-mailserver-address)
|
:placeholder (i18n/label :t/specify-mailserver-address)
|
||||||
|
:content qr-code
|
||||||
|
:style styles/input
|
||||||
:container styles/input-container
|
:container styles/input-container
|
||||||
:default-value (get-in manage-mailserver [:url :value])
|
:default-value (get-in manage-mailserver [:url :value])
|
||||||
:on-change-text #(re-frame/dispatch [:mailserver-set-input :url %])}]]]
|
:on-change-text #(re-frame/dispatch [:mailserver-set-input :url %])}]]]
|
||||||
|
@ -2,6 +2,28 @@
|
|||||||
(:require [cljs.test :refer-macros [deftest is testing]]
|
(:require [cljs.test :refer-macros [deftest is testing]]
|
||||||
[status-im.ui.screens.offline-messaging-settings.edit-mailserver.events :as events]))
|
[status-im.ui.screens.offline-messaging-settings.edit-mailserver.events :as events]))
|
||||||
|
|
||||||
|
(def valid-enode-url "enode://1da276e34126e93babf24ec88aac1a7602b4cbb2e11b0961d0ab5e989ca9c261aa7f7c1c85f15550a5f1e5a5ca2305b53b9280cf5894d5ecf7d257b173136d40:somepassword@167.99.209.61:30504")
|
||||||
|
|
||||||
|
(deftest set-input
|
||||||
|
(testing "it validates names"
|
||||||
|
(testing "correct name"
|
||||||
|
(is (= {:db {:mailservers/manage {:name {:value "value"
|
||||||
|
:error false}}}}
|
||||||
|
(events/set-input :name "value" {}))))
|
||||||
|
(testing "blank name"
|
||||||
|
(is (= {:db {:mailservers/manage {:name {:value ""
|
||||||
|
:error true}}}}
|
||||||
|
(events/set-input :name "" {})))))
|
||||||
|
(testing "it validates enodes url"
|
||||||
|
(testing "correct url"
|
||||||
|
(is (= {:db {:mailservers/manage {:url {:value valid-enode-url
|
||||||
|
:error false}}}}
|
||||||
|
(events/set-input :url valid-enode-url {}))))
|
||||||
|
(testing "broken url"
|
||||||
|
(is (= {:db {:mailservers/manage {:url {:value "broken"
|
||||||
|
:error true}}}}
|
||||||
|
(events/set-input :url "broken" {}))))))
|
||||||
|
|
||||||
(deftest save-new-mailserver
|
(deftest save-new-mailserver
|
||||||
(testing "save a new mailserver"
|
(testing "save a new mailserver"
|
||||||
(let [cofx {:random-id "random-id"
|
(let [cofx {:random-id "random-id"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user