|
59 | 59 | ["wallet/" :account] :wallet-account
|
60 | 60 | [user-with-data-path :user-data] :user
|
61 | 61 | "c" :community
|
62 |
| - "u" :user} |
| 62 | + "u" :user |
| 63 | + #"wc:([^\?]+)" :wallet-connect |
| 64 | + "wc" :wallet-connect} |
63 | 65 | ethereum-scheme eip-extractor}])
|
64 | 66 |
|
65 | 67 | (defn parse-query-params
|
|
74 | 76 | (when-not (string/blank? fragment)
|
75 | 77 | fragment)))
|
76 | 78 |
|
| 79 | +(defn remove-scheme |
| 80 | + [uri] |
| 81 | + (let [[_ url] (string/split uri #"://")] |
| 82 | + url)) |
| 83 | + |
77 | 84 | (defn match-uri
|
78 | 85 | [uri]
|
79 | 86 | (let [;; bidi has trouble parse path with `=` in it extract `=` here and add back to parsed
|
|
87 | 94 | uri-without-equal-in-path
|
88 | 95 | (if equal-end-of-base64url (string/replace-first uri equal-end-of-base64url "") uri)
|
89 | 96 |
|
| 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 | + |
90 | 101 | ;; fragment is the one after `#`, usually user-id, ens-name, community-id
|
91 | 102 | fragment (parse-fragment uri)
|
92 | 103 | ens? (utils.ens/is-valid-eth-name? fragment)
|
93 | 104 | compressed-key? (validators/valid-compressed-key? fragment)
|
94 | 105 |
|
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) |
97 | 108 | :uri uri
|
98 | 109 | :query-params (parse-query-params uri))]
|
99 | 110 | (cond-> parsed
|
|
130 | 141 | (update-in [:route-params :user-data] #(str % equal-end-of-base64url))
|
131 | 142 |
|
132 | 143 | (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)))))) |
134 | 151 |
|
135 | 152 | (defn match-contact-async
|
136 | 153 | [chain {:keys [user-id ens-name]} callback]
|
|
327 | 344 | (= handler :wallet-account)
|
328 | 345 | (cb (match-wallet-account route-params))
|
329 | 346 |
|
| 347 | + (= handler :wallet-connect) |
| 348 | + (cb {:type :wallet-connect |
| 349 | + :uri (:uri route-params)}) |
| 350 | + |
330 | 351 | (address/address? uri)
|
331 | 352 | (cb (address->eip681 uri))
|
332 | 353 |
|
|
0 commit comments