diff --git a/src/status_im2/contexts/add_new_contact/events.cljs b/src/status_im2/contexts/add_new_contact/events.cljs index 6bc2b0e7e477..231fd83243ef 100644 --- a/src/status_im2/contexts/add_new_contact/events.cljs +++ b/src/status_im2/contexts/add_new_contact/events.cljs @@ -34,14 +34,14 @@ (zipmap (repeat nil)))) ([kv] (-> (init-contact) (merge kv)))) -(def url-regex #"^https?://status.app/u#(.+)") +(def url-regex #"^https?://status.app/u(/([a-zA-Z0-9_-]+)(={0,2}))?#(.+)") (defn ->id [{:keys [input] :as contact}] (let [trimmed-input (utils.string/safe-trim input)] (->> {:id (if (empty? trimmed-input) nil - (if-some [[_ id] (re-matches url-regex trimmed-input)] + (if-some [id (last (re-matches url-regex trimmed-input))] id trimmed-input))} (merge contact)))) diff --git a/src/status_im2/contexts/add_new_contact/events_test.cljs b/src/status_im2/contexts/add_new_contact/events_test.cljs index 392f2d194695..9130b02687ac 100644 --- a/src/status_im2/contexts/add_new_contact/events_test.cljs +++ b/src/status_im2/contexts/add_new_contact/events_test.cljs @@ -12,6 +12,7 @@ (def ens "esep") (def ens-stateofus-eth (str ens ".stateofus.eth")) (def link-ckey (str "https://status.app/u#" ckey)) +(def link-ckey-with-encoded-data (str "https://status.app/u/CwSACgcKBVBhdmxvAw==#" ckey)) (def link-ens (str "https://status.app/u#" ens)) ;;; unit tests (no app-db involved) @@ -22,56 +23,61 @@ :input i})) (events/init-contact e)) - "" {:user-public-key user-ukey - :input "" - :type :empty - :state :empty} - - " " {:user-public-key user-ukey - :input " " - :type :empty - :state :empty} - - ukey {:user-public-key user-ukey - :input ukey - :id ukey - :type :public-key - :public-key ukey - :state :invalid - :msg :t/not-a-chatkey} - - ens {:user-public-key user-ukey - :input ens - :id ens - :type :ens - :ens ens-stateofus-eth - :state :resolve-ens} - - (str " " ens) {:user-public-key user-ukey - :input (str " " ens) - :id ens - :type :ens - :ens ens-stateofus-eth - :state :resolve-ens} - - ckey {:user-public-key user-ukey - :input ckey - :id ckey - :type :compressed-key - :state :decompress-key} - - link-ckey {:user-public-key user-ukey - :input link-ckey - :id ckey - :type :compressed-key - :state :decompress-key} - - link-ens {:user-public-key user-ukey - :input link-ens - :id ens - :type :ens - :ens ens-stateofus-eth - :state :resolve-ens})) + "" {:user-public-key user-ukey + :input "" + :type :empty + :state :empty} + + " " {:user-public-key user-ukey + :input " " + :type :empty + :state :empty} + + ukey {:user-public-key user-ukey + :input ukey + :id ukey + :type :public-key + :public-key ukey + :state :invalid + :msg :t/not-a-chatkey} + + ens {:user-public-key user-ukey + :input ens + :id ens + :type :ens + :ens ens-stateofus-eth + :state :resolve-ens} + + (str " " ens) {:user-public-key user-ukey + :input (str " " ens) + :id ens + :type :ens + :ens ens-stateofus-eth + :state :resolve-ens} + + ckey {:user-public-key user-ukey + :input ckey + :id ckey + :type :compressed-key + :state :decompress-key} + + link-ckey {:user-public-key user-ukey + :input link-ckey + :id ckey + :type :compressed-key + :state :decompress-key} + link-ckey-with-encoded-data {:user-public-key user-ukey + :input link-ckey-with-encoded-data + :id ckey + :type :compressed-key + :state :decompress-key} + + link-ens {:user-public-key user-ukey + :input link-ens + :id ens + :type :ens + :ens ens-stateofus-eth + :state :resolve-ens})) ;;; event handler tests (no callbacks)