Checking transaction recepient validity (#780)

This commit is contained in:
alwx 2017-03-10 18:20:05 +03:00 committed by Roman Volosovskyi
parent e2f31aae00
commit 947dcfba37
2 changed files with 15 additions and 7 deletions

View File

@ -4,6 +4,7 @@
[status-im.navigation.handlers :as nav]
[status-im.utils.handlers :as u]
[status-im.utils.types :as t]
[status-im.utils.hex :refer [valid-hex?]]
[status-im.components.status :as status]
[clojure.string :as s]
[taoensso.timbre :as log]))
@ -120,13 +121,15 @@
(register-handler ::transaction-queued
(after #(dispatch [:navigate-to-modal :confirm]))
(fn [db [_ {:keys [id message_id args]}]]
(let [{:keys [from to value]} args
transaction {:id id
(let [{:keys [from to value]} args]
(if (valid-hex? to)
(let [transaction {:id id
:from from
:to to
:value (.toDecimal js/Web3.prototype value)
:message-id message_id}]
(assoc-in db [:transactions-queue id] transaction))))
(assoc-in db [:transactions-queue id] transaction))
db))))
(register-handler :transaction-completed
(u/side-effect!

View File

@ -5,3 +5,8 @@
(if (and hex (s/starts-with? hex "0x"))
(subs hex 2)
hex))
(defn valid-hex? [hex]
(let [hex (normalize-hex hex)]
(and (re-matches #"^[0-9a-fA-F]+$" hex)
(not= (js/parseInt hex 16) 0))))