Skip to content

Commit

Permalink
some polishing and improvements on network preferences bottom sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
briansztamfater committed May 8, 2024
1 parent 62f7feb commit 6a09720
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/status_im/contexts/wallet/common/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@

(defn make-network-item
"This function generates props for quo/category component item"
[{:keys [network-name color on-change networks state label-props]}]
[{:keys [network-name color on-change networks state label-props normal-checkbox?]}]
(cond-> {:title (string/capitalize (name network-name))
:image :icon-avatar
:image-props {:icon (resources/get-network network-name)
:size :size-20}
:action :selector
:action-props {:type (if (= :default state)
:action-props {:type (if (and (= :default state) (not normal-checkbox?))
:filled-checkbox
:checkbox)
:customization-color color
Expand Down
1 change: 1 addition & 0 deletions src/status_im/contexts/wallet/send/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
(assoc-in [:wallet :ui :send :recipient] (or recipient address))
(assoc-in [:wallet :ui :send :to-address] to-address)
(assoc-in [:wallet :ui :send :address-prefix] prefix)
(assoc-in [:wallet :ui :send :receiver-preferred-networks] receiver-networks)
(assoc-in [:wallet :ui :send :receiver-networks] receiver-networks))
:fx [[:dispatch
[:wallet/wizard-navigate-forward
Expand Down
19 changes: 0 additions & 19 deletions src/status_im/contexts/wallet/send/input_amount/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
[status-im.contexts.wallet.common.asset-list.view :as asset-list]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.common.utils.networks :as network-utils]
[status-im.contexts.wallet.send.input-amount.style :as style]
[status-im.contexts.wallet.send.routes.view :as routes]
[status-im.contexts.wallet.send.utils :as send-utils]
[status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences]
[utils.address :as address]
[utils.i18n :as i18n]
[utils.money :as money]
Expand Down Expand Up @@ -80,23 +78,6 @@
(rf/dispatch [:wallet/edit-token-to-send token])
(clear-input!))}]]))

(defn- open-preferences
[selected-networks account]
(rf/dispatch
[:show-bottom-sheet
{:content (fn []
[network-preferences/view
{:title (i18n/label :t/edit-receiver-networks)
:section-one-title (i18n/label :t/preferred-by-receiver)
:section-two-title (i18n/label :t/not-preferred-by-receiver)
:selected-networks (vec (map network-utils/id->network selected-networks))
:receiver? true
:account account
:button-label "Apply"
:on-save (fn [chain-ids]
(rf/dispatch [:hide-bottom-sheet])
(rf/dispatch [:wallet/update-receiver-networks chain-ids]))}])}]))

(defn- token-not-available
[token-symbol receiver-networks token-networks]
(let [add-token-networks (fn []
Expand Down
28 changes: 22 additions & 6 deletions src/status_im/contexts/wallet/send/routes/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[status-im.contexts.wallet.common.utils.networks :as network-utils]
[status-im.contexts.wallet.send.routes.style :as style]
[status-im.contexts.wallet.send.utils :as send-utils]
[status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences]
[utils.debounce :as debounce]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
Expand Down Expand Up @@ -97,8 +98,27 @@
(on-save))
:customization-color color}}]])))

(defn- open-preferences
[]
(let [receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
receiver-preferred-networks (rf/sub [:wallet/wallet-send-receiver-preferred-networks])]
(rf/dispatch
[:show-bottom-sheet
{:content (fn []
[network-preferences/view
{:title (i18n/label :t/edit-receiver-networks)
:first-section-label (i18n/label :t/preferred-by-receiver)
:second-section-label (i18n/label :t/not-preferred-by-receiver)
:selected-networks (set (map network-utils/id->network receiver-networks))
:receiver-preferred-networks receiver-preferred-networks
:button-label (i18n/label :t/apply)
:on-save (fn [chain-ids]
(rf/dispatch [:hide-bottom-sheet])
(rf/dispatch [:wallet/update-receiver-networks
chain-ids]))}])}])))

(defn render-network-values
[{:keys [network-values token-symbol on-press theme on-save to? loading-routes?
[{:keys [network-values token-symbol on-press to? loading-routes?
token-not-supported-in-receiver-networks?]}]
[rn/view
(map-indexed (fn [index {:keys [chain-id total-amount type]}]
Expand All @@ -120,11 +140,7 @@
:on-press #(when (not loading-routes?)
(cond
(= type :add)
(rf/dispatch [:show-bottom-sheet
{:content (fn []
[networks-drawer
{:theme theme
:on-save on-save}])}])
(open-preferences)
on-press (on-press chain-id total-amount)))}]])
network-values)])

