Skip to content

Commit

Permalink
feat: support /u# /c# when parse and gen
Browse files Browse the repository at this point in the history
  • Loading branch information
yqrashawn committed Oct 26, 2023
1 parent 09df6ac commit e67a744
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/status_im/communities/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
(defn universal-link
[community-id]
(str (:external universal-links/domains)
"/c/"
"/c#"
community-id))

(defn <-request-to-join-community-rpc
Expand Down
4 changes: 3 additions & 1 deletion src/status_im/router/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
["cr/" :community-id] :community-requests
"g/" group-chat-extractor
["wallet/" :account] :wallet-account
["u/" :user-data] :user}
["u/" :user-data] :user
"c" :community
"u" :user}
ethereum-scheme eip-extractor}])

(defn parse-query-params
Expand Down
14 changes: 14 additions & 0 deletions src/status_im/router/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
:query-params (when (= 3 (count expected)) (last expected))
:uri uri})

"https://status.app/u#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
[:user
{:user-id "zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"}]
"https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
[:user
{:user-data
Expand All @@ -31,6 +34,10 @@
"G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y"
:user-id "zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"}]

"status-app://u#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
[:user
{:user-id "zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"}]

"https://status.app/cc/G54AAKwObLdpiGjXnckYzRcOSq0QQAS_CURGfqVU42ceGHCObstUIknTTZDOKF3E8y2MSicncpO7fTskXnoACiPKeejvjtLTGWNxUhlT7fyQS7Jrr33UVHluxv_PLjV2ePGw5GQ33innzeK34pInIgUGs5RjdQifMVmURalxxQKwiuoY5zwIjixWWRHqjHM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
[:community-chat
{:chat-data
Expand All @@ -48,13 +55,20 @@
{:community-data
"iyKACkQKB0Rvb2RsZXMSJ0NvbG9yaW5nIHRoZSB3b3JsZCB3aXRoIGpveSDigKIg4bSXIOKAohiYohsiByMxMzFEMkYqAwEhMwM="
:community-id "zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"}]
"https://status.app/c#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
[:community
{:community-id "zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"}]

"status-app://c/iyKACkQKB0Rvb2RsZXMSJ0NvbG9yaW5nIHRoZSB3b3JsZCB3aXRoIGpveSDigKIg4bSXIOKAohiYohsiByMxMzFEMkYqAwEhMwM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
[:community
{:community-data
"iyKACkQKB0Rvb2RsZXMSJ0NvbG9yaW5nIHRoZSB3b3JsZCB3aXRoIGpveSDigKIg4bSXIOKAohiYohsiByMxMzFEMkYqAwEhMwM="
:community-id "zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"}]

"status-app://c#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
[:community
{:community-id "zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"}]

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

Expand Down
23 changes: 2 additions & 21 deletions src/status_im/utils/universal_links/core.cljs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
(ns status-im.utils.universal-links.core
(:require
[clojure.string :as string]
[goog.string :as gstring]
[native-module.core :as native-module]
[re-frame.core :as re-frame]
[status-im.group-chats.core :as group-chats]
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.router.core :as router]
[status-im.ui.components.react :as react]
[status-im.wallet.choose-recipient.core :as choose-recipient]
[status-im2.constants :as constants]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]
[utils.ethereum.chain :as chain]
Expand All @@ -27,27 +25,11 @@
(def links
{:private-chat "%s/p/%s"
:community-requests "%s/cr/%s"
:community "%s/c/%s"
:community "%s/c#%s"
:group-chat "%s/g/%s"
:user "%s/u/%s"
:user "%s/u#%s"
:browse "%s/b/%s"})

(defn generate-link
[link-type domain-type param]
(gstring/format (get links link-type)
(get domains domain-type)
param))

(defn universal-link?
[url]
(boolean
(re-matches constants/regx-universal-link url)))

(defn deep-link?
[url]
(boolean
(re-matches constants/regx-deep-link url)))

(rf/defn handle-browse
[cofx {:keys [url]}]
(log/info "universal-links: handling browse" url)
Expand Down Expand Up @@ -220,7 +202,6 @@
#_(native-module/start-searching-for-local-pairing-peers
#(log/info "[local-pairing] errors from local-pairing-preflight-outbound-check ->" %)))


(defn finalize
"Remove event listener for url"
[]
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/utils/universal_links/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
(is (nil? (get-in (links/handle-url {:db db} "some-url")
[:db :universal-links/url]))))
(testing "Handle a custom string"
(is (= (get-in (links/handle-url {:db db} "https://status.app/u/statuse2e")
(is (= (get-in (links/handle-url {:db db} "https://status.app/u#statuse2e")
[::router/handle-uri :uri])
"https://status.app/u/statuse2e")))))))
"https://status.app/u#statuse2e")))))))

(deftest url-event-listener
(testing "the url is not nil"
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/utils/universal_links/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

(def links
{:private-chat "%s/p/%s"
:user "%s/u/%s"
:user "%s/u#%s"
:browse "%s/b/%s"})

(defn universal-link?
Expand Down
2 changes: 1 addition & 1 deletion src/status_im2/contexts/add_new_contact/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
(zipmap (repeat nil))))
([kv] (-> (init-contact) (merge kv))))

