Skip to content

Commit

Permalink
fix(add-contact): support profile ulink with encoded data
Browse files Browse the repository at this point in the history
  • Loading branch information
yqrashawn committed Nov 2, 2023
1 parent 25a2320 commit afe206d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/status_im2/contexts/add_new_contact/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
106 changes: 56 additions & 50 deletions src/status_im2/contexts/add_new_contact/events_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit afe206d

Please sign in to comment.