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

View File

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