Expand Down
74 changes: 45 additions & 29 deletions src/status_im/contexts/wallet/sheets/network_preferences/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
[utils.re-frame :as rf]))

(defn view
[{:keys [title receiver? _section-one-title _section-two-title selected-networks account watch-only?]}]
[{:keys [title first-section-label second-section-label selected-networks
receiver-preferred-networks account watch-only?]}]
(let [state (reagent/atom :default)
{:keys [color address
network-preferences-names]} (or account (rf/sub [:wallet/current-viewing-account]))
initial-network-preferences-names (or selected-networks network-preferences-names)
network-preferences-names-state (reagent/atom #{})
receiver? (boolean (not-empty receiver-preferred-networks))
network-preferences-names-state (reagent/atom (if receiver? selected-networks #{}))
toggle-network (fn [network-name]
(reset! state :changed)
(let [contains-network? (contains?
Expand All @@ -35,14 +37,24 @@
initial-network-preferences-names
@network-preferences-names-state))]
(fn [{:keys [on-save blur? button-label]}]
(let [theme (quo.theme/use-theme)
network-details (rf/sub [:wallet/network-details])
mainnet (first network-details)
layer-2-networks (rest network-details)
current-networks (filter (fn [network]
(contains? (get-current-preferences-names)
(:network-name network)))
network-details)]
(let [theme (quo.theme/use-theme)
network-details (rf/sub [:wallet/network-details])
first-section-networks (filter (fn [network]
(if receiver-preferred-networks
(some (fn [chain-id]
(= (:chain-id network) chain-id))
receiver-preferred-networks)
(= (:network-name network) :mainnet)))
network-details)
second-section-networks (remove (fn [network]
(some (fn [chain-id]
(= (:chain-id network) chain-id))
(map :chain-id first-section-networks)))
network-details)
current-networks (filter (fn [network]
(contains? (get-current-preferences-names)
(:network-name network)))
network-details)]
[:<>
;; quo/overlay isn't compatible with sheets
(when blur?
Expand All @@ -52,9 +64,10 @@
:blur-radius 25}])
[quo/drawer-top
{:title (or title (i18n/label :t/network-preferences))
:description (if watch-only?
(i18n/label :t/network-preferences-desc-1)
(i18n/label :t/network-preferences-desc-2))
:description (when-not receiver?
(if watch-only?
(i18n/label :t/network-preferences-desc-1)
(i18n/label :t/network-preferences-desc-2)))
:blur? blur?}]
(when-not receiver?
[quo/data-item
Expand All @@ -78,26 +91,29 @@
[quo/category
{:list-type :settings
:blur? blur?
:data [(utils/make-network-item {:state @state
:network-name (:network-name mainnet)
:color color
:blur? blur?
:networks (get-current-preferences-names)
:on-change #(toggle-network (:network-name
mainnet))})]}]
:label (when first-section-label first-section-label)
:data (mapv (fn [network]
(utils/make-network-item {:state @state
:network-name (:network-name network)
:color color
:normal-checkbox? receiver?
:networks (get-current-preferences-names)
:on-change #(toggle-network (:network-name
network))}))
first-section-networks)}]
[quo/category
{:list-type :settings
:blur? blur?
:label (i18n/label :t/layer-2)
:label (or second-section-label (i18n/label :t/layer-2))
:data (mapv (fn [network]
(utils/make-network-item {:state @state
:network-name (:network-name network)
:color color
:blur? blur?
:networks (get-current-preferences-names)
:on-change #(toggle-network (:network-name
network))}))
layer-2-networks)}]
(utils/make-network-item {:state @state
:network-name (:network-name network)
:color color
:normal-checkbox? receiver?
:networks (get-current-preferences-names)
:on-change #(toggle-network (:network-name
network))}))
second-section-networks)}]
[quo/bottom-actions
{:actions :one-action
:blur? blur?
Expand Down
5 changes: 5 additions & 0 deletions src/status_im/subs/wallet/wallet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
:<- [:wallet/wallet-send]
:-> :receiver-networks)

(rf/reg-sub
:wallet/wallet-send-receiver-preferred-networks
:<- [:wallet/wallet-send]
:-> :receiver-preferred-networks)

(rf/reg-sub
:wallet/wallet-send-route
:<- [:wallet/wallet-send]
Expand Down

0 comments on commit 6a09720

Please sign in to comment.