[BUG #2133] Correctly parse/generate amount from QR code

This commit is contained in:
Julien Eluard 2017-10-16 20:28:50 +02:00 committed by Roman Volosovskyi
parent 43dab5b174
commit 8393f19596
2 changed files with 17 additions and 15 deletions

View File

@ -10,30 +10,31 @@
toggled-state (if (= :on flashlight-state) :off :on)]
(assoc-in db [:wallet/send-transaction :camera-flashlight] toggled-state))))
(defn choose-address-and-name [db address name]
(update db :wallet/send-transaction assoc :to-address address :to-name name))
(defn choose-address-and-name [db address name amount]
(update db :wallet/send-transaction assoc :to-address address :to-name name :amount amount))
(defn- extract-address [s]
;; First try to parse as EIP67 URI, if not assume this is an address directly
(if-let [m (eip67/parse-uri s)]
(:address m)
s))
(defn- extract-details
"First try to parse as EIP67 URI, if not assume this is an address directly.
Returns a map containing at least the `address` key"
[s]
(or (eip67/parse-uri s) {:address s}))
(handlers/register-handler-fx
:choose-recipient
(fn [{{:keys [web3] :as db} :db} [_ data name]]
(let [{:keys [view-id]} db
address (extract-address data)
m (extract-details data)
address (:address m)
;; isAddress works with or without address with leading '0x'
valid-address? (.isAddress web3 address)]
(cond-> {:db db}
(= :choose-recipient view-id) (assoc :dispatch [:navigate-back])
valid-address? (update :db #(choose-address-and-name % address name))
valid-address? (update :db #(choose-address-and-name % address name (:value m)))
(not valid-address?) (assoc :show-error (i18n/label :t/wallet-invalid-address {:data data}))))))
(handlers/register-handler-fx
:wallet-open-send-transaction
(fn [{db :db} [_ address name]]
{:db (choose-address-and-name db address name)
{:db (choose-address-and-name db address name nil)
:dispatch-n [[:navigate-back]
[:navigate-back]]}))

View File

@ -29,17 +29,18 @@
:action :request
:params {:hide-actions? true}}]))
(views/defview qr-code []
(views/defview qr-code [amount]
(views/letsubs [account [:get-current-account]]
[components.qr-code/qr-code
{:value (eip67/generate-uri (:address account))
{:value (eip67/generate-uri (:address account) {:value amount})
:size 256}]))
(views/defview request-transaction []
;;Because input field is in the end of view we will scroll to the end on input focus event
(views/letsubs [amount-error [:get-in [:wallet/request-transaction :amount-error]]
(views/letsubs [amount [:get-in [:wallet/request-transaction :amount]]
amount-error [:get-in [:wallet/request-transaction :amount-error]]
request-enabled? [:wallet.request/request-enabled?]
scroll (atom nil)]
scroll (atom nil)]
[react/keyboard-avoiding-view wallet.styles/wallet-modal-container
[status-bar/status-bar {:type :wallet}]
[toolbar-view]
@ -48,7 +49,7 @@
[react/view components.styles/flex
[react/view styles/network-container
[react/view styles/qr-container
[qr-code]]]
[qr-code amount]]]
[react/view wallet.styles/choose-wallet-container
[components/choose-wallet]]
[react/view wallet.styles/amount-container