Fixes #4099: Localize currency according to selected currency

Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
pacamara 2018-05-15 00:04:02 +01:00 committed by Julien Eluard
parent 225d2e2ec0
commit 53349ef31f
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
3 changed files with 81 additions and 5 deletions

View File

@ -387,3 +387,75 @@
(or (translation locale)
(translation (subs locale 0 2))
fallback)))
(defn format-currency [value currency-code]
(.addTier2Support goog.i18n.currency)
(def currency-code-to-nfs-map
{"ZAR" (.-NumberFormatSymbols_af goog.i18n)
"ETB" (.-NumberFormatSymbols_am goog.i18n)
"EGP" (.-NumberFormatSymbols_ar goog.i18n)
"DZD" (.-NumberFormatSymbols_ar_DZ goog.i18n)
"AZN" (.-NumberFormatSymbols_az goog.i18n)
"BYN" (.-NumberFormatSymbols_be goog.i18n)
"BGN" (.-NumberFormatSymbols_bg goog.i18n)
"BDT" (.-NumberFormatSymbols_bn goog.i18n)
"EUR" (.-NumberFormatSymbols_br goog.i18n)
"BAM" (.-NumberFormatSymbols_bs goog.i18n)
"USD" (.-NumberFormatSymbols_en goog.i18n)
"CZK" (.-NumberFormatSymbols_cs goog.i18n)
"GBP" (.-NumberFormatSymbols_cy goog.i18n)
"DKK" (.-NumberFormatSymbols_da goog.i18n)
"CHF" (.-NumberFormatSymbols_de_CH goog.i18n)
"AUD" (.-NumberFormatSymbols_en_AU goog.i18n)
"CAD" (.-NumberFormatSymbols_en_CA goog.i18n)
"INR" (.-NumberFormatSymbols_en_IN goog.i18n)
"SGD" (.-NumberFormatSymbols_en_SG goog.i18n)
"MXN" (.-NumberFormatSymbols_es_419 goog.i18n)
"IRR" (.-NumberFormatSymbols_fa goog.i18n)
"PHP" (.-NumberFormatSymbols_fil goog.i18n)
"ILS" (.-NumberFormatSymbols_he goog.i18n)
"HRK" (.-NumberFormatSymbols_hr goog.i18n)
"HUF" (.-NumberFormatSymbols_hu goog.i18n)
"AMD" (.-NumberFormatSymbols_hy goog.i18n)
"IDR" (.-NumberFormatSymbols_id goog.i18n)
"ISK" (.-NumberFormatSymbols_is goog.i18n)
"JPY" (.-NumberFormatSymbols_ja goog.i18n)
"GEL" (.-NumberFormatSymbols_ka goog.i18n)
"KZT" (.-NumberFormatSymbols_kk goog.i18n)
"KHR" (.-NumberFormatSymbols_km goog.i18n)
"KRW" (.-NumberFormatSymbols_ko goog.i18n)
"KGS" (.-NumberFormatSymbols_ky goog.i18n)
"CDF" (.-NumberFormatSymbols_ln goog.i18n)
"LAK" (.-NumberFormatSymbols_lo goog.i18n)
"MKD" (.-NumberFormatSymbols_mk goog.i18n)
"MNT" (.-NumberFormatSymbols_mn goog.i18n)
"MDL" (.-NumberFormatSymbols_mo goog.i18n)
"MYR" (.-NumberFormatSymbols_ms goog.i18n)
"MMK" (.-NumberFormatSymbols_my goog.i18n)
"NOK" (.-NumberFormatSymbols_nb goog.i18n)
"NPR" (.-NumberFormatSymbols_ne goog.i18n)
"PLN" (.-NumberFormatSymbols_pl goog.i18n)
"BRL" (.-NumberFormatSymbols_pt goog.i18n)
"RON" (.-NumberFormatSymbols_ro goog.i18n)
"RUB" (.-NumberFormatSymbols_ru goog.i18n)
"RSD" (.-NumberFormatSymbols_sh goog.i18n)
"LKR" (.-NumberFormatSymbols_si goog.i18n)
"ALL" (.-NumberFormatSymbols_sq goog.i18n)
"SEK" (.-NumberFormatSymbols_sv goog.i18n)
"TZS" (.-NumberFormatSymbols_sw goog.i18n)
"THB" (.-NumberFormatSymbols_th goog.i18n)
"TRY" (.-NumberFormatSymbols_tr goog.i18n)
"UAH" (.-NumberFormatSymbols_uk goog.i18n)
"PKR" (.-NumberFormatSymbols_ur goog.i18n)
"UZS" (.-NumberFormatSymbols_uz goog.i18n)
"VND" (.-NumberFormatSymbols_vi goog.i18n)
"CNY" (.-NumberFormatSymbols_zh goog.i18n)
"HKD" (.-NumberFormatSymbols_zh_HK goog.i18n)
"TWD" (.-NumberFormatSymbols_zh_TW goog.i18n)})
(def custom-nfs (currency-code-to-nfs-map currency-code))
(set! (.-NumberFormatSymbols goog.i18n) (if custom-nfs custom-nfs (.-NumberFormatSymbols_en goog.i18n)))
(.format
(new goog.i18n.NumberFormat (.-CURRENCY goog.i18n.NumberFormat.Format) currency-code)
value))

View File

@ -1,6 +1,7 @@
(ns status-im.ui.screens.wallet.subs
(:require [re-frame.core :as re-frame]
[status-im.constants :as constants]
[status-im.i18n :as i18n]
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.ethereum.tokens :as tokens]
[status-im.utils.money :as money]))
@ -31,13 +32,15 @@
(re-frame/reg-sub :asset-value
(fn [[_ fsym tsym]]
[(re-frame/subscribe [:balance])
(re-frame/subscribe [:price fsym tsym])])
(fn [[balance price] [_ fsym tsym]]
(re-frame/subscribe [:price fsym tsym])
(re-frame/subscribe [:wallet/currency])])
(fn [[balance price currency] [_ fsym tsym]]
(when (and balance price)
(-> (money/wei->ether (get balance fsym))
(money/eth->fiat price)
(money/with-precision 2)
str))))
str
(i18n/format-currency (:code currency))))))
(defn- get-balance-total-value [balance prices currency]
(->> balance
@ -61,7 +64,8 @@
(-> currency :code keyword)))]
(-> balance-total-value
(money/with-precision 2)
str))
str
(i18n/format-currency (:code currency))))
"...")))
(re-frame/reg-sub :prices-loading?

View File

@ -68,7 +68,7 @@
[react/text {:style styles/asset-item-price
:uppercase? true
:number-of-lines 1}
(if @asset-value (str (:symbol currency) @asset-value) "...")]]])))
(if @asset-value @asset-value "...")]]])))
(defn- asset-section [assets currency]
[react/view styles/asset-section