Skip to content

Commit 96b88a4

Browse files
[#20720] feat: add ability to set currency from account Settings (#20772)
* [#20720] feat: add ability to set currency from account Settings
1 parent cc6dcc3 commit 96b88a4

39 files changed

+620
-113
lines changed
1.79 KB
Loading
Loading
Loading
14.8 KB
Loading
28.5 KB
Loading
14.7 KB
Loading
28.5 KB
Loading

src/legacy/status_im/data_store/settings.cljs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns legacy.status-im.data-store.settings
22
(:require
33
[clojure.set :as set]
4+
[clojure.string :as string]
45
[legacy.status-im.data-store.visibility-status-updates :as visibility-status-updates]
56
[utils.ethereum.eip.eip55 :as eip55]))
67

@@ -18,6 +19,13 @@
1819
{}
1920
pinned-mailservers))
2021

22+
(defn rpc->currency
23+
[currency]
24+
(-> currency
25+
(name)
26+
(string/lower-case)
27+
(keyword)))
28+
2129
(defn rpc->settings
2230
[settings]
2331
(-> settings
@@ -26,13 +34,13 @@
2634
(update :wallet-legacy/visible-tokens rpc->visible-tokens)
2735
(update :pinned-mailservers rpc->pinned-mailservers)
2836
(update :link-previews-enabled-sites set)
29-
(update :currency keyword)
37+
(update :currency rpc->currency)
3038
(visibility-status-updates/<-rpc-settings)
3139
(set/rename-keys {:compressedKey :compressed-key
3240
:emojiHash :emoji-hash})))
3341

3442
(defn rpc->setting-value
3543
[{:keys [name] :as setting}]
3644
(condp = name
37-
:currency (update setting :value keyword)
45+
:currency (update setting :value rpc->currency)
3846
setting))

src/legacy/status_im/multiaccounts/update/core.cljs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns legacy.status-im.multiaccounts.update.core
22
(:require
3+
[legacy.status-im.data-store.settings :as settings]
34
[legacy.status-im.utils.deprecated-types :as types]
45
[status-im.constants :as constants]
56
[taoensso.timbre :as log]
@@ -81,7 +82,7 @@
8182
[{:keys [db] :as cofx} setting setting-value]
8283
(let [current-multiaccount (:profile/profile db)
8384
setting-value (if (= :currency setting)
84-
(keyword setting-value)
85+
(settings/rpc->currency setting-value)
8586
setting-value)
8687
db (case setting
8788
:stickers/packs-pending
@@ -104,7 +105,9 @@
104105
db)]
105106
{:db (if setting-value
106107
(assoc-in db [:profile/profile setting] setting-value)
107-
(update db :profile/profile dissoc setting))}))
108+
(update db :profile/profile dissoc setting))
109+
:fx [(when (= setting :currency)
110+
[:dispatch [:wallet/get-wallet-token-for-all-accounts]])]}))
108111

109112
(rf/defn set-many-js
110113
[cofx settings-js]

src/legacy/status_im/utils/currency.cljs

-84
This file was deleted.

src/quo/components/settings/settings_item/view.cljs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
[quo.components.settings.settings-item.style :as style]
1111
[quo.components.tags.context-tag.view :as context-tag]
1212
[quo.components.tags.status-tags :as status-tags]
13+
[quo.components.utilities.token.view :as token]
1314
[quo.foundations.colors :as colors]
1415
[quo.theme :as quo.theme]
1516
[react-native.core :as rn]
@@ -59,6 +60,7 @@
5960
:icon [icon/icon image-props (style/color blur? theme)]
6061
:avatar [user-avatar/user-avatar image-props]
6162
:icon-avatar [icon-avatar/icon-avatar image-props]
63+
:token [token/view image-props]
6264
nil)]))
6365

6466
(defn tag-component

src/status_im/common/json_rpc/events.cljs

+8
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,11 @@
9494
(fn [params]
9595
(doseq [param params]
9696
(call param))))
97+
98+
(defn log-rpc-error
99+
[_ [{:keys [event params]} error]]
100+
(log/error (str "Failed to " event)
101+
{:params params
102+
:error error}))
103+
104+
(rf/reg-event-fx :log-rpc-error log-rpc-error)

