Skip to content

Commit

Permalink
Updates for on-qr-code-scanned
Browse files Browse the repository at this point in the history
  • Loading branch information
alwx committed Jan 31, 2024
1 parent c0746a5 commit 25eb9ea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/status_im/common/router.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
(def web-urls (map #(str % web2-domain "/") web-prefixes))

(defn path-urls [path]
(map #(str % "/" path) web-urls))
(map #(str % path) web-urls))

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

Expand Down
55 changes: 24 additions & 31 deletions src/status_im/contexts/shell/qr_reader/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@
[react-native.hooks :as hooks]
[status-im.common.router :as router]
[status-im.common.scan-qr-code.view :as scan-qr-code]
[status-im.contexts.communities.events]
[status-im.contexts.wallet.common.validation :as wallet-validation]
[status-im.navigation.events :as navigation]
[utils.i18n :as i18n]))

(defn community-qr-code?
[scanned-text]
(string/starts-with? scanned-text "https://status.app/c/"))

;;(some string/starts-with? (router/path-urls router/user-with-data-path))
(defn- text-for-path? [text path]
(some #(string/starts-with? text %) (router/path-urls path)))

(defn channel-qr-code?
(defn- extract-id
[scanned-text]
(string/starts-with? scanned-text "https://status.app/cc/"))

(defn profile-qr-code?
[scanned-text]
(string/starts-with? scanned-text "https://status.app/u/"))
(let [index (string/index-of scanned-text "#")]
(subs scanned-text index)))

(defn legacy-eth-address?
[scanned-text]
Expand All @@ -32,32 +27,30 @@
[scanned-text]
false)

(defn extracted-id
[scanned-text]
(let [index (string/index-of scanned-text "#")]
(subs scanned-text index)))

(defn on-qr-code-scanned [scanned-text]
(cond
(community-qr-code? scanned-text)
false
(let [address (extract-id scanned-text)]
(cond
(text-for-path? scanned-text router/community-with-data-path)
(rf/dispatch [:communities/navigate-to-community-overview address])

(channel-qr-code? scanned-text)
false
(text-for-path? scanned-text router/channel-path)
nil

(profile-qr-code? scanned-text)
(rf/dispatch [:chat.ui/show-profile (extracted-id scanned-text)])
(text-for-path? scanned-text router/user-with-data-path)
(rf/dispatch [:chat.ui/show-profile address])

(legacy-eth-address? scanned-text)
(navigation/change-tab :wallet-stack)
(legacy-eth-address? scanned-text)
;; :wallet/scan-address-success
(rf/dispatch [:navigate-to :wallet-accounts address])

(pairing-qr-code? scanned-text)
false
(pairing-qr-code? scanned-text)
;; :syncing/input-connection-string-for-bootstrapping
nil

:else
#(rf/dispatch [:toasts/upsert {:type :negative
:theme :dark
:text (i18n/label :t/invalid-qr)}])))
:else
(rf/dispatch [:toasts/upsert {:type :negative
:theme :dark
:text (i18n/label :t/invalid-qr)}]))))

(defn- f-internal-view
[]
Expand Down

0 comments on commit 25eb9ea

Please sign in to comment.