fix: approval of amounts with big decimals (#21326)
Signed-off-by: Brian Sztamfater <brian@status.im>
This commit is contained in:
parent
0cbb6819b4
commit
9c73d9d03c
|
@ -391,7 +391,7 @@
|
|||
approval-amount-required (:approval-amount-required route)
|
||||
approval-amount-required-sanitized (-> approval-amount-required
|
||||
(utils.hex/normalize-hex)
|
||||
(native-module/hex-to-number))
|
||||
(money/from-hex))
|
||||
approval-contract-address (:approval-contract-address route)
|
||||
data (native-module/encode-function-call
|
||||
constants/contract-function-signature-erc20-approve
|
||||
|
|
|
@ -151,6 +151,12 @@
|
|||
[^js bn]
|
||||
(str "0x" (to-string bn 16)))
|
||||
|
||||
(defn from-hex
|
||||
[hex-str]
|
||||
(try
|
||||
(new BigNumber hex-str 16)
|
||||
(catch :default _ nil)))
|
||||
|
||||
(defn wei->str
|
||||
([unit n display-unit]
|
||||
(str (to-fixed (wei-> unit n)) " " display-unit))
|
||||
|
|
|
@ -83,3 +83,10 @@
|
|||
1000001 "1M"
|
||||
10000000 "10M"
|
||||
100000000 "100M"))
|
||||
|
||||
(deftest from-hex-test
|
||||
(is (= (money/bignumber "2840425681744351250") (money/from-hex "276b381bbb44d012")))
|
||||
(is (= (money/bignumber "0") (money/from-hex "0")))
|
||||
(is (= (money/bignumber "255") (money/from-hex "ff")))
|
||||
(is (= (money/bignumber "4294967295") (money/from-hex "ffffffff")))
|
||||
(is (= (money/bignumber "12345678901234567890") (money/from-hex "ab54a98ceb1f0ad2"))))
|
||||
|
|
Loading…
Reference in New Issue