src/status_im/common/resources.cljs

+4-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@
9090
:dark (js/require "../resources/images/ui2/sweating-man-dark.png")}
9191
:no-pinned-messages
9292
{:light (js/require "../resources/images/ui2/no-pinned-messages-light.png")
93-
:dark (js/require "../resources/images/ui2/no-pinned-messages-dark.png")}})
93+
:dark (js/require "../resources/images/ui2/no-pinned-messages-dark.png")}
94+
:no-assets
95+
{:light (js/require "../resources/images/ui2/no-assets-light.png")
96+
:dark (js/require "../resources/images/ui2/no-assets-dark.png")}})
9497

9598
(def mock-images
9699
{:bored-ape (js/require "../resources/images/mock2/bored-ape.png")

src/status_im/constants.cljs

+2
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@
586586

587587
(def ^:const contact-item-height 56)
588588

589+
(def ^:const currency-item-height 64)
590+
589591
(def ^:const slippages [0.1 0.5 1])
590592
(def ^:const default-slippage 0.5)
591593
(def ^:const max-recommended-slippage 5)

src/status_im/contexts/profile/login/events.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
[:dispatch-later [{:ms 1500 :dispatch [:profile.login/non-critical-initialization]}]]
9696
[:dispatch [:network/check-expensive-connection]]
9797
[:profile.settings/get-profile-picture key-uid]
98+
[:settings/get-currencies]
9899
(when (ff/enabled? ::ff/wallet.wallet-connect)
99100
[:dispatch [:wallet-connect/init]])
100101
(when notifications-enabled?

src/status_im/contexts/profile/settings/events.cljs

+5
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,8 @@
151151
[{:method "settings_mnemonicWasShown"
152152
:on-success #(log/debug "mnemonic was marked as shown")
153153
:on-error #(log/error "mnemonic was not marked as shown" %)}]]]}))
154+
155+
(rf/reg-event-fx :profile.settings/update-currency
156+
(fn [_ [currency]]
157+
{:fx [[:dispatch [:profile.settings/profile-update :currency currency]]
158+
[:dispatch [:wallet/get-wallet-token-for-all-accounts]]]}))

src/status_im/contexts/profile/settings/list_items.cljs

+6-7
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,12 @@
8585
:image :icon
8686
:blur? true
8787
:action :arrow}
88-
(when config/show-not-implemented-features?
89-
{:title (i18n/label :t/language-and-currency)
90-
:on-press not-implemented/alert
91-
:image-props :i/globe
92-
:image :icon
93-
:blur? true
94-
:action :arrow})]
88+
{:title (i18n/label :t/language-and-currency)
89+
:on-press #(rf/dispatch [:open-modal :screen/settings.language-and-currency])
90+
:image-props :i/globe
91+
:image :icon
92+
:blur? true
93+
:action :arrow}]
9594
[(when config/show-not-implemented-features?
9695
{:title (i18n/label :t/data-usage)
9796
:on-press not-implemented/alert
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(ns status-im.contexts.settings.language-and-currency.currency.style)
2+
3+
(def input-container
4+
{:padding-horizontal 20
5+
:padding-vertical 8})
6+
7+
(def empty-results
8+
{:margin-top 100})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(ns status-im.contexts.settings.language-and-currency.currency.utils
2+
(:require [status-im.constants :as constants]))
3+
4+
(defn make-currency-item
5+
"This function generates props for quo/category component item"
6+
[{:keys [currency selected-currency on-change]}]
7+
{:title (if (:token? currency)
8+
(:short-name currency)
9+
(str (:short-name currency) " · " (:symbol currency)))
10+
:description :text
11+
:description-props {:text (:name currency)}
12+
:container-style {:height constants/currency-item-height}
13+
:image (when (:token? currency) :token)
14+
:image-props {:token (:id currency)
15+
:size :size-20}
16+
:action :selector
17+
:action-props {:type :radio
18+
:blur? true
19+
:checked? (= selected-currency (:id currency))
20+
:on-change #(on-change (:id currency))}})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
(ns status-im.contexts.settings.language-and-currency.currency.view
2+
(:require [quo.core :as quo]
3+
[react-native.core :as rn]
4+
[status-im.common.resources :as resources]
5+
[status-im.constants :as constants]
6+
[status-im.contexts.settings.language-and-currency.currency.style :as style]
7+
[status-im.contexts.settings.language-and-currency.currency.utils :as utils]
8+
[status-im.contexts.settings.language-and-currency.data-store :as data-store]
9+
[utils.debounce :as debounce]
10+
[utils.i18n :as i18n]
11+
[utils.re-frame :as rf]))
12+
13+
(defn- navigate-back
14+
[]
15+
(rf/dispatch [:navigate-back]))
16+
17+
(defn- get-item-layout
18+
[_ index]
19+
#js {:length constants/currency-item-height
20+
:offset (* constants/currency-item-height index)
21+
:index index})
22+
23+
(defn- settings-category-view
24+
[{:keys [title data]} _ _ {:keys [selected-currency on-currency-press]}]
25+
[rn/delay-render
26+
[quo/category
27+
{:label title
28+
:data (map (fn [currency]
29+
(utils/make-currency-item
30+
{:currency currency
31+
:selected-currency selected-currency
32+
:on-change on-currency-press}))
33+
data)
34+
:blur? true
35+
:list-type :settings}]])
36+
37+
(defn view
38+
[]
39+
(let [[search-text set-search-text] (rn/use-state "")
40+
on-currency-press (rn/use-callback #(rf/dispatch [:profile.settings/update-currency
41+
%]))
42+
selected-currency (rf/sub [:profile/currency])
43+
currencies (rf/sub [:currencies/categorized search-text])
44+
on-change-text (rn/use-callback
45+
(debounce/debounce
46+
#(set-search-text %)
47+
300))
48+
formatted-data (rn/use-memo
49+
#(data-store/get-formatted-currency-data currencies)
50+
[search-text currencies])]
51+
[quo/overlay
52+
{:type :shell
53+
:top-inset? true}
54+
[quo/page-nav
55+
{:background :blur
56+
:icon-name :i/arrow-left
57+
:on-press navigate-back}]
58+
[quo/page-top
59+
{:title (i18n/label :t/currency)}]
60+
[quo/input
61+
{:small? true
62+
:blur? true
63+
:container-style style/input-container
64+
:placeholder (i18n/label :t/search-currencies)
65+
:icon-name :i/search
66+
:on-change-text on-change-text}]
67+
(when (zero? (:total currencies))
68+
[quo/empty-state
69+
{:title (i18n/label :t/no-result)
70+
:image (resources/get-themed-image :no-assets :dark)
71+
:container-style style/empty-results
72+
:description (i18n/label :t/try-with-different-currency)}])
73+
[rn/flat-list
74+
{:data formatted-data
75+
:render-data {:selected-currency selected-currency
76+
:on-currency-press on-currency-press}
77+
:render-fn settings-category-view
78+
:get-item-layout get-item-layout
79+
:initial-num-to-render 14
80+
:max-to-render-per-batch 20
81+
:scroll-event-throttle 16
82+
:shows-vertical-scroll-indicator false
83+
:bounces false
84+
:over-scroll-mode :never}]]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(ns status-im.contexts.settings.language-and-currency.data-store
2+
(:require [clojure.set :as set]
3+
[utils.i18n :as i18n]))
4+
5+
(defn rpc->currency
6+
[currency]
7+
(some-> currency
8+
(dissoc :unicode)
9+
(set/rename-keys
10+
{:shortName :short-name
11+
:isPopular :popular?
12+
:isToken :token?})
13+
(update :id keyword)))
14+
15+
(defn rpc->currencies
16+
[currencies]
17+
(map rpc->currency currencies))
18+
19+
(defn get-formatted-currency-data
20+
[{:keys [popular crypto other]}]
21+
(concat
22+
(when (seq popular)
23+
[{:title (i18n/label :t/popular-currencies)
24+
:data popular}])
25+
(when (seq crypto)
26+
[{:title (i18n/label :t/crypto)
27+
:data crypto}])
28+
(when (seq other)
29+
[{:title (i18n/label :t/all-currencies)
30+
:data other}])))

0 commit comments

Comments
 (0)