Skip to content

Commit 5dc907b

Browse files
[#20150] feat: wallet connect pairing via deep links
1 parent d4a58ac commit 5dc907b

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/status_im/common/router.cljs

+25-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
["wallet/" :account] :wallet-account
6060
[user-with-data-path :user-data] :user
6161
"c" :community
62-
"u" :user}
62+
"u" :user
63+
#"wc:([^\?]+)" :wallet-connect
64+
"wc" :wallet-connect}
6365
ethereum-scheme eip-extractor}])
6466

6567
(defn parse-query-params
@@ -74,6 +76,11 @@
7476
(when-not (string/blank? fragment)
7577
fragment)))
7678

79+
(defn remove-scheme
80+
[uri]
81+
(let [[_ url] (string/split uri #"://")]
82+
url))
83+
7784
(defn match-uri
7885
[uri]
7986
(let [;; bidi has trouble parse path with `=` in it extract `=` here and add back to parsed
@@ -87,13 +94,17 @@
8794
uri-without-equal-in-path
8895
(if equal-end-of-base64url (string/replace-first uri equal-end-of-base64url "") uri)
8996

97+
;;bidi has issue to detect wc regex with /?, couldn't fine any other workaround
98+
normalize-url
99+
(if (string/includes? uri "//wc:") (string/replace-first uri "/?" "?") uri-without-equal-in-path)
100+
90101
;; fragment is the one after `#`, usually user-id, ens-name, community-id
91102
fragment (parse-fragment uri)
92103
ens? (utils.ens/is-valid-eth-name? fragment)
93104
compressed-key? (validators/valid-compressed-key? fragment)
94105

95-
{:keys [handler route-params] :as parsed}
96-
(assoc (bidi/match-route routes uri-without-equal-in-path)
106+
{:keys [handler route-params query-params] :as parsed}
107+
(assoc (bidi/match-route routes normalize-url)
97108
:uri uri
98109
:query-params (parse-query-params uri))]
99110
(cond-> parsed
@@ -130,7 +141,13 @@
130141
(update-in [:route-params :user-data] #(str % equal-end-of-base64url))
131142

132143
(and (= handler :user) compressed-key?)
133-
(assoc-in [:route-params :user-id] fragment))))
144+
(assoc-in [:route-params :user-id] fragment)
145+
146+
(= handler :wallet-connect)
147+
(assoc-in [:route-params :uri]
148+
(if (get query-params "uri")
149+
(get query-params "uri")
150+
(remove-scheme normalize-url))))))
134151

135152
(defn match-contact-async
136153
[chain {:keys [user-id ens-name]} callback]
@@ -327,6 +344,10 @@
327344
(= handler :wallet-account)
328345
(cb (match-wallet-account route-params))
329346

347+
(= handler :wallet-connect)
348+
(cb {:type :wallet-connect
349+
:uri (:uri route-params)})
350+
330351
(address/address? uri)
331352
(cb (address->eip681 uri))
332353

src/status_im/common/universal_links.cljs

+7-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@
105105
[full-url]
106106
(log/info "universal-links: no handler for " full-url))
107107

108+
(rf/defn handle-wallet-connect
109+
[_ uri]
110+
(log/info "universal-links: handle-wallet-connect" uri)
111+
{:dispatch [:wallet-connect/on-scan-connection uri]})
112+
108113
(defn dispatch-url
109114
"Dispatch url so we can get access to re-frame/db"
110115
[url]
@@ -117,7 +122,7 @@
117122

118123
(rf/defn on-handle
119124
{:events [:universal-links/match-value]}
120-
[cofx url {:keys [type chat-id community-id] :as data}]
125+
[cofx url {:keys [type chat-id community-id uri] :as data}]
121126
(case type
122127
:group-chat (handle-group-chat cofx data)
123128
:private-chat (handle-private-chat cofx data)
@@ -130,6 +135,7 @@
130135
:browser (handle-browse cofx data)
131136
:eip681 (handle-eip681 cofx data)
132137
:wallet-account (handle-wallet-account cofx data)
138+
:wallet-connect (handle-wallet-connect cofx uri)
133139
(handle-not-found url)))
134140

135141
(rf/defn route-url

0 commit comments

Comments
 (0)