add plain url support in all qr scanners, add scanner to browser options

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2021-06-17 14:51:09 +02:00
parent a1d091ac19
commit dd5864ff25
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
7 changed files with 55 additions and 16 deletions

View File

@ -140,6 +140,13 @@
{:type :browser
:error :unsafe-link})))
(defn match-browser-string [domain]
(if (security/safe-link? domain)
{:type :browser
:url domain}
{:type :browser
:error :unsafe-link}))
;; NOTE(Ferossgp): Better to handle eip681 also with router instead of regexp.
(defn match-eip681 [uri]
(if-let [message (eip681/parse-uri uri)]
@ -218,6 +225,9 @@
(ethereum/address? uri)
(cb (address->eip681 uri))
(http/url? uri)
(cb (match-browser-string uri))
:else
(cb {:type :undefined
:data uri}))))

View File

@ -10,7 +10,8 @@
[status-im.utils.http :as http]
[status-im.utils.utils :as utils]
[status-im.ui.components.icons.icons :as icons]
[status-im.constants :as constants]))
[status-im.constants :as constants]
[status-im.qr-scanner.core :as qr-scanner]))
(defn hide-sheet-and-dispatch [event]
(re-frame/dispatch [:bottom-sheet/hide])
@ -43,6 +44,15 @@
fav? (get bookmarks url)
connected? (some #{constants/dapp-permission-web3} (get-in permissions [(http/url-host url) :permissions]))]
[react/view {:flex 1}
[quo/button {:style {:align-self :flex-end
:margin-right 15}
:type :icon
:theme :icon
:accessibility-label :universal-qr-scanner
:on-press #(hide-sheet-and-dispatch
[::qr-scanner/scan-code
{:handler ::qr-scanner/on-scan-success}])}
:main-icons/qr]
(when-not empty-tab
[:<>
[quo/list-item

View File

@ -22,7 +22,8 @@
[status-im.ui.components.permissions :as components.permissions]
[quo.core :as quo]
[status-im.ui.screens.wallet.components.views :as components]
[status-im.ui.screens.browser.options.views :as options])
[status-im.ui.screens.browser.options.views :as options]
[status-im.qr-scanner.core :as qr-scanner])
(:require-macros [status-im.utils.views :as views]))
(defn toolbar-content [url url-original secure? url-editing? unsafe?]
@ -93,18 +94,23 @@
:accessibility-label :browser-open-tabs}
[icons/icon :main-icons/tabs]]
[react/touchable-highlight
{:on-press #(when-not empty-tab
(re-frame/dispatch
(if empty-tab
[react/touchable-highlight
{:accessibility-label :universal-qr-scanner
:on-press #(re-frame/dispatch
[::qr-scanner/scan-code
{:handler ::qr-scanner/on-scan-success}])}
[icons/icon :main-icons/qr]]
[react/touchable-highlight
{:on-press #(re-frame/dispatch
[:bottom-sheet/show-sheet
{:content (options/browser-options
url
dapps-account
empty-tab
name)}]))
:style (when empty-tab styles/disabled-button)
:accessibility-label :browser-options}
[icons/icon :main-icons/more]]]))
name)}])
:accessibility-label :browser-options}
[icons/icon :main-icons/more]])]))
(def resources-to-permissions-map {"android.webkit.resource.VIDEO_CAPTURE" :camera
"android.webkit.resource.AUDIO_CAPTURE" :record-audio})

View File

@ -34,7 +34,8 @@
[{:icon :qr
:accessibility-label :scan-contact-code-button
:on-press #(re-frame/dispatch [:wallet.send/qr-scanner
{:handler :wallet.send/qr-scanner-result}])}]}])
{:ignore-url true
:handler :wallet.send/qr-scanner-result}])}]}])
(defonce search-active? (reagent/atom false))

View File

@ -126,6 +126,12 @@
(string/replace host #"www." "")))
(catch :default _ nil)))
(defn url? [str]
(try
(when-let [host (.getDomain ^js (goog.Uri. str))]
(not (string/blank? host)))
(catch :default _ nil)))
(defn parse-payload [o]
(when o
(try

View File

@ -89,7 +89,7 @@
(fx/defn handle-eip681 [cofx data]
(fx/merge cofx
(choose-recipient/parse-eip681-uri-and-resolve-ens data)
(choose-recipient/parse-eip681-uri-and-resolve-ens data true)
(navigation/navigate-to-cofx :wallet nil)))
(fx/defn handle-referrer-url [_ {:keys [referrer]}]

View File

@ -10,7 +10,9 @@
[status-im.router.core :as router]
[status-im.qr-scanner.core :as qr-scaner]
[status-im.bottom-sheet.core :as bottom-sheet]
[status-im.navigation :as navigation]))
[status-im.navigation :as navigation]
[status-im.utils.http :as http]
[status-im.utils.universal-links.utils :as links]))
;; FIXME(Ferossgp): Should be part of QR scanner not wallet
(fx/defn toggle-flashlight
@ -102,7 +104,7 @@
(fx/defn parse-eip681-uri-and-resolve-ens
{:events [:wallet/parse-eip681-uri-and-resolve-ens]}
[{db :db :as cofx} {:keys [message uri paths ens-names error]}]
[{db :db :as cofx} {:keys [message uri paths ens-names error]} ignore-url]
(if-not error
;; first we get a vector of ens-names to resolve and a vector of paths of
;; these names
@ -122,11 +124,15 @@
(assoc-in message path address))
message
(map vector paths addresses)) uri]))}})
{:ui/show-error (i18n/label :t/wallet-invalid-address {:data uri})}))
(if (and (http/url? uri) (not ignore-url))
(if (links/universal-link? uri)
{:dispatch [:universal-links/handle-url uri]}
{:browser/show-browser-selection uri})
{:ui/show-error (i18n/label :t/wallet-invalid-address {:data uri})})))
(fx/defn qr-scanner-result
{:events [:wallet.send/qr-scanner-result]}
[cofx data _]
[cofx data {:keys [ignore-url]}]
(fx/merge cofx
(navigation/navigate-back)
(parse-eip681-uri-and-resolve-ens (router/match-eip681 data))))
(parse-eip681-uri-and-resolve-ens (router/match-eip681 data) ignore-url)))