mirror of
https://github.com/status-im/status-mobile.git
synced 2025-02-10 23:56:48 +00:00
[BUG #2133] Correctly parse/generate amount from QR code
This commit is contained in:
parent
43dab5b174
commit
8393f19596
@ -10,30 +10,31 @@
|
|||||||
toggled-state (if (= :on flashlight-state) :off :on)]
|
toggled-state (if (= :on flashlight-state) :off :on)]
|
||||||
(assoc-in db [:wallet/send-transaction :camera-flashlight] toggled-state))))
|
(assoc-in db [:wallet/send-transaction :camera-flashlight] toggled-state))))
|
||||||
|
|
||||||
(defn choose-address-and-name [db address name]
|
(defn choose-address-and-name [db address name amount]
|
||||||
(update db :wallet/send-transaction assoc :to-address address :to-name name))
|
(update db :wallet/send-transaction assoc :to-address address :to-name name :amount amount))
|
||||||
|
|
||||||
(defn- extract-address [s]
|
(defn- extract-details
|
||||||
;; First try to parse as EIP67 URI, if not assume this is an address directly
|
"First try to parse as EIP67 URI, if not assume this is an address directly.
|
||||||
(if-let [m (eip67/parse-uri s)]
|
Returns a map containing at least the `address` key"
|
||||||
(:address m)
|
[s]
|
||||||
s))
|
(or (eip67/parse-uri s) {:address s}))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:choose-recipient
|
:choose-recipient
|
||||||
(fn [{{:keys [web3] :as db} :db} [_ data name]]
|
(fn [{{:keys [web3] :as db} :db} [_ data name]]
|
||||||
(let [{:keys [view-id]} db
|
(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'
|
;; isAddress works with or without address with leading '0x'
|
||||||
valid-address? (.isAddress web3 address)]
|
valid-address? (.isAddress web3 address)]
|
||||||
(cond-> {:db db}
|
(cond-> {:db db}
|
||||||
(= :choose-recipient view-id) (assoc :dispatch [:navigate-back])
|
(= :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}))))))
|
(not valid-address?) (assoc :show-error (i18n/label :t/wallet-invalid-address {:data data}))))))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:wallet-open-send-transaction
|
:wallet-open-send-transaction
|
||||||
(fn [{db :db} [_ address name]]
|
(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]
|
:dispatch-n [[:navigate-back]
|
||||||
[:navigate-back]]}))
|
[:navigate-back]]}))
|
@ -29,15 +29,16 @@
|
|||||||
:action :request
|
:action :request
|
||||||
:params {:hide-actions? true}}]))
|
:params {:hide-actions? true}}]))
|
||||||
|
|
||||||
(views/defview qr-code []
|
(views/defview qr-code [amount]
|
||||||
(views/letsubs [account [:get-current-account]]
|
(views/letsubs [account [:get-current-account]]
|
||||||
[components.qr-code/qr-code
|
[components.qr-code/qr-code
|
||||||
{:value (eip67/generate-uri (:address account))
|
{:value (eip67/generate-uri (:address account) {:value amount})
|
||||||
:size 256}]))
|
:size 256}]))
|
||||||
|
|
||||||
(views/defview request-transaction []
|
(views/defview request-transaction []
|
||||||
;;Because input field is in the end of view we will scroll to the end on input focus event
|
;;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?]
|
request-enabled? [:wallet.request/request-enabled?]
|
||||||
scroll (atom nil)]
|
scroll (atom nil)]
|
||||||
[react/keyboard-avoiding-view wallet.styles/wallet-modal-container
|
[react/keyboard-avoiding-view wallet.styles/wallet-modal-container
|
||||||
@ -48,7 +49,7 @@
|
|||||||
[react/view components.styles/flex
|
[react/view components.styles/flex
|
||||||
[react/view styles/network-container
|
[react/view styles/network-container
|
||||||
[react/view styles/qr-container
|
[react/view styles/qr-container
|
||||||
[qr-code]]]
|
[qr-code amount]]]
|
||||||
[react/view wallet.styles/choose-wallet-container
|
[react/view wallet.styles/choose-wallet-container
|
||||||
[components/choose-wallet]]
|
[components/choose-wallet]]
|
||||||
[react/view wallet.styles/amount-container
|
[react/view wallet.styles/amount-container
|
||||||
|
Loading…
x
Reference in New Issue
Block a user