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 11, 2019
1 parent e925b2d commit 4e927d5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/status_im/browser/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,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 @@ -1499,6 +1499,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-in-status-option-selected 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
16 changes: 12 additions & 4 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,24 @@
[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])}})))
(if (valid-url? data)
(browser/handle-message-link 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 [:qr-scanner.ui/qr-code-error-dismissed])}}))))

(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 @@ -382,7 +382,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 4e927d5

Please sign in to comment.