|
38 | 38 | [path]
|
39 | 39 | (map #(str % path) status-web-urls))
|
40 | 40 |
|
41 |
| - |
42 | 41 | (def handled-schemes (set (into uri-schemes status-web-urls)))
|
43 | 42 |
|
| 43 | +(defn wc-normalize-uri |
| 44 | + [uri] |
| 45 | + (if (string/includes? uri "//wc:") (string/replace-first uri "/?" "?") uri)) |
| 46 | + |
44 | 47 | (def group-chat-extractor
|
45 | 48 | {[#"(.*)" :params] {"" :group-chat
|
46 | 49 | "/" :group-chat}})
|
|
60 | 63 | ["wallet/" :account] :wallet-account
|
61 | 64 | [user-with-data-path :user-data] :user
|
62 | 65 | "c" :community
|
63 |
| - "u" :user} |
| 66 | + "u" :user |
| 67 | + #"wc:([^\?]+)" :wallet-connect |
| 68 | + "wc" :wallet-connect} |
64 | 69 | ethereum-scheme eip-extractor}])
|
65 | 70 |
|
66 | 71 | (defn parse-query-params
|
|
75 | 80 | (when-not (string/blank? fragment)
|
76 | 81 | fragment)))
|
77 | 82 |
|
| 83 | +(defn remove-scheme |
| 84 | + [uri] |
| 85 | + (let [[_ url] (string/split uri #"://")] |
| 86 | + url)) |
| 87 | + |
78 | 88 | (defn match-uri
|
79 | 89 | [uri]
|
80 | 90 | (let [;; bidi has trouble parse path with `=` in it extract `=` here and add back to parsed
|
|
88 | 98 | uri-without-equal-in-path
|
89 | 99 | (if equal-end-of-base64url (string/replace-first uri equal-end-of-base64url "") uri)
|
90 | 100 |
|
| 101 | + ;;bidi has issue to detect wc regex with /?, couldn't fine any other workaround |
| 102 | + normalize-uri |
| 103 | + (wc-normalize-uri uri-without-equal-in-path) |
| 104 | + |
91 | 105 | ;; fragment is the one after `#`, usually user-id, ens-name, community-id
|
92 | 106 | fragment (parse-fragment uri)
|
93 | 107 | ens? (utils.ens/is-valid-eth-name? fragment)
|
94 | 108 | compressed-key? (validators/valid-compressed-key? fragment)
|
95 | 109 |
|
96 |
| - {:keys [handler route-params] :as parsed} |
97 |
| - (assoc (bidi/match-route routes uri-without-equal-in-path) |
| 110 | + {:keys [handler route-params query-params] :as parsed} |
| 111 | + (assoc (bidi/match-route routes normalize-uri) |
98 | 112 | :uri uri
|
99 | 113 | :query-params (parse-query-params uri))]
|
100 | 114 | (cond-> parsed
|
|
131 | 145 | (update-in [:route-params :user-data] #(str % equal-end-of-base64url))
|
132 | 146 |
|
133 | 147 | (and (= handler :user) compressed-key?)
|
134 |
| - (assoc-in [:route-params :user-id] fragment)))) |
| 148 | + (assoc-in [:route-params :user-id] fragment) |
| 149 | + |
| 150 | + (= handler :wallet-connect) |
| 151 | + (assoc-in [:route-params :uri] |
| 152 | + (if (get query-params "uri") |
| 153 | + (get query-params "uri") |
| 154 | + (remove-scheme normalize-uri)))))) |
135 | 155 |
|
136 | 156 | (defn match-contact-async
|
137 | 157 | [chain {:keys [user-id ens-name]} callback]
|
|
328 | 348 | (= handler :wallet-account)
|
329 | 349 | (cb (match-wallet-account route-params))
|
330 | 350 |
|
| 351 | + (= handler :wallet-connect) |
| 352 | + (cb {:type :wallet-connect |
| 353 | + :uri (:uri route-params)}) |
| 354 | + |
331 | 355 | (address/address? uri)
|
332 | 356 | (cb (address->eip681 uri))
|
333 | 357 |
|
|
0 commit comments