bug #5542 - fixed errors when no currency selected - using usd as default throughout the app

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Goran Jovic 2018-08-28 16:03:32 +02:00 committed by Andrey Shovkoplyas
parent c96bc5aa8b
commit c35a651f15
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
7 changed files with 41 additions and 15 deletions

View File

@ -21,6 +21,7 @@
[status-im.utils.money :as money] [status-im.utils.money :as money]
[status-im.ui.screens.wallet.db :as wallet.db] [status-im.ui.screens.wallet.db :as wallet.db]
[status-im.ui.screens.wallet.choose-recipient.events :as choose-recipient.events] [status-im.ui.screens.wallet.choose-recipient.events :as choose-recipient.events]
[status-im.ui.screens.currency-settings.subs :as currency-settings.subs]
[status-im.models.transactions :as wallet.transactions] [status-im.models.transactions :as wallet.transactions]
[status-im.ui.screens.navigation :as navigation])) [status-im.ui.screens.navigation :as navigation]))
@ -228,7 +229,7 @@
(defn- inject-network-price-info [{:keys [amount asset] :as parameters} {:keys [db]}] (defn- inject-network-price-info [{:keys [amount asset] :as parameters} {:keys [db]}]
(let [{:keys [chain prices]} db (let [{:keys [chain prices]} db
currency (-> db currency (-> db
(get-in [:account/account :settings :wallet :currency] :usd) currency-settings.subs/get-currency
name name
string/upper-case)] string/upper-case)]
(assoc parameters (assoc parameters

View File

@ -18,7 +18,6 @@
[status-im.transport.message.v1.protocol :as protocol] [status-im.transport.message.v1.protocol :as protocol]
[status-im.data-store.messages :as messages-store] [status-im.data-store.messages :as messages-store]
[status-im.data-store.user-statuses :as user-statuses-store] [status-im.data-store.user-statuses :as user-statuses-store]
[status-im.ui.screens.currency-settings.subs :as currency-settings]
[status-im.utils.datetime :as datetime] [status-im.utils.datetime :as datetime]
[clojure.string :as string])) [clojure.string :as string]))

View File

@ -1,14 +1,8 @@
(ns status-im.ui.screens.currency-settings.events (ns status-im.ui.screens.currency-settings.events
(:require [status-im.models.wallet :as wallet] (:require [status-im.ui.screens.currency-settings.models :as models]
[status-im.ui.screens.accounts.models :as accounts.models] [status-im.utils.handlers :as handlers]))
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.settings/set-currency :wallet.settings/set-currency
(fn [{:keys [db] :as cofx} [_ currency]] (fn [cofx [_ currency]]
(let [settings (get-in db [:account/account :settings]) (models/set-currency currency cofx)))
new-settings (assoc-in settings [:wallet :currency] currency)]
(handlers-macro/merge-fx cofx
(accounts.models/update-settings new-settings)
(wallet/update-wallet)))))

View File

@ -0,0 +1,11 @@
(ns status-im.ui.screens.currency-settings.models
(:require [status-im.ui.screens.accounts.models :as accounts.models]
[status-im.models.wallet :as wallet]
[status-im.utils.handlers-macro :as handlers-macro]))
(defn set-currency [currency {:keys [db] :as cofx}]
(let [settings (get-in db [:account/account :settings])
new-settings (assoc-in settings [:wallet :currency] currency)]
(handlers-macro/merge-fx cofx
(accounts.models/update-settings new-settings)
(wallet/update-wallet))))

View File

@ -1,10 +1,12 @@
(ns status-im.ui.screens.currency-settings.subs (ns status-im.ui.screens.currency-settings.subs
(:require [re-frame.core :as re-frame])) (:require [re-frame.core :as re-frame]))
(defn get-user-currency [db] ;;TODO(goranjovic): this fn should go to `status-im.ui.screens.currency-settings.subs`
(get-in db [:account/account :settings :wallet :currency] :usd)) ;; but it can't because of cyclic dependencies
(defn get-currency [db]
(or (get-in db [:account/account :settings :wallet :currency]) :usd))
(re-frame/reg-sub (re-frame/reg-sub
:wallet.settings/currency :wallet.settings/currency
(fn [db] (fn [db]
(get-user-currency db))) (get-currency db)))

View File

@ -50,6 +50,7 @@
[status-im.test.init.core] [status-im.test.init.core]
[status-im.test.ui.screens.accounts.login.models] [status-im.test.ui.screens.accounts.login.models]
[status-im.test.ui.screens.accounts.recover.models] [status-im.test.ui.screens.accounts.recover.models]
[status-im.test.ui.screens.currency-settings.models]
[status-im.test.ui.screens.wallet.db])) [status-im.test.ui.screens.wallet.db]))
(enable-console-print!) (enable-console-print!)
@ -110,5 +111,6 @@
'status-im.test.utils.http 'status-im.test.utils.http
'status-im.test.ui.screens.accounts.login.models 'status-im.test.ui.screens.accounts.login.models
'status-im.test.ui.screens.accounts.recover.models 'status-im.test.ui.screens.accounts.recover.models
'status-im.test.ui.screens.currency-settings.models
'status-im.test.ui.screens.wallet.db 'status-im.test.ui.screens.wallet.db
'status-im.test.browser.events) 'status-im.test.browser.events)

View File

@ -0,0 +1,17 @@
(ns status-im.test.ui.screens.currency-settings.models
(:require [cljs.test :refer-macros [deftest is testing]]
[status-im.ui.screens.currency-settings.subs :as subs]
[status-im.ui.screens.currency-settings.models :as models]))
(deftest get-currency
(is (= :usd (subs/get-currency {:account/account {:settings {:wallet {:currency :usd}}}})))
(is (= :usd (subs/get-currency {:account/account {:settings {:wallet {:currency nil}}}})))
(is (= :usd (subs/get-currency {:account/account {:settings {:wallet {}}}})))
(is (= :aud (subs/get-currency {:account/account {:settings {:wallet {:currency :aud}}}}))))
(deftest set-currency
(let [cofx (models/set-currency :usd {:db {:account/account {:settings {:wallet {}}}}})]
(is (= [:db :get-balance :get-tokens-balance :get-prices :data-store/base-tx] (keys cofx)))
(is (= :usd (get-in cofx [:db :account/account :settings :wallet :currency]))))
(is (= :jpy (get-in (models/set-currency :jpy {:db {:account/account {:settings {:wallet {}}}}})
[:db :account/account :settings :wallet :currency]))))