Skip to content

Commit

Permalink
Split state
Browse files Browse the repository at this point in the history
  • Loading branch information
Rende11 committed Dec 7, 2023
1 parent fb30762 commit f042206
Showing 1 changed file with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,44 @@

(defn- make-network-item
[{:keys [network-name] :as _network}
{:keys [color on-change network-preferences] :as _options}]
{:title (string/capitalize (name network-name))
{:keys [title color on-change network-preferences state] :as _options}]
{:title (or 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 :checkbox
:action-props {:type (if (= :default state)
:filled-checkbox
:checkbox)
:customization-color color
:checked? (contains? network-preferences network-name)
:on-change on-change}})

(defn- view-internal
[]
(let [{:keys [color address
(let [state (reagent/atom :default)
{:keys [color address
network-preferences-names]} (rf/sub [:wallet/current-viewing-account])
network-preferences-names-state (reagent/atom network-preferences-names)
initial-network-preferences-names network-preferences-names
network-preferences-names-state (reagent/atom #{})
toggle-network (fn [network-name]
(reset! state :changed)
(if (contains? @network-preferences-names-state
network-name)
(swap! network-preferences-names-state disj
network-name)
(swap! network-preferences-names-state conj
network-name)))]
network-name)))
get-current-preferences-names (fn []
(if (= @state :default)
initial-network-preferences-names
@network-preferences-names-state))]
(fn [{:keys [on-save theme]}]
(let [network-details (rf/sub [:wallet/network-details])
mainnet (first network-details)
layer-2-networks (rest network-details)
current-networks (filter (fn [network]
(contains? @network-preferences-names-state
(contains? (get-current-preferences-names)
(:network-name network)))
network-details)]
[:<>
Expand All @@ -64,28 +73,29 @@
{:background-color (colors/theme-colors colors/neutral-2_5
colors/neutral-90
theme)})}]

[quo/category
{:list-type :settings
:data [(make-network-item mainnet
{:color color
:network-preferences @network-preferences-names-state
{:state @state
:title (i18n/label :t/mainnet)
:color color
:network-preferences (get-current-preferences-names)
:on-change #(toggle-network (:network-name
mainnet))})]}]
[quo/category
{:list-type :settings
:label (i18n/label :t/layer-2)
:data (mapv (fn [network]
(make-network-item network
{:color color
:network-preferences @network-preferences-names-state
{:state @state
:color color
:network-preferences (get-current-preferences-names)
:on-change #(toggle-network (:network-name
network))}))
layer-2-networks)}]
[quo/bottom-actions
{:button-one-label (i18n/label :t/confirm)
:button-one-props {:disabled? (= @network-preferences-names-state
network-preferences-names)
:button-one-props {:disabled? (= @state :default)
:on-press (fn []
(let [chain-ids (map :chain-id current-networks)]
(on-save chain-ids)))
Expand Down

0 comments on commit f042206

Please sign in to comment.