This commit is contained in:
Roman Volosovskyi 2016-10-04 11:28:56 +03:00
parent 4303570ebc
commit 00664f8975
3 changed files with 30 additions and 17 deletions

View File

@ -28,7 +28,8 @@
[status-im.i18n :refer [label]]
[cljs.spec :as s]
[status-im.contacts.validations :as v]
[status-im.contacts.styles :as st]))
[status-im.contacts.styles :as st]
[status-im.utils.hex :refer [normalize-hex]]))
(def toolbar-title
@ -52,14 +53,23 @@
:photo-path (identicon id)
:whisper-identity id}])))
(defn- validation-error-message [whisper-identity error]
(defn- validation-error-message
[whisper-identity {:keys [address public-key]} error]
(cond
(not (s/valid? ::v/unique-identity whisper-identity)) (label :t/contact-already-added)
(not (s/valid? ::v/whisper-identity whisper-identity)) (label :t/enter-valid-address)
(#{(normalize-hex address) (normalize-hex public-key)}
(normalize-hex whisper-identity))
(label :t/can-not-add-yourself)
(not (s/valid? ::v/unique-identity whisper-identity))
(label :t/contact-already-added)
(not (s/valid? ::v/whisper-identity whisper-identity))
(label :t/enter-valid-address)
:else error))
(defn toolbar-action [new-contact-identity error]
(let [error-message (validation-error-message new-contact-identity error)]
(defn toolbar-action [new-contact-identity account error]
(let [error-message (validation-error-message new-contact-identity account error)]
{:image {:source {:uri (if (str/blank? error-message)
:icon_ok_blue
:icon_ok_disabled)}
@ -68,9 +78,9 @@
(on-add-contact new-contact-identity))}))
(defview contact-whisper-id-input [whisper-identity error]
[]
[current-account [:get-current-account]]
(let [error (when-not (str/blank? whisper-identity)
(validation-error-message whisper-identity error))]
(validation-error-message whisper-identity current-account error))]
[view button-input-container
[text-field
{:error error
@ -88,7 +98,8 @@
(defview new-contact []
[new-contact-identity [:get :new-contact-identity]
error [:get :new-contact-address-error]]
error [:get :new-contact-address-error]
account [:get-current-account]]
[view st/contact-form-container
[view
[status-bar]
@ -97,7 +108,7 @@
:style icon-back}
:handler #(dispatch [:navigate-back])}
:custom-content toolbar-title
:action (toolbar-action new-contact-identity error)}]]
:action (toolbar-action new-contact-identity account error)}]]
[view st/form-container
[contact-whisper-id-input new-contact-identity error]]
[view st/address-explication-container

View File

@ -156,12 +156,13 @@
(defmulti to-query (fn [realm schema-name operator field value]
operator))
(defmethod to-query :eq [realm schema-name operator field value]
(let [value (to-string value)
field-type (field-type realm schema-name field)
query (str (name field) "=" (if (= "string" (name field-type))
(str "\"" value "\"")
value))]
(defmethod to-query :eq [schema schema-name operator field value]
(let [value (to-string value)
field-type (field-type schema schema-name field)
escaped-value (when value (str/replace (str value) #"\"" "\\\""))
query (str (name field) "=" (if (= "string" (name field-type))
(str "\"" escaped-value "\"")
value))]
query))
(defn get-by-field [realm schema-name field value]
@ -184,4 +185,4 @@
:or (or-query queries)))))
(defn exists? [realm schema-name fields]
(pos? (.-length (get-by-fields realm schema-name :and fields))))
(pos? (.-length (get-by-fields realm schema-name :and fields))))

View File

@ -157,6 +157,7 @@
:address-explication "Maybe here should be some text explaining what an address is and where to look for it"
:enter-valid-address "Please enter a valid address or scan a QR code"
:contact-already-added "The contact has already been added"
:can-not-add-yourself "You can't add yourself"
:unknown-address "Unknown address"