Merge pull request #319 from status-im/bug/add-new-contact-bugs
Fixes bugs related to "Add new contact" form (#308, #309)
This commit is contained in:
commit
fb1b789eee
|
@ -28,7 +28,8 @@
|
||||||
[status-im.i18n :refer [label]]
|
[status-im.i18n :refer [label]]
|
||||||
[cljs.spec :as s]
|
[cljs.spec :as s]
|
||||||
[status-im.contacts.validations :as v]
|
[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
|
(def toolbar-title
|
||||||
|
@ -52,14 +53,23 @@
|
||||||
:photo-path (identicon id)
|
:photo-path (identicon id)
|
||||||
:whisper-identity id}])))
|
:whisper-identity id}])))
|
||||||
|
|
||||||
(defn- validation-error-message [whisper-identity error]
|
(defn- validation-error-message
|
||||||
|
[whisper-identity {:keys [address public-key]} error]
|
||||||
(cond
|
(cond
|
||||||
(not (s/valid? ::v/unique-identity whisper-identity)) (label :t/contact-already-added)
|
(#{(normalize-hex address) (normalize-hex public-key)}
|
||||||
(not (s/valid? ::v/whisper-identity whisper-identity)) (label :t/enter-valid-address)
|
(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))
|
:else error))
|
||||||
|
|
||||||
(defn toolbar-action [new-contact-identity error]
|
(defn toolbar-action [new-contact-identity account error]
|
||||||
(let [error-message (validation-error-message new-contact-identity error)]
|
(let [error-message (validation-error-message new-contact-identity account error)]
|
||||||
{:image {:source {:uri (if (str/blank? error-message)
|
{:image {:source {:uri (if (str/blank? error-message)
|
||||||
:icon_ok_blue
|
:icon_ok_blue
|
||||||
:icon_ok_disabled)}
|
:icon_ok_disabled)}
|
||||||
|
@ -68,9 +78,9 @@
|
||||||
(on-add-contact new-contact-identity))}))
|
(on-add-contact new-contact-identity))}))
|
||||||
|
|
||||||
(defview contact-whisper-id-input [whisper-identity error]
|
(defview contact-whisper-id-input [whisper-identity error]
|
||||||
[]
|
[current-account [:get-current-account]]
|
||||||
(let [error (when-not (str/blank? whisper-identity)
|
(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
|
[view button-input-container
|
||||||
[text-field
|
[text-field
|
||||||
{:error error
|
{:error error
|
||||||
|
@ -88,7 +98,8 @@
|
||||||
|
|
||||||
(defview new-contact []
|
(defview new-contact []
|
||||||
[new-contact-identity [:get :new-contact-identity]
|
[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 st/contact-form-container
|
||||||
[view
|
[view
|
||||||
[status-bar]
|
[status-bar]
|
||||||
|
@ -97,7 +108,7 @@
|
||||||
:style icon-back}
|
:style icon-back}
|
||||||
:handler #(dispatch [:navigate-back])}
|
:handler #(dispatch [:navigate-back])}
|
||||||
:custom-content toolbar-title
|
:custom-content toolbar-title
|
||||||
:action (toolbar-action new-contact-identity error)}]]
|
:action (toolbar-action new-contact-identity account error)}]]
|
||||||
[view st/form-container
|
[view st/form-container
|
||||||
[contact-whisper-id-input new-contact-identity error]]
|
[contact-whisper-id-input new-contact-identity error]]
|
||||||
[view st/address-explication-container
|
[view st/address-explication-container
|
||||||
|
|
|
@ -156,12 +156,13 @@
|
||||||
(defmulti to-query (fn [realm schema-name operator field value]
|
(defmulti to-query (fn [realm schema-name operator field value]
|
||||||
operator))
|
operator))
|
||||||
|
|
||||||
(defmethod to-query :eq [realm schema-name operator field value]
|
(defmethod to-query :eq [schema schema-name operator field value]
|
||||||
(let [value (to-string value)
|
(let [value (to-string value)
|
||||||
field-type (field-type realm schema-name field)
|
field-type (field-type schema schema-name field)
|
||||||
query (str (name field) "=" (if (= "string" (name field-type))
|
escaped-value (when value (str/replace (str value) #"\"" "\\\""))
|
||||||
(str "\"" value "\"")
|
query (str (name field) "=" (if (= "string" (name field-type))
|
||||||
value))]
|
(str "\"" escaped-value "\"")
|
||||||
|
value))]
|
||||||
query))
|
query))
|
||||||
|
|
||||||
(defn get-by-field [realm schema-name field value]
|
(defn get-by-field [realm schema-name field value]
|
||||||
|
|
|
@ -157,6 +157,7 @@
|
||||||
:address-explication "Maybe here should be some text explaining what an address is and where to look for it"
|
: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"
|
:enter-valid-address "Please enter a valid address or scan a QR code"
|
||||||
:contact-already-added "The contact has already been added"
|
:contact-already-added "The contact has already been added"
|
||||||
|
:can-not-add-yourself "You can't add yourself"
|
||||||
:unknown-address "Unknown address"
|
:unknown-address "Unknown address"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue