diff --git a/src/status_im/contexts/wallet/common/utils.cljs b/src/status_im/contexts/wallet/common/utils.cljs index 65f3844f65..318e742a4d 100644 --- a/src/status_im/contexts/wallet/common/utils.cljs +++ b/src/status_im/contexts/wallet/common/utils.cljs @@ -7,6 +7,7 @@ [utils.number :as number] [utils.string])) +(def missing-price-decimals 6) ; if we don't have the monetary value of the token, we default to 6 decimals (defn get-first-name [full-name] (first (string/split full-name #" "))) @@ -66,16 +67,20 @@ (defn get-standard-crypto-format "For full details: https://github.com/status-im/status-mobile/issues/18225" [{:keys [market-values-per-currency]} token-units] - (if (or (nil? token-units) - (nil? market-values-per-currency) - (money/equal-to token-units 0)) - "0" - (let [price (-> market-values-per-currency :usd :price) - one-cent-value (if (pos? price) (/ 0.01 price) 0) - decimals-count (calc-max-crypto-decimals one-cent-value)] - (if (< token-units one-cent-value) - (str "<" (number/remove-trailing-zeroes (.toFixed one-cent-value decimals-count))) - (number/remove-trailing-zeroes (.toFixed token-units decimals-count)))))) + (cond (or (nil? token-units) + (money/equal-to token-units 0)) + "0" + + (nil? (-> market-values-per-currency :usd :price)) + (number/remove-trailing-zeroes (.toFixed token-units missing-price-decimals)) + + :else + (let [price (-> market-values-per-currency :usd :price) + one-cent-value (if (pos? price) (/ 0.01 price) 0) + decimals-count (calc-max-crypto-decimals one-cent-value)] + (if (< token-units one-cent-value) + (str "<" (number/remove-trailing-zeroes (.toFixed one-cent-value decimals-count))) + (number/remove-trailing-zeroes (.toFixed token-units decimals-count)))))) (defn get-market-value [currency {:keys [market-values-per-currency]}] diff --git a/src/status_im/contexts/wallet/common/utils_test.cljs b/src/status_im/contexts/wallet/common/utils_test.cljs index f72f9bbb37..d4e9674f89 100644 --- a/src/status_im/contexts/wallet/common/utils_test.cljs +++ b/src/status_im/contexts/wallet/common/utils_test.cljs @@ -64,6 +64,11 @@ (is (= (utils/get-standard-crypto-format {:market-values-per-currency market-values-per-currency} token-units) "0.005"))) + (let [market-values-per-currency {:usd {:price nil}} + token-units (money/bignumber 0.0123456)] + (is (= (utils/get-standard-crypto-format {:market-values-per-currency market-values-per-currency} + token-units) + "0.012346"))) (let [market-values-per-currency {:usd {:price 0.005}} token-units (money/bignumber 0.01)] (is (= (utils/get-standard-crypto-format {:market-values-per-currency market-values-per-currency} diff --git a/status-go-version.json b/status-go-version.json index 6e10dcc828..1b9df8afd8 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v0.184.45", - "commit-sha1": "9cdfd6fb42da23b0d5cae6e15548c26179c971ec", - "src-sha256": "0lsjzq20mg248l9ksa1fa59yq08npygrh0ak32khdi9s60bh1x94" + "version": "v0.184.46", + "commit-sha1": "9e7d13039e50eeb815e7fa7082080d2ec5c81493", + "src-sha256": "02f8s7bfq8wavdkqg4wpraan4j3vi1p8h1r22ngzp9nxfwjif8xr" }