-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check chains Save network-preferences Improvements Fix linter issues Clean up Updates Update sub test Update tests Updates Store as set Fix minor issues Update naming Revive `get-account-by-address` Fix alignment Fix merge
- Loading branch information
Showing
9 changed files
with
320 additions
and
179 deletions.
There are no files selected for viewing
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
138 changes: 81 additions & 57 deletions
138
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,94 @@ | ||
(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}] | ||
{: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 | ||
:label :none | ||
:blur? false | ||
:card? true | ||
:title (i18n/label :t/address) | ||
:subtitle address | ||
:subtitle-type :default | ||
: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-names]} (rf/sub [:wallet/current-viewing-account]) | ||
network-preferences-names-state (reagent/atom network-preferences-names) | ||
toggle-network (fn [network-name] | ||
(if (contains? @network-preferences-names-state | ||
network-name) | ||
(swap! network-preferences-names-state disj | ||
network-name) | ||
(swap! network-preferences-names-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 (filter (fn [network] | ||
(contains? @network-preferences-names-state | ||
(:network-name network))) | ||
network-details)] | ||
[:<> | ||
[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-names-state | ||
: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 | ||
:on-change #(toggle-network (:network-name | ||
network))})) | ||
layer-2-networks)}] | ||
[quo/bottom-actions | ||
{:button-one-label (i18n/label :t/update) | ||
:button-one-props {:disabled? (= @network-preferences-names-state | ||
network-preferences-names) | ||
:on-press (fn [] | ||
(let [chain-ids (map :chain-id current-networks)] | ||
(on-save chain-ids))) | ||
:customization-color color}}]])))) | ||
|
||
(def view (quo.theme/with-theme view-internal)) |
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
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
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
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
Oops, something went wrong.