diff --git a/src/status_im/contexts/wallet/send/utils.cljs b/src/status_im/contexts/wallet/send/utils.cljs index 0b49832b94f2..c54900b342f5 100644 --- a/src/status_im/contexts/wallet/send/utils.cljs +++ b/src/status_im/contexts/wallet/send/utils.cljs @@ -32,6 +32,8 @@ (let [amount-hex (if to? (:amount-in path) (:amount-out path)) amount-units (native-module/hex-to-number (utils.hex/normalize-hex amount-hex)) + ;; 2000000000000000000 + ; 2000000000000 amount (money/with-precision (if native-token? (money/wei->ether amount-units) diff --git a/src/status_im/contexts/wallet/send/utils_test.cljs b/src/status_im/contexts/wallet/send/utils_test.cljs index 96c37b27567b..741d8c6b7449 100644 --- a/src/status_im/contexts/wallet/send/utils_test.cljs +++ b/src/status_im/contexts/wallet/send/utils_test.cljs @@ -31,8 +31,10 @@ (deftest test-network-amounts (testing "Correctly calculates network amounts for transaction with native token" - (let [route [{:amount-in "0xde0b6b3a7640000" :to {:chain-id "1"}} - {:amount-in "0xde0b6b3a7640000" :to {:chain-id "2"}}] + (let [route [{:amount-in "0xde0b6b3a7640000" + :to {:chain-id "1"}} + {:amount-in "0xde0b6b3a7640000" + :to {:chain-id "2"}}] token-decimals 18 native-token? true to? true @@ -40,13 +42,16 @@ :token-decimals token-decimals :native-token? native-token? :to? to?}) - expected {"1" (money/bignumber "1") "2" (money/bignumber "1")}] + expected {"1" (money/bignumber "1") + "2" (money/bignumber "1")}] (doseq [[chain-id exp-value] expected] (is (money/equal-to (get result chain-id) exp-value))))) (testing "Correctly calculates network amounts for transaction with non-native token" - (let [route [{:amount-out "0x1bc16d674ec80000" :from {:chain-id "1"}} - {:amount-out "0x1bc16d674ec80000" :from {:chain-id "2"}}] + (let [route [{:amount-out "0x1e8480" + :from {:chain-id "1"}} + {:amount-out "0x1e8480" + :from {:chain-id "2"}}] token-decimals 6 native-token? false to? false @@ -54,7 +59,8 @@ :token-decimals token-decimals :native-token? native-token? :to? to?}) - expected {"1" (money/bignumber "2") "2" (money/bignumber "2")}] + expected {"1" (money/bignumber "2") + "2" (money/bignumber "2")}] (doseq [[chain-id exp-value] expected] (is (money/equal-to (get result chain-id) exp-value)))))) @@ -73,10 +79,13 @@ (deftest test-network-values-sanitized (testing "Sanitizes values correctly for display" - (let [amounts {"1" (money/bignumber "0.0000001") + (let [amounts {"1" (money/bignumber "0") "2" (money/bignumber "2.5") "3" (money/bignumber "0.005")} result (utils/network-values-sanitized amounts) - expected {"1" "<0.01" "2" "2.5" "3" "<0.01"}] + expected {"1" "<0.01" + "2" (money/bignumber "2.5") + "3" (money/bignumber "0.005")}] (doseq [[chain-id exp-value] expected] - (is (= (get result chain-id) exp-value)))))) + (is #(or (= (get result chain-id) exp-value) + (money/equal-to (get result chain-id) exp-value)))))))