mirror of
https://github.com/status-im/status-react.git
synced 2025-01-12 20:14:40 +00:00
fix #649
This commit is contained in:
parent
5af0905f2f
commit
0d9f35190f
@ -1,5 +1,6 @@
|
|||||||
(ns status-im.contacts.validations
|
(ns status-im.contacts.validations
|
||||||
(:require [cljs.spec :as s]
|
(:require [cljs.spec :as s]
|
||||||
|
[clojure.string :as str]
|
||||||
[status-im.data-store.contacts :as contacts]))
|
[status-im.data-store.contacts :as contacts]))
|
||||||
|
|
||||||
(def web3 (js/require "web3"))
|
(def web3 (js/require "web3"))
|
||||||
@ -12,19 +13,27 @@
|
|||||||
(:pending? (contacts/get-by-id identity))
|
(:pending? (contacts/get-by-id identity))
|
||||||
true))
|
true))
|
||||||
|
|
||||||
|
(defn hex-string? [s]
|
||||||
|
(let [s' (if (str/starts-with? s "0x")
|
||||||
|
(subs s 2)
|
||||||
|
s)]
|
||||||
|
(boolean (re-matches #"(?i)[0-9a-f]+" s'))))
|
||||||
|
|
||||||
(defn valid-length? [identity]
|
(defn valid-length? [identity]
|
||||||
(let [length (count identity)]
|
(let [length (count identity)]
|
||||||
(or
|
(and
|
||||||
(= 130 length)
|
(hex-string? identity)
|
||||||
(= 132 length)
|
(or
|
||||||
(is-address? identity))))
|
(and (= 128 length) (not (str/includes? identity "0x")))
|
||||||
|
(and (= 130 length) (str/starts-with? identity "0x"))
|
||||||
|
(and (= 132 length) (str/starts-with? identity "0x04"))
|
||||||
|
(is-address? identity)))))
|
||||||
|
|
||||||
(s/def ::identity-length valid-length?)
|
(s/def ::identity-length valid-length?)
|
||||||
(s/def ::contact-can-be-added contact-can-be-added?)
|
(s/def ::contact-can-be-added contact-can-be-added?)
|
||||||
(s/def ::not-empty-string (s/and string? not-empty))
|
(s/def ::not-empty-string (s/and string? not-empty))
|
||||||
(s/def ::name ::not-empty-string)
|
(s/def ::name ::not-empty-string)
|
||||||
(s/def ::whisper-identity (s/and ::not-empty-string
|
(s/def ::whisper-identity (s/and ::not-empty-string
|
||||||
::contact-can-be-added
|
|
||||||
::identity-length))
|
::identity-length))
|
||||||
|
|
||||||
(s/def ::contact (s/keys :req-un [::name ::whisper-identity]
|
(s/def ::contact (s/keys :req-un [::name ::whisper-identity]
|
||||||
|
@ -63,12 +63,12 @@
|
|||||||
(normalize-hex whisper-identity))
|
(normalize-hex whisper-identity))
|
||||||
(label :t/can-not-add-yourself)
|
(label :t/can-not-add-yourself)
|
||||||
|
|
||||||
(not (s/valid? ::v/contact-can-be-added whisper-identity))
|
|
||||||
(label :t/contact-already-added)
|
|
||||||
|
|
||||||
(not (s/valid? ::v/whisper-identity whisper-identity))
|
(not (s/valid? ::v/whisper-identity whisper-identity))
|
||||||
(label :t/enter-valid-public-key)
|
(label :t/enter-valid-public-key)
|
||||||
|
|
||||||
|
(not (s/valid? ::v/contact-can-be-added whisper-identity))
|
||||||
|
(label :t/contact-already-added)
|
||||||
|
|
||||||
:else error))
|
:else error))
|
||||||
|
|
||||||
(defn toolbar-actions [new-contact-identity account error]
|
(defn toolbar-actions [new-contact-identity account error]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user