Skip to content

Commit 8b6418f

Browse files
committed
fix(add-contact): support profile ulink with encoded data
1 parent fd2210f commit 8b6418f

File tree

2 files changed

+58
-52
lines changed

2 files changed

+58
-52
lines changed

src/status_im2/contexts/add_new_contact/events.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
(zipmap (repeat nil))))
3535
([kv] (-> (init-contact) (merge kv))))
3636

37-
(def url-regex #"^https?://status.app/u#(.+)")
37+
(def url-regex #"^https?://status.app/u(/([a-zA-Z0-9_-]+)(={0,2}))?#(.+)")
3838

3939
(defn ->id
4040
[{:keys [input] :as contact}]
4141
(let [trimmed-input (utils.string/safe-trim input)]
4242
(->> {:id (if (empty? trimmed-input)
4343
nil
44-
(if-some [[_ id] (re-matches url-regex trimmed-input)]
44+
(if-some [id (last (re-matches url-regex trimmed-input))]
4545
id
4646
trimmed-input))}
4747
(merge contact))))

src/status_im2/contexts/add_new_contact/events_test.cljs

+56-50
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
(def ens "esep")
1313
(def ens-stateofus-eth (str ens ".stateofus.eth"))
1414
(def link-ckey (str "https://status.app/u#" ckey))
15+
(def link-ckey-with-encoded-data (str "https://status.app/u/CwSACgcKBVBhdmxvAw==#" ckey))
1516
(def link-ens (str "https://status.app/u#" ens))
1617

1718
;;; unit tests (no app-db involved)
@@ -22,56 +23,61 @@
2223
:input i}))
2324
(events/init-contact e))
2425

25-
"" {:user-public-key user-ukey
26-
:input ""
27-
:type :empty
28-
:state :empty}
29-
30-
" " {:user-public-key user-ukey
31-
:input " "
32-
:type :empty
33-
:state :empty}
34-
35-
ukey {:user-public-key user-ukey
36-
:input ukey
37-
:id ukey
38-
:type :public-key
39-
:public-key ukey
40-
:state :invalid
41-
:msg :t/not-a-chatkey}
42-
43-
ens {:user-public-key user-ukey
44-
:input ens
45-
:id ens
46-
:type :ens
47-
:ens ens-stateofus-eth
48-
:state :resolve-ens}
49-
50-
(str " " ens) {:user-public-key user-ukey
51-
:input (str " " ens)
52-
:id ens
53-
:type :ens
54-
:ens ens-stateofus-eth
55-
:state :resolve-ens}
56-
57-
ckey {:user-public-key user-ukey
58-
:input ckey
59-
:id ckey
60-
:type :compressed-key
61-
:state :decompress-key}
62-
63-
link-ckey {:user-public-key user-ukey
64-
:input link-ckey
65-
:id ckey
66-
:type :compressed-key
67-
:state :decompress-key}
68-
69-
link-ens {:user-public-key user-ukey
70-
:input link-ens
71-
:id ens
72-
:type :ens
73-
:ens ens-stateofus-eth
74-
:state :resolve-ens}))
26+
"" {:user-public-key user-ukey
27+
:input ""
28+
:type :empty
29+
:state :empty}
30+
31+
" " {:user-public-key user-ukey
32+
:input " "
33+
:type :empty
34+
:state :empty}
35+
36+
ukey {:user-public-key user-ukey
37+
:input ukey
38+
:id ukey
39+
:type :public-key
40+
:public-key ukey
41+
:state :invalid
42+
:msg :t/not-a-chatkey}
43+
44+
ens {:user-public-key user-ukey
45+
:input ens
46+
:id ens
47+
:type :ens
48+
:ens ens-stateofus-eth
49+
:state :resolve-ens}
50+
51+
(str " " ens) {:user-public-key user-ukey
52+
:input (str " " ens)
53+
:id ens
54+
:type :ens
55+
:ens ens-stateofus-eth
56+
:state :resolve-ens}
57+
58+
ckey {:user-public-key user-ukey
59+
:input ckey
60+
:id ckey
61+
:type :compressed-key
62+
:state :decompress-key}
63+
64+
link-ckey {:user-public-key user-ukey
65+
:input link-ckey
66+
:id ckey
67+
:type :compressed-key
68+
:state :decompress-key}
69+
link-ckey-with-encoded-data {:user-public-key user-ukey
70+
:input link-ckey-with-encoded-data
71+
:id ckey
72+
:type :compressed-key
73+
:state :decompress-key}
74+
75+
link-ens {:user-public-key user-ukey
76+
:input link-ens
77+
:id ens
78+
:type :ens
79+
:ens ens-stateofus-eth
80+
:state :resolve-ens}))
7581

7682
;;; event handler tests (no callbacks)
7783

0 commit comments

Comments
 (0)