Skip to content

Commit

Permalink
refactor: remote old uri routes
Browse files Browse the repository at this point in the history
didn't remove the route handler
we might need these in the future

Signed-off-by: yqrashawn <namy.19@gmail.com>
  • Loading branch information
yqrashawn committed Oct 11, 2023
1 parent daf9879 commit 969b763
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 57 deletions.
48 changes: 19 additions & 29 deletions src/status_im/router/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@

(def handled-schemes (set (into uri-schemes web-urls)))

(def browser-extractor
{[#"(.*)" :domain] {"" :browser
"/" :browser}})

(def group-chat-extractor
{[#"(.*)" :params] {"" :group-chat
"/" :group-chat}})

(def eip-extractor
{#{[:prefix "-" :address]
[:address]}
Expand All @@ -46,16 +38,9 @@

(def routes
[""
{handled-schemes {"b/" browser-extractor
"browser/" browser-extractor
["p/" :chat-id] :private-chat
["cr/" :community-id] :community-requests
["c/" :community-data] :community
{handled-schemes {["c/" :community-data] :community
["cc/" :chat-data] :community-chat
"g/" group-chat-extractor
["wallet/" :account] :wallet-account
["u/" :user-data] :user
["user/" :user-id] :user}
["u/" :user-data] :user}
ethereum-scheme eip-extractor}])

(defn parse-query-params
Expand Down Expand Up @@ -252,31 +237,35 @@
:community))

(defn handle-uri
[chain chats uri cb]
(let [{:keys [handler route-params query-params]} (match-uri uri)]
[chain _chats uri cb]
(let [{:keys [handler route-params]} (match-uri uri)]
(log/info "[router] uri " uri " matched " handler " with " route-params)
(cond

(= handler :browser)
(cb (match-browser uri route-params))
;; ;; NOTE: removed in `match-uri`, might need this in the future
;; (= handler :browser)
;; (cb (match-browser uri route-params))

(= handler :ethereum)
(cb (match-eip681 uri))

(and (= handler :user) (:user-id route-params))
(match-contact-async chain route-params cb)

(= handler :private-chat)
(match-private-chat-async chain route-params cb)
;; ;; NOTE: removed in `match-uri`, might need this in the future
;; (= handler :private-chat)
;; (match-private-chat-async chain route-params cb)

(= handler :group-chat)
(cb (match-group-chat chats query-params))
;; ;; NOTE: removed in `match-uri`, might need this in the future
;; (= handler :group-chat)
;; (cb (match-group-chat chats query-params))

(validators/valid-public-key? uri)
(match-contact-async chain {:user-id uri} cb)

(= handler :community-requests)
(cb {:type handler :community-id (:community-id route-params)})
;; ;; NOTE: removed in `match-uri`, might need this in the future
;; (= handler :community-requests)
;; (cb {:type handler :community-id (:community-id route-params)})

(and (= handler :community) (:community-id route-params))
(cb {:type (community-route-type route-params)
Expand All @@ -290,8 +279,9 @@
(cb {:type (community-route-type route-params)
:community-id (:community-id route-params)})

(= handler :wallet-account)
(cb (match-wallet-account route-params))
;; ;; NOTE: removed in `match-uri`, might need this in the future
;; (= handler :wallet-account)
;; (cb (match-wallet-account route-params))

(address/address? uri)
(cb (address->eip681 uri))
Expand Down
28 changes: 0 additions & 28 deletions src/status_im/router/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,6 @@
"iyKACkQKB0Rvb2RsZXMSJ0NvbG9yaW5nIHRoZSB3b3JsZCB3aXRoIGpveSDigKIg4bSXIOKAohiYohsiByMxMzFEMkYqAwEhMwM="
:community-id "zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"}]

"status-app://u/statuse2e"
[:user {:user-data "statuse2e"}]

(str "status-app://user/" public-key)
[:user {:user-id public-key}]

"status-app://b/www.cryptokitties.co"
[:browser {:domain "www.cryptokitties.c"}]

(str "status-app://g/args?a=" public-key "&a1=" chat-name-url "&a2=" chat-id)
[:group-chat {:params "arg"} {"a" public-key "a1" chat-name "a2" chat-id}]

(str "https://status.app/g/args?a=" public-key "&a1=" chat-name-url "&a2=" chat-id)
[:group-chat {:params "arg"} {"a" public-key "a1" chat-name "a2" chat-id}]

"https://status.app/u/statuse2e"
[:user {:user-data "statuse2e"}]

(str "https://status.app/user/" public-key)
[:user {:user-id public-key}]

;; Last char removed by: https://github.com/juxt/bidi/issues/104
"https://status.app/b/www.cryptokitties.co"
[:browser {:domain "www.cryptokitties.c"}]

"https://status.app/b/https://www.google.com/"
[:browser {:domain "https://www.google.co"}]

"ethereum:0x89205a3a3b2a69de6dbf7f01ed13b2108b2c43e7"
[:ethereum {:address "0x89205a3a3b2a69de6dbf7f01ed13b2108b2c43e7"}]

Expand Down

0 comments on commit 969b763

Please sign in to comment.