From 969b76338188f4a5de7d5710dab5b7f026d1562d Mon Sep 17 00:00:00 2001 From: yqrashawn Date: Wed, 4 Oct 2023 10:09:22 +0800 Subject: [PATCH] refactor: remote old uri routes didn't remove the route handler we might need these in the future Signed-off-by: yqrashawn --- src/status_im/router/core.cljs | 48 ++++++++++++----------------- src/status_im/router/core_test.cljs | 28 ----------------- 2 files changed, 19 insertions(+), 57 deletions(-) diff --git a/src/status_im/router/core.cljs b/src/status_im/router/core.cljs index 38ca3b6aab1f..86e2f18312e6 100644 --- a/src/status_im/router/core.cljs +++ b/src/status_im/router/core.cljs @@ -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]} @@ -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 @@ -252,13 +237,14 @@ :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)) @@ -266,17 +252,20 @@ (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) @@ -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)) diff --git a/src/status_im/router/core_test.cljs b/src/status_im/router/core_test.cljs index 7c13c75d74b3..dbf51f8b04ff 100644 --- a/src/status_im/router/core_test.cljs +++ b/src/status_im/router/core_test.cljs @@ -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"}]