From eb1cc65a3d170283bcce86d54e9af3cdf2235d48 Mon Sep 17 00:00:00 2001 From: tbenr Date: Fri, 14 Feb 2020 08:38:42 +0100 Subject: [PATCH] watch only qrcode and already exists check Signed-off-by: Churikova Tetiana --- src/status_im/subs.cljs | 6 +++++ .../ui/screens/wallet/add_new/views.cljs | 24 +++++++++++++++---- src/status_im/wallet/accounts/core.cljs | 15 ++++++++++++ src/status_im/wallet/core.cljs | 7 ++++++ test/cljs/status_im/test/i18n.cljs | 1 + translations/en.json | 3 ++- 6 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index ff80bcba33..322dd852e2 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -543,6 +543,12 @@ (or (not (ethereum/address? address)) (some #(when (= (:address %) address) %) accounts)))) +(re-frame/reg-sub + :add-account-scanned-address + :<- [:add-account] + (fn [add-account] + (get add-account :scanned-address))) + ;;CHAT ============================================================================================================== (re-frame/reg-sub diff --git a/src/status_im/ui/screens/wallet/add_new/views.cljs b/src/status_im/ui/screens/wallet/add_new/views.cljs index 6419112257..11edc42327 100644 --- a/src/status_im/ui/screens/wallet/add_new/views.cljs +++ b/src/status_im/ui/screens/wallet/add_new/views.cljs @@ -11,8 +11,8 @@ [status-im.multiaccounts.db :as multiaccounts.db] [status-im.ui.components.toolbar :as toolbar] [status-im.ui.components.styles :as components.styles] - [status-im.ethereum.core :as ethereum] - [status-im.ui.components.topbar :as topbar])) + [status-im.ui.components.topbar :as topbar] + [status-im.utils.utils :as utils.utils])) (defn add-account [] [react/view {:flex 1} @@ -62,10 +62,25 @@ :padding-horizontal 16 :background-color colors/gray-lighter}) +(defn- request-camera-permissions [] + (let [options {:handler :wallet.add-new/qr-scanner-result}] + (re-frame/dispatch + [:request-permissions + {:permissions [:camera] + :on-allowed + #(re-frame/dispatch [:wallet.add-new/qr-scanner-allowed options]) + :on-denied + #(utils.utils/set-timeout + (fn [] + (utils.utils/show-popup (i18n/label :t/error) + (i18n/label :t/camera-access-error))) + 50)}]))) + (defview add-watch-account [] - (letsubs [add-account-disabled? [:add-account-disabled?]] + (letsubs [add-account-disabled? [:add-account-disabled?] + add-account-scanned-address [:add-account-scanned-address]] [react/keyboard-avoiding-view {:flex 1} - [topbar/topbar] + [topbar/topbar {:accessories [{:icon :qr :handler #(request-camera-permissions)}]}] [react/view {:flex 1 :justify-content :space-between :align-items :center :margin-horizontal 16} @@ -78,6 +93,7 @@ [react/text-input {:auto-focus true :multiline true :text-align :center + :default-value add-account-scanned-address :placeholder (i18n/label :t/enter-address) :style {:typography :header :flex 1} :on-change-text #(re-frame/dispatch [:set-in [:add-account :address] %])}]]] diff --git a/src/status_im/wallet/accounts/core.cljs b/src/status_im/wallet/accounts/core.cljs index f690057d82..0258808993 100644 --- a/src/status_im/wallet/accounts/core.cljs +++ b/src/status_im/wallet/accounts/core.cljs @@ -3,6 +3,7 @@ [status-im.constants :as constants] [status-im.ethereum.core :as ethereum] [status-im.ethereum.eip55 :as eip55] + [status-im.ethereum.eip681 :as eip681] [status-im.ethereum.json-rpc :as json-rpc] [status-im.i18n :as i18n] [status-im.multiaccounts.update.core :as multiaccounts.update] @@ -169,3 +170,17 @@ :type :watch :color (rand-nth colors/account-colors)})} (navigation/navigate-to-cofx :account-added nil)))) + +(fx/defn view-only-qr-scanner-result + {:events [:wallet.add-new/qr-scanner-result]} + [{db :db :as cofx} data _] + (let [address (or (when (ethereum/address? data) data) + (:address (eip681/parse-uri data)))] + (fx/merge cofx + (merge {:db (-> db + (assoc-in [:add-account :scanned-address] address) + (assoc-in [:add-account :address] address))} + (when-not address + {:utils/show-popup {:title (i18n/label :t/error) + :content (i18n/label :t/invalid-address-qr-code)}})) + (navigation/navigate-back)))) diff --git a/src/status_im/wallet/core.cljs b/src/status_im/wallet/core.cljs index ae03a00d12..181e52ff6b 100644 --- a/src/status_im/wallet/core.cljs +++ b/src/status_im/wallet/core.cljs @@ -629,6 +629,13 @@ (bottom-sheet/hide-bottom-sheet) (navigation/navigate-to-cofx :qr-scanner options))) +(fx/defn view-only-qr-scanner-allowed + {:events [:wallet.add-new/qr-scanner-allowed]} + [{:keys [db] :as cofx} options] + (fx/merge cofx + {:db (update-in db [:add-account] dissoc :address)} + (navigation/navigate-to-cofx :qr-scanner options))) + (fx/defn wallet-send-set-symbol {:events [:wallet.send/set-symbol]} [{:keys [db] :as cofx} symbol] diff --git a/test/cljs/status_im/test/i18n.cljs b/test/cljs/status_im/test/i18n.cljs index c0bfd07ea6..fd406fde7a 100644 --- a/test/cljs/status_im/test/i18n.cljs +++ b/test/cljs/status_im/test/i18n.cljs @@ -550,6 +550,7 @@ :intro-wizard-title4 :intro-wizard-title5 :intro-wizard-title6 + :invalid-address-qr-code :invalid-extension :invalid-format :invalid-key-confirm diff --git a/translations/en.json b/translations/en.json index 362ce553b9..3427c9c5c6 100644 --- a/translations/en.json +++ b/translations/en.json @@ -440,7 +440,7 @@ "enter-recipient-address-or-username": "Enter address or username of the recepient", "enter-seed-phrase": "Enter seed phrase", "enter-url": "Enter URL", - "enter-watch-account-address": "Enter the address to watch", + "enter-watch-account-address": "Scan a QR code\nor\nenter the address to watch", "enter-word": "Enter word", "enter-your-code": "Enter your 6-digit passcode", "enter-your-password": "Enter your password", @@ -563,6 +563,7 @@ "intro-wizard-title6": "Enable notifications", "are-you-sure-to-cancel": "Are you sure you want to cancel?", "you-will-start-from-scratch": "You will start from scratch with a new set of keys", + "invalid-address-qr-code": "Scanned QR code doesn't contain a valid address", "invalid-extension": "Invalid extension URI", "invalid-format": "Invalid format\nMust be {{format}}", "invalid-key-confirm": "Apply",