mirror of
https://github.com/status-im/status-mobile.git
synced 2025-01-13 10:16:01 +00:00
[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 #"," ".")
|
||||
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"}
|
||||
|
||||
|
@ -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"}))
|
||||
|
Loading…
x
Reference in New Issue
Block a user