-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
113 additions
and
65 deletions.
There are no files selected for viewing
150 changes: 93 additions & 57 deletions
150
src/status_im2/contexts/wallet/common/sheets/network_preferences/view.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,106 @@ | ||
(ns status-im2.contexts.wallet.common.sheets.network-preferences.view | ||
(:require [quo.core :as quo] | ||
(:require [clojure.string :as string] | ||
[quo.core :as quo] | ||
[quo.foundations.colors :as colors] | ||
[quo.foundations.resources :as resources] | ||
[quo.theme :as quo.theme] | ||
[reagent.core :as reagent] | ||
[status-im2.contexts.wallet.common.sheets.network-preferences.style :as style] | ||
[utils.i18n :as i18n] | ||
[utils.re-frame :as rf])) | ||
|
||
(defn- mainnet | ||
[account-color] | ||
[{:title "Mainnet" | ||
:image :icon-avatar | ||
:image-props {:icon (resources/get-network :ethereum) | ||
:size :size-20} | ||
:action :selector | ||
:action-props {:type :checkbox | ||
:customization-color account-color}}]) | ||
|
||
(defn- networks-list | ||
[account-color] | ||
[{:title "Optimism" | ||
:image :icon-avatar | ||
:image-props {:icon (resources/get-network :optimism) | ||
:size :size-20} | ||
:action :selector | ||
:action-props {:type :checkbox | ||
:customization-color account-color}} | ||
{:title "Arbitrum" | ||
:image :icon-avatar | ||
:image-props {:icon (resources/get-network :arbitrum) | ||
:size :size-20} | ||
:action :selector | ||
:action-props {:type :checkbox | ||
:customization-color account-color}}]) | ||
(defn- make-network-item | ||
[{:keys [network-name] :as _network} | ||
{:keys [color on-change network-preferences] :as _options}] | ||
{:key (name network-name) | ||
: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 | ||
:customization-color color | ||
:checked? (contains? network-preferences network-name) | ||
:on-change on-change}}) | ||
|
||
(defn- view-internal | ||
[{:keys [on-save theme]}] | ||
(let [{:keys [color address]} (rf/sub [:wallet/current-viewing-account])] | ||
[:<> | ||
[quo/drawer-top | ||
{:title (i18n/label :t/network-preferences) | ||
:description (i18n/label :t/network-preferences-desc)}] | ||
[quo/data-item | ||
{:status :default | ||
:size :default | ||
:description :default | ||
:label :none | ||
:blur? false | ||
:card? true | ||
:title (i18n/label :t/address) | ||
:subtitle address | ||
:container-style (merge style/data-item | ||
{:background-color (colors/theme-colors colors/neutral-2_5 | ||
colors/neutral-90 | ||
theme)})}] | ||
[quo/category | ||
{:list-type :settings | ||
:data (mainnet color)}] | ||
[quo/category | ||
{:list-type :settings | ||
:label (i18n/label :t/layer-2) | ||
:data (networks-list color)}] | ||
[quo/bottom-actions | ||
{:button-one-label (i18n/label :t/update) | ||
:button-one-props {:disabled? true | ||
:on-press on-save | ||
:customization-color color}}]])) | ||
[] | ||
(let [{:keys [color address network-preferences]} (rf/sub [:wallet/current-viewing-account]) | ||
network-preferences-state (reagent/atom network-preferences) | ||
toggle-network (fn [network-name] | ||
(if (contains? @network-preferences-state | ||
network-name) | ||
(swap! network-preferences-state disj | ||
network-name) | ||
(swap! network-preferences-state conj | ||
network-name)))] | ||
(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 (->> network-details | ||
(filter | ||
#(contains? @network-preferences-state (:network-name %))))] | ||
[:<> | ||
[quo/drawer-top | ||
{:title (i18n/label :t/network-preferences) | ||
:description (i18n/label :t/network-preferences-desc)}] | ||
[quo/data-item | ||
{:status :default | ||
:size :default | ||
:description :default | ||
:label :none | ||
:blur? false | ||
:card? true | ||
:title (i18n/label :t/address) | ||
:custom-subtitle (fn [] | ||
[quo/address-text | ||
{:networks current-networks | ||
:address address | ||
:format :long}]) | ||
:container-style (merge style/data-item | ||
{: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-state | ||
:on-change #(toggle-network (:network-name | ||
mainnet))})]}] | ||
[quo/category | ||
{:list-type :settings | ||
:label (i18n/label :t/layer-2) | ||
:data (mapv #(make-network-item % | ||
{:color color | ||
:network-preferences @network-preferences-state | ||
:on-change (fn [_] | ||
(toggle-network (:network-name | ||
%)))}) | ||
layer-2-networks)}] | ||
[quo/bottom-actions | ||
{:button-one-label (i18n/label :t/update) | ||
:button-one-props {:disabled? true | ||
:on-press on-save | ||
:customization-color color}}]])))) | ||
|
||
(def view (quo.theme/with-theme view-internal)) | ||
|
||
|
||
(comment | ||
;; Temp | ||
(rf/sub [:profile/profile]) | ||
(rf/sub [:wallet/accounts]) | ||
(rf/sub [:wallet]) | ||
(rf/sub [:wallet/network-details]) | ||
(rf/sub [:wallet/networks]) | ||
(rf/sub [:wallet/balances]) | ||
(rf/sub [:wallet/current-viewing-account]) | ||
|
||
(rf/sub [:wallet/account-networks]) | ||
|
||
(make-network-item (first (rf/sub [:wallet/network-details])) {}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters