bug #4485 - shows warning when scanned qr code changes pre-selected asset type or amount

Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
Goran Jovic 2018-05-28 16:51:56 +02:00
parent 446ae1b30d
commit dd37223b58
No known key found for this signature in database
GPG Key ID: D429D1A9B2EB8A8E
7 changed files with 56 additions and 22 deletions

View File

@ -573,6 +573,8 @@
:wallet-address-from-clipboard "Use Address From Clipboard"
:wallet-invalid-address "Invalid address: \n {{data}}"
:wallet-invalid-chain-id "Network does not match: \n {{data}} but current chain is {{chain}}"
:changed-asset-warning "Asset was changed from {{old}} to {{new}}"
:changed-amount-warning "Amount was changed from {{old}} to {{new}}"
:wallet-browse-photos "Browse Photos"
:wallet-advanced "Advanced"
:wallet-transaction-fee "Transaction Fee"

View File

@ -35,17 +35,43 @@
(when (ethereum/address? s)
{:address s :chain-id chain-id})))
(defn changed-asset-warning [cofx old-symbol new-symbol]
(assoc-in cofx [:db :wallet :send-transaction :asset-error]
(i18n/label :t/changed-asset-warning {:old old-symbol :new new-symbol})))
(defn changed-amount-warning [cofx old-amount new-amount]
(assoc-in cofx [:db :wallet :send-transaction :amount-error]
(i18n/label :t/changed-amount-warning {:old old-amount :new new-amount})))
(defn use-default-eth-gas [cofx]
(assoc-in cofx [:db :wallet :send-transaction :gas]
ethereum/default-transaction-gas))
(handlers/register-handler-fx
:wallet/fill-request-from-url
(fn [{{:keys [network] :as db} :db} [_ data]]
(let [{:keys [view-id]} db
current-chain-id (get-in constants/default-networks [network :config :NetworkId])
(fn [{{:keys [network] :as db} :db} [_ data origin]]
(let [{:keys [view-id]} db
current-chain-id (get-in constants/default-networks [network :config :NetworkId])
{:keys [address chain-id] :as details} (extract-details data current-chain-id)
valid-network? (boolean (= current-chain-id chain-id))]
valid-network? (boolean (= current-chain-id chain-id))
previous-state (get-in db [:wallet :send-transaction])
old-symbol (:symbol previous-state)
new-symbol (:symbol details)
old-amount (:amount previous-state)
new-amount (:value details)
new-gas (:gas details)]
(cond-> {:db db
:dispatch [:navigate-back]}
(and address (= :choose-recipient view-id)) (assoc :dispatch [:navigate-back])
(and address valid-network?) (update :db #(fill-request-details % details))
(and old-symbol new-symbol (not= old-symbol new-symbol)) (changed-asset-warning old-symbol new-symbol)
(and old-amount new-amount (not= old-amount new-amount)) (changed-amount-warning old-amount new-amount)
;; NOTE(goranjovic) - the next line is there is because QR code scanning switches the amount to ETH
;; automatically, so we need to update the gas limit accordingly. The check for origin screen is there
;; so that we wouldn't also switch gas limit to ETH specific if the user pastes address as text.
;; We need to check if address is defined so that we wouldn't trigger this behavior when invalid QR is scanned
;; (e.g. whisper-id)
(and address (= origin :qr) (not new-gas)) (use-default-eth-gas)
(not address) (assoc :show-error (i18n/label :t/wallet-invalid-address {:data data}))
(and address (not valid-network?)) (assoc :show-error (i18n/label :t/wallet-invalid-chain-id {:data data :chain current-chain-id}))))))

View File

@ -63,7 +63,7 @@
:torchMode (camera/set-torch camera-flashlight)
:onBarCodeRead #(when-not @read-once?
(reset! read-once? true)
(re-frame/dispatch [:wallet/fill-request-from-url (camera/get-qr-code-data %) nil]))}]]
(re-frame/dispatch [:wallet/fill-request-from-url (camera/get-qr-code-data %) :qr]))}]]
[viewfinder dimensions (size dimensions)]]
[bottom-buttons/bottom-button
[button/button {:disabled? false

View File

@ -75,23 +75,26 @@
:request :wallet-request-assets
(throw (str "Unknown type: " k))))
(views/defview asset-selector [{:keys [disabled? type symbol]}]
(views/defview asset-selector [{:keys [disabled? type symbol error]}]
(views/letsubs [balance [:balance]
network [:network]]
(let [{:keys [name icon decimals]} (tokens/asset-for (ethereum/network->chain-keyword network) symbol)]
[components/cartouche {:disabled? disabled? :on-press #(re-frame/dispatch [:navigate-to (type->view type)])}
(i18n/label :t/wallet-asset)
[react/view {:style styles/asset-content-container
:accessibility-label :choose-asset-button}
[list/item-image (assoc icon :style styles/asset-icon :image-style {:width 32 :height 32})]
[react/view styles/asset-text-content
[react/view styles/asset-label-content
[react/text {:style (merge styles/text-content styles/asset-label)}
name]
[react/text {:style styles/text-secondary-content}
(clojure.core/name symbol)]]
[react/text {:style (merge styles/text-secondary-content styles/asset-label)}
(str (wallet.utils/format-amount (symbol balance) decimals))]]]])))
[react/view
[components/cartouche {:disabled? disabled? :on-press #(re-frame/dispatch [:navigate-to (type->view type)])}
(i18n/label :t/wallet-asset)
[react/view {:style styles/asset-content-container
:accessibility-label :choose-asset-button}
[list/item-image (assoc icon :style styles/asset-icon :image-style {:width 32 :height 32})]
[react/view styles/asset-text-content
[react/view styles/asset-label-content
[react/text {:style (merge styles/text-content styles/asset-label)}
name]
[react/text {:style styles/text-secondary-content}
(clojure.core/name symbol)]]
[react/text {:style (merge styles/text-secondary-content styles/asset-label)}
(str (wallet.utils/format-amount (symbol balance) decimals))]]]]
(when error
[tooltip/tooltip error {}])])))
(defn- recipient-address [address]
[react/text {:style (merge styles/recipient-address (when-not address styles/recipient-no-address))
@ -150,7 +153,7 @@
:accessibility-label :recipient-address-input}]]
[bottom-buttons/bottom-button
[button/button {:disabled? (string/blank? @content)
:on-press #(re-frame/dispatch [:wallet/fill-request-from-url @content])
:on-press #(re-frame/dispatch [:wallet/fill-request-from-url @content :code])
:fit-to-text? false}
(i18n/label :t/done)]]]])))

View File

@ -8,6 +8,7 @@
(spec/def ::to (spec/nilable string?))
(spec/def ::to-name (spec/nilable string?))
(spec/def ::amount-error (spec/nilable string?))
(spec/def ::asset-error (spec/nilable string?))
(spec/def ::amount-text (spec/nilable string?))
(spec/def ::password (spec/nilable #(instance? security/MaskedData %)))
(spec/def ::wrong-password? (spec/nilable boolean?))
@ -28,7 +29,7 @@
(spec/def ::method (spec/nilable string?))
(spec/def :wallet/send-transaction (allowed-keys
:opt-un [::amount ::to ::to-name ::amount-error ::amount-text ::password
:opt-un [::amount ::to ::to-name ::amount-error ::asset-error ::amount-text ::password
::waiting-signal? ::signing? ::id ::later?
::camera-flashlight ::in-progress?
::wrong-password? ::from-chat? ::symbol ::advanced?

View File

@ -89,6 +89,7 @@
(assoc-in [:wallet :send-transaction :symbol] symbol)
(assoc-in [:wallet :send-transaction :amount] nil)
(assoc-in [:wallet :send-transaction :amount-text] nil)
(assoc-in [:wallet :send-transaction :asset-error] nil)
(assoc-in [:wallet :send-transaction :gas] (ethereum/estimate-gas symbol)))}))
(handlers/register-handler-fx

View File

@ -198,7 +198,7 @@
[advanced-cartouche transaction modal?])])
(defn- send-transaction-panel [{:keys [modal? transaction scroll advanced? network]}]
(let [{:keys [amount amount-text amount-error signing? to to-name sufficient-funds? in-progress? from-chat? symbol]} transaction
(let [{:keys [amount amount-text amount-error asset-error signing? to to-name sufficient-funds? in-progress? from-chat? symbol]} transaction
{:keys [decimals] :as token} (tokens/asset-for (ethereum/network->chain-keyword network) symbol)
timeout (atom nil)]
[wallet.components/simple-screen {:avoid-keyboard? (not modal?)
@ -216,6 +216,7 @@
:address to
:name to-name}]
[components/asset-selector {:disabled? (or from-chat? modal?)
:error asset-error
:type :send
:symbol symbol}]
[components/amount-selector {:disabled? (or from-chat? modal?)