Skip to content

Commit

Permalink
Scan url with QR scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Calabio committed Apr 10, 2019
1 parent b06ef9c commit 14a533e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 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 @@ -199,6 +199,12 @@
(utils.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 @@ -1395,6 +1395,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 @@ -39,7 +39,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
11 changes: 7 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,13 +4,16 @@
[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]))

(fx/defn handle-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 [:qr-scanner.ui/qr-code-error-dismissed])}})))
(if (clojure.string/includes? 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])}}))))

0 comments on commit 14a533e

Please sign in to comment.