diff --git a/src/status_im/contexts/wallet/common/utils.cljs b/src/status_im/contexts/wallet/common/utils.cljs index ad6ff9d89d..f4bab8cb03 100644 --- a/src/status_im/contexts/wallet/common/utils.cljs +++ b/src/status_im/contexts/wallet/common/utils.cljs @@ -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 diff --git a/src/utils/money.cljs b/src/utils/money.cljs index 58bf4ace81..843cf2e3b9 100644 --- a/src/utils/money.cljs +++ b/src/utils/money.cljs @@ -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)) diff --git a/src/utils/money_test.cljs b/src/utils/money_test.cljs index 93ab5eb9f2..556db66ce3 100644 --- a/src/utils/money_test.cljs +++ b/src/utils/money_test.cljs @@ -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"))))