[fix #5303] Improve amount validation for /send and /request commands
Signed-off-by: Dmitry Novotochinov <dmitry.novot@gmail.com>
This commit is contained in:
parent
c25abecfc8
commit
19590c8e54
|
@ -167,11 +167,13 @@
|
||||||
(let [sanitised-str (string/replace amount #"," ".")
|
(let [sanitised-str (string/replace amount #"," ".")
|
||||||
portions (string/split sanitised-str ".")
|
portions (string/split sanitised-str ".")
|
||||||
decimals (count (get portions 1))
|
decimals (count (get portions 1))
|
||||||
amount (js/parseFloat sanitised-str)]
|
amount-string (str amount)
|
||||||
|
amount (js/Number sanitised-str)]
|
||||||
(cond
|
(cond
|
||||||
|
|
||||||
(or (js/isNaN amount)
|
(or (js/isNaN amount)
|
||||||
(> (count portions) 2))
|
(> (count portions) 2)
|
||||||
|
(re-matches #".+(\.|,)$" amount-string))
|
||||||
{:title "Amount"
|
{:title "Amount"
|
||||||
:description "Amount is not valid number"}
|
:description "Amount is not valid number"}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,21 @@
|
||||||
(is (= (protocol/validate personal-request-command {:asset "SNT" :amount "a"} cofx)
|
(is (= (protocol/validate personal-request-command {:asset "SNT" :amount "a"} cofx)
|
||||||
{:title "Amount"
|
{:title "Amount"
|
||||||
:description "Amount is not valid number"}))
|
: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)
|
(is (= (protocol/validate personal-request-command {:asset "ETH" :amount "0.54354353454353453453454353453445345545"} cofx)
|
||||||
{:title "Amount"
|
{:title "Amount"
|
||||||
:description "Max number of decimals is 18"}))
|
:description "Max number of decimals is 18"}))
|
||||||
|
|
Loading…
Reference in New Issue