Skip to content

Commit

Permalink
Scan URL with QR Scanner from Chats
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Calabio committed Jun 19, 2019
1 parent b6163b8 commit 6083c23
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion env/dev/env/config.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns env.config)

(def figwheel-urls {:android "ws://localhost:3449/figwheel-ws",
:ios "ws://192.168.0.9:3449/figwheel-ws",
:ios "ws://192.168.1.88:3449/figwheel-ws",
:desktop "ws://localhost:3449/figwheel-ws"}
)
6 changes: 6 additions & 0 deletions src/status_im/browser/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@
(universal-links/handle-url cofx link)
{:browser/show-browser-selection link}))

(fx/defn browser-selection-cancel
[{:keys [db]}]
(let [view-id (:view-id db)]
(if (= view-id :qr-scanner)
{:db (assoc-in db [:navigation/screen-params view-id :barcode-read?] false)})))

(fx/defn update-browser-on-nav-change
[cofx url error?]
(let [browser (get-current-browser (:db cofx))
Expand Down
5 changes: 5 additions & 0 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,11 @@
(fn [cofx [_ link]]
(browser/handle-message-link cofx link)))

(handlers/register-handler-fx
:browser.ui/browser-selection-cancel
(fn [cofx [_ _]]
(browser/browser-selection-cancel cofx)))

(handlers/register-handler-fx
:browser.ui/remove-browser-pressed
(fn [cofx [_ browser-id]]
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/ui/components/list_selection.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
:action #(re-frame/dispatch [:browser.ui/open-url link])}
{:label (i18n/label (platform-web-browser))
:action #(.openURL (react/linking) (http/normalize-url link))}]
:cancel-text (i18n/label :t/browsing-cancel)}))
:cancel-text (i18n/label :t/browsing-cancel)
:on-cancel #(re-frame/dispatch [:browser.ui/browser-selection-cancel])}))

(defn browse-in-web-browser [link]
(show {:title (i18n/label :t/browsing-title)
Expand Down
21 changes: 14 additions & 7 deletions src/status_im/ui/screens/add_new/models.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
[status-im.i18n :as i18n]
[status-im.ui.screens.navigation :as navigation]
[status-im.utils.universal-links.core :as universal-links]
[status-im.utils.fx :as fx]))
[status-im.utils.fx :as fx]
[status-im.browser.core :as browser]
[status-im.constants :as constants]
[status-im.extensions.core :as extensions]))

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

(fx/defn process-qr-code
[cofx data]
(if (spec/valid? :global/public-key data)
(universal-links/handle-view-profile cofx data)
(or (universal-links/handle-url cofx data)
{:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
:content (i18n/label :t/use-valid-qr-code {:data data})
:on-dismiss #(re-frame/dispatch [:navigate-to-clean :home])}})))
(cond (spec/valid? :global/public-key data) (universal-links/handle-view-profile cofx data)
(universal-links/universal-link? data) (universal-links/handle-url cofx data)
(universal-links/deep-link? data) (universal-links/handle-url cofx data)
(valid-url? data) (browser/handle-message-link cofx data)
:else {:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
:content (i18n/label :t/use-valid-qr-code {:data data})
:on-dismiss #(re-frame/dispatch [:navigate-to-clean :home])}}))

(fx/defn handle-qr-code
[cofx data]
Expand Down
2 changes: 1 addition & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
"currency-display-name-npr": "Nepal Rupee",
"backup-recovery-phrase": "Backup recovery phrase",
"send-request": "Send request",
"use-valid-qr-code": "This QR code doesn't contain a valid universal link, contact code or username: {{data}}",
"use-valid-qr-code": "This QR code doesn't contain a valid universal link, url, contact code or username: {{data}}",
"paste-json": "Paste JSON",
"browsing-site-blocked-title": "This site is blocked",
"browsing-site-blocked-description1": "We detected potential malicious activity from this address. To protect you and your wallet, we're preventing further navigation.\n\nIf you think this is an error, let us know in the ",
Expand Down

0 comments on commit 6083c23

Please sign in to comment.