diff --git a/src/status_im/ui/screens/wallet/choose_recipient/views.cljs b/src/status_im/ui/screens/wallet/choose_recipient/views.cljs index 6c58e3e0e7..77927e0282 100644 --- a/src/status_im/ui/screens/wallet/choose_recipient/views.cljs +++ b/src/status_im/ui/screens/wallet/choose_recipient/views.cljs @@ -9,6 +9,7 @@ [status-im.components.react :as react] [status-im.components.icons.vector-icons :as vector-icons] [status-im.ui.screens.wallet.choose-recipient.styles :as styles] + [status-im.utils.platform :as platform] [status-im.components.status-bar :as status-bar] [status-im.components.camera :as camera] [clojure.string :as string])) @@ -75,7 +76,8 @@ (defview choose-recipient [] (letsubs [camera-dimensions [:camera-dimensions] - camera-flashlight [:camera-flashlight]] + camera-flashlight [:camera-flashlight] + camera-permitted? [:get-in [:wallet/send-transaction :camera-permitted?]]] [react/view {:style styles/wallet-container} [status-bar/status-bar {:type :wallet}] [toolbar-view camera-flashlight] @@ -84,14 +86,16 @@ (re-frame/dispatch [:set-in [:wallet/send-transaction :camera-dimensions] {:width (.-width layout) :height (.-height layout)}]))} - [camera/camera {:style styles/preview - :aspect :fill - :captureAudio false - :torchMode (camera/set-torch camera-flashlight) - :onBarCodeRead (fn [code] - (let [data (-> code - .-data - (string/replace #"ethereum:" ""))] - (re-frame/dispatch [:choose-recipient data nil])))}] + (when (or platform/android? + camera-permitted?) + [camera/camera {:style styles/preview + :aspect :fill + :captureAudio false + :torchMode (camera/set-torch camera-flashlight) + :onBarCodeRead (fn [code] + (let [data (-> code + .-data + (string/replace #"ethereum:" ""))] + (re-frame/dispatch [:choose-recipient data nil])))}]) [viewfinder camera-dimensions]] [recipient-buttons]])) diff --git a/src/status_im/ui/screens/wallet/main/views.cljs b/src/status_im/ui/screens/wallet/main/views.cljs index 70c7285b36..d4bb340351 100644 --- a/src/status_im/ui/screens/wallet/main/views.cljs +++ b/src/status_im/ui/screens/wallet/main/views.cljs @@ -61,11 +61,6 @@ (str (when pos-change? "+") change "%") "-%")]])) -(defn- wallet-send [] - (rf/dispatch [:navigate-to :wallet-send-transaction]) - (when platform/android? - (rf/dispatch [:request-permissions [:camera]]))) - (defn main-section [usd-value change error-message] [react/view {:style styles/main-section} (when error-message @@ -79,7 +74,8 @@ (i18n/label :t/wallet-total-value)] [change-display change]] [react/view {:style (merge button.styles/buttons-container styles/buttons) :button-text-style styles/main-button-text} - [btn/button {:on-press wallet-send :style (button.styles/button-bar :first)} + [btn/button {:on-press #(rf/dispatch [:navigate-to :wallet-send-transaction]) + :style (button.styles/button-bar :first)} (i18n/label :t/wallet-send)] [btn/button {:on-press #(rf/dispatch [:navigate-to :wallet-request-transaction]) :style (button.styles/button-bar :other)} (i18n/label :t/wallet-request)] diff --git a/src/status_im/ui/screens/wallet/send/db.cljs b/src/status_im/ui/screens/wallet/send/db.cljs index 8b5af98048..1aeab820ac 100644 --- a/src/status_im/ui/screens/wallet/send/db.cljs +++ b/src/status_im/ui/screens/wallet/send/db.cljs @@ -16,10 +16,11 @@ (spec/def ::width double?) (spec/def ::camera-dimensions (spec/keys :req-un [::height ::width])) (spec/def ::camera-flashlight #{:on :off}) +(spec/def ::camera-permitted? boolean?) (spec/def ::in-progress? boolean?) (spec/def :wallet/send-transaction (allowed-keys :opt-un [::amount ::to-address ::to-name ::amount-error ::password ::waiting-signal? ::signing? ::transaction-id ::later? ::camera-dimensions ::camera-flashlight ::in-progress? - ::wrong-password?])) + ::wrong-password? ::camera-permitted?])) diff --git a/src/status_im/ui/screens/wallet/send/views.cljs b/src/status_im/ui/screens/wallet/send/views.cljs index 3538ddcb93..6bd5d93e03 100644 --- a/src/status_im/ui/screens/wallet/send/views.cljs +++ b/src/status_im/ui/screens/wallet/send/views.cljs @@ -96,6 +96,14 @@ (defn- sufficient-funds? [amount balance] (<= amount (money/wei->ether balance))) +(defn request-camera-permissions [] + (when platform/android? + (re-frame/dispatch [:request-permissions [:camera]])) + (camera/request-access + (fn [permitted?] + (re-frame/dispatch [:set-in [:wallet/send-transaction :camera-permitted?] permitted?]) + (re-frame/dispatch [:navigate-to :choose-recipient])))) + (defview send-transaction [] (letsubs [balance [:balance] amount [:get-in [:wallet/send-transaction :amount]] @@ -114,7 +122,7 @@ [react/view wallet.styles/choose-participant-container [components/choose-recipient {:address to-address :name to-name - :on-press #(re-frame/dispatch [:navigate-to :choose-recipient])}]] + :on-press request-camera-permissions}]] [react/view wallet.styles/choose-wallet-container [components/choose-wallet]] [react/view wallet.styles/amount-container