Fixed amount validation regression
This commit is contained in:
parent
1df074c100
commit
0a94d10559
|
@ -91,8 +91,8 @@
|
||||||
[components/button-text (i18n/label :t/transactions-sign-transaction)]
|
[components/button-text (i18n/label :t/transactions-sign-transaction)]
|
||||||
[vector-icons/icon :icons/forward {:color :white :container-style wallet.styles/forward-icon-container}]]]]))
|
[vector-icons/icon :icons/forward {:color :white :container-style wallet.styles/forward-icon-container}]]]]))
|
||||||
|
|
||||||
(defn- sufficient-funds? [amount-in-eth balance]
|
(defn sufficient-funds? [amount-in-eth balance]
|
||||||
(<= (money/str->float amount-in-eth) (money/wei->ether balance)))
|
(.greaterThanOrEqualTo balance (money/bignumber (money/to-wei amount-in-eth))))
|
||||||
|
|
||||||
(defn request-camera-permissions []
|
(defn request-camera-permissions []
|
||||||
(when platform/android?
|
(when platform/android?
|
||||||
|
@ -110,7 +110,7 @@
|
||||||
to-address [:get-in [:wallet/send-transaction :to-address]]
|
to-address [:get-in [:wallet/send-transaction :to-address]]
|
||||||
to-name [:get-in [:wallet/send-transaction :to-name]]
|
to-name [:get-in [:wallet/send-transaction :to-name]]
|
||||||
in-progress? [:get-in [:wallet/send-transaction :in-progress?]]]
|
in-progress? [:get-in [:wallet/send-transaction :in-progress?]]]
|
||||||
(let [sufficient-funds? (sufficient-funds? amount balance)]
|
(let [sufficient-funds? (or (nil? amount) (sufficient-funds? amount balance))]
|
||||||
[react/keyboard-avoiding-view wallet.styles/wallet-modal-container
|
[react/keyboard-avoiding-view wallet.styles/wallet-modal-container
|
||||||
[react/view components.styles/flex
|
[react/view components.styles/flex
|
||||||
[status-bar/status-bar {:type :wallet}]
|
[status-bar/status-bar {:type :wallet}]
|
||||||
|
|
|
@ -28,22 +28,27 @@
|
||||||
(string/replace (string/trim str) #"," ".")))
|
(string/replace (string/trim str) #"," ".")))
|
||||||
|
|
||||||
(defn bignumber [n]
|
(defn bignumber [n]
|
||||||
(dependencies/Web3.prototype.toBigNumber (str n)))
|
|
||||||
|
|
||||||
(defn str->float [str]
|
|
||||||
(when str
|
(when str
|
||||||
(.toNumber (bignumber (normalize str)))))
|
(try
|
||||||
|
(dependencies/Web3.prototype.toBigNumber (str n))
|
||||||
|
(catch :default err nil))))
|
||||||
|
|
||||||
(defn valid? [str]
|
(defn valid? [str]
|
||||||
(try (> (str->float str) 0)
|
(when str
|
||||||
(catch :default err false)))
|
(when-let [bn (bignumber (normalize str))]
|
||||||
|
(.greaterThanOrEqualTo bn 0))))
|
||||||
|
|
||||||
(defn to-wei [str]
|
(defn to-wei [str]
|
||||||
(dependencies/Web3.prototype.toWei str "ether"))
|
(when str
|
||||||
|
(try
|
||||||
|
(dependencies/Web3.prototype.toWei (normalize str) "ether")
|
||||||
|
(catch :default err nil))))
|
||||||
|
|
||||||
(defn to-decimal [value]
|
(defn to-decimal [str]
|
||||||
(dependencies/Web3.prototype.toDecimal value))
|
(when str
|
||||||
|
(try
|
||||||
|
(dependencies/Web3.prototype.toDecimal (normalize str))
|
||||||
|
(catch :default err nil))))
|
||||||
|
|
||||||
(def eth-units
|
(def eth-units
|
||||||
{:wei (bignumber "1")
|
{:wei (bignumber "1")
|
||||||
|
|
|
@ -11,22 +11,19 @@
|
||||||
"0.111122223333441239"))))
|
"0.111122223333441239"))))
|
||||||
|
|
||||||
(deftest valid?
|
(deftest valid?
|
||||||
(is (false? (money/valid? nil)))
|
(is (not (true? (money/valid? nil))))
|
||||||
(is (false? (money/valid? "a")))
|
(is (not (true? (money/valid? "a"))))
|
||||||
(is (false? (money/valid? "-1")))
|
(is (not (true? (money/valid? "-1"))))
|
||||||
(is (false? (money/valid? "1a")))
|
(is (not (true? (money/valid? "1a"))))
|
||||||
|
(is (not (true? (money/valid? "0,,"))))
|
||||||
(is (true? (money/valid? "1")))
|
(is (true? (money/valid? "1")))
|
||||||
(is (true? (money/valid? "1.1")))
|
(is (true? (money/valid? "1.1")))
|
||||||
(is (true? (money/valid? "1,1"))))
|
(is (true? (money/valid? "1,1")))
|
||||||
|
(is (true? (money/valid? "0.00000000000000000000001")))
|
||||||
|
(is (true? (money/valid? "0.0000000000000000000000000001"))))
|
||||||
|
|
||||||
(deftest normalize
|
(deftest normalize
|
||||||
(is (= nil (money/normalize nil)))
|
(is (= nil (money/normalize nil)))
|
||||||
(is (= "1" (money/normalize " 1 ")))
|
(is (= "1" (money/normalize " 1 ")))
|
||||||
(is (= "1.1" (money/normalize "1.1")))
|
(is (= "1.1" (money/normalize "1.1")))
|
||||||
(is (= "1.1" (money/normalize "1,1"))))
|
(is (= "1.1" (money/normalize "1,1"))))
|
||||||
|
|
||||||
(deftest str->float
|
|
||||||
(is (= nil (money/str->float nil)))
|
|
||||||
(is (= 1 (money/str->float " 1 ")))
|
|
||||||
(is (= 1.1 (money/str->float "1.1")))
|
|
||||||
(is (= 1.1 (money/str->float "1,1"))))
|
|
Loading…
Reference in New Issue