Add ios-specific permissions checking

- Move permission check from main screen (no longer makes sense given
  choose recipient is reached from send)
- Add ios-specific display and permission checks
This commit is contained in:
angusiguess 2017-10-09 17:10:55 -03:00 committed by Roman Volosovskyi
parent e8c8dbc098
commit 1d2a7e2f6e
4 changed files with 27 additions and 18 deletions

View File

@ -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,6 +86,8 @@
(re-frame/dispatch [:set-in [:wallet/send-transaction :camera-dimensions]
{:width (.-width layout)
:height (.-height layout)}]))}
(when (or platform/android?
camera-permitted?)
[camera/camera {:style styles/preview
:aspect :fill
:captureAudio false
@ -92,6 +96,6 @@
(let [data (-> code
.-data
(string/replace #"ethereum:" ""))]
(re-frame/dispatch [:choose-recipient data nil])))}]
(re-frame/dispatch [:choose-recipient data nil])))}])
[viewfinder camera-dimensions]]
[recipient-buttons]]))

View File

@ -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)]

View File

@ -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?]))

View File

@ -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