(def url-regex #"^https?://status.app/u/(.+)")
(def url-regex #"^https?://status.app/u#(.+)")

(defn ->id
[{:keys [input] :as contact}]
Expand Down
4 changes: 2 additions & 2 deletions src/status_im2/contexts/add_new_contact/events_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
(def ckey "zQ3shWj4WaBdf2zYKCkXe6PHxDxNTzZyid1i75879Ue9cX9gA")
(def ens "esep")
(def ens-stateofus-eth (str ens ".stateofus.eth"))
(def link-ckey (str "https://status.app/u/" ckey))
(def link-ens (str "https://status.app/u/" ens))
(def link-ckey (str "https://status.app/u#" ckey))
(def link-ens (str "https://status.app/u#" ens))

;;; unit tests (no app-db involved)

Expand Down
9 changes: 4 additions & 5 deletions src/status_im2/contexts/add_new_contact/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@
:button (when empty-input?
{:on-press paste-on-input
:text (i18n/label :t/paste)})
;; NOTE: `scanned` has priority over `@input-value`, we clean it when the input
;; is updated so that it's `nil` and `@input-value` is shown.
;; To fastly clean it, we use `dispatch-sync`.
;; This call could be avoided if `::qr-scanner/scan-code` were able to receive a
;; callback function, not only a re-frame event as callback.
;; NOTE: `scanned` has priority over `@input-value`, we clean it when the input is updated
;; so that it's `nil` and `@input-value` is shown. To fastly clean it, we use
;; `dispatch-sync`. This call could be avoided if `::qr-scanner/scan-code` were able to
;; receive a callback function, not only a re-frame event as callback.
:value (or scanned @input-value)
:on-change-text (fn [new-text]
(reset! input-value new-text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

(defn community-link
[id]
(str "https://status.app/c/" id))
(str "https://status.app/c#" id))

(rf/defn cache-link-preview-data
{:events [:chat.ui/cache-link-preview-data]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[]
(let [state (reagent/atom {:info-button? true
:link-title "Link to profile"
:url "status.app/u/zQ34e1zlOdas0pKnvrweeedsasas12adjie8"})]
:url "status.app/u#zQ34e1zlOdas0pKnvrweeedsasas12adjie8"})]
(fn []
(let [qr-media-server-uri (image-server/get-qr-image-uri-for-any-url
{:url (:url @state)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/address.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@

(defn get-abbreviated-profile-url
"The goal here is to generate a string that begins with
status.app/u/ joined with the 1st 5 characters
status.app/u# joined with the 1st 5 characters
of the compressed public key followed by an ellipsis followed by
the last 10 characters of the compressed public key"
[base-url public-key]
(if (and public-key base-url (> (count public-key) 17) (= "status.app/u/" base-url))
(if (and public-key base-url (> (count public-key) 17) (= "status.app/u#" base-url))
(let [first-part-of-public-pk (subs public-key 0 5)
ellipsis "..."
public-key-size (count public-key)
Expand Down
14 changes: 7 additions & 7 deletions src/utils/address_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@

(deftest test-get-abbreviated-profile-url
(testing "Ensure the function correctly generates an abbreviated profile URL for a valid public key"
(is (= "status.app/u/zQ3sh...mrdYpzeFUa"
(is (= "status.app/u#zQ3sh...mrdYpzeFUa"
(utils.address/get-abbreviated-profile-url
"status.app/u/"
"status.app/u#"
"zQ3shPrnUhhR42JJn3QdhodGest8w8MjiH8hPaimrdYpzeFUa"))))

(testing "Ensure the function returns nil when given an empty public key"
(is (nil? (utils.address/get-abbreviated-profile-url "status.app/u/" ""))))
(is (nil? (utils.address/get-abbreviated-profile-url "status.app/u#" ""))))

(testing "Ensure the function returns nil when given a nil public key"
(is (nil? (utils.address/get-abbreviated-profile-url "status.app/u/" nil))))
(is (nil? (utils.address/get-abbreviated-profile-url "status.app/u#" nil))))

(testing "Ensure the function returns nil when given an incorrect base URL"
(is (nil? (utils.address/get-abbreviated-profile-url
"status.app/uwu/"
"status.app/uwu#"
"zQ3shPrnUhhR42JJn3QdhodGest8w8MjiH8hPaimrdYpzeFUa"))))

(testing "Ensure the function returns nil when given a public key shorter than 17 characters"
(is (nil? (utils.address/get-abbreviated-profile-url "status.app/u/" "abc")))
(is (nil? (utils.address/get-abbreviated-profile-url "status.app/u/" "1234")))))
(is (nil? (utils.address/get-abbreviated-profile-url "status.app/u#" "abc")))
(is (nil? (utils.address/get-abbreviated-profile-url "status.app/u#" "1234")))))
4 changes: 2 additions & 2 deletions src/utils/image_server.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
(def ^:const account-initials-action "/accountInitials")
(def ^:const contact-images-action "/contactImages")
(def ^:const generate-qr-action "/GenerateQRCode")
(def ^:const status-profile-base-url "https://status.app/u/")
(def ^:const status-profile-base-url-without-https "status.app/u/")
(def ^:const status-profile-base-url "https://status.app/u#")
(def ^:const status-profile-base-url-without-https "status.app/u#")

(defn get-font-file-ready
"setup font file and get the absolute path to it
Expand Down

0 comments on commit e67a744

Please sign in to comment.