[fix #5303] Improve amount validation for /send and /request commands

Signed-off-by: Dmitry Novotochinov <dmitry.novot@gmail.com>
This commit is contained in:
Dmitry Novotochinov 2018-08-29 15:29:56 +03:00
parent c25abecfc8
commit 19590c8e54
No known key found for this signature in database
GPG Key ID: 43D1DAF5AD39C927
2 changed files with 19 additions and 2 deletions

View File

@ -167,11 +167,13 @@
(let [sanitised-str (string/replace amount #"," ".")
portions (string/split sanitised-str ".")
decimals (count (get portions 1))
amount (js/parseFloat sanitised-str)]
amount-string (str amount)
amount (js/Number sanitised-str)]
(cond
(or (js/isNaN amount)
(> (count portions) 2))
(> (count portions) 2)
(re-matches #".+(\.|,)$" amount-string))
{:title "Amount"
:description "Amount is not valid number"}

View File

@ -57,6 +57,21 @@
(is (= (protocol/validate personal-request-command {:asset "SNT" :amount "a"} cofx)
{:title "Amount"
:description "Amount is not valid number"}))
(is (= (protocol/validate personal-request-command {:asset "ETH" :amount "0,1Aaa"} cofx)
{:title "Amount"
:description "Amount is not valid number"}))
(is (= (protocol/validate personal-request-command {:asset "ETH" :amount "1-45"} cofx)
{:title "Amount"
:description "Amount is not valid number"}))
(is (= (protocol/validate personal-request-command {:asset "SNT" :amount "1$#@8"} cofx)
{:title "Amount"
:description "Amount is not valid number"}))
(is (= (protocol/validate personal-request-command {:asset "SNT" :amount "20,"} cofx)
{:title "Amount"
:description "Amount is not valid number"}))
(is (= (protocol/validate personal-request-command {:asset "SNT" :amount "20."} cofx)
{:title "Amount"
:description "Amount is not valid number"}))
(is (= (protocol/validate personal-request-command {:asset "ETH" :amount "0.54354353454353453453454353453445345545"} cofx)
{:title "Amount"
:description "Max number of decimals is 18"}))