Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add screen for key-pairs and accounts inside wallet settings #19912

Merged
merged 28 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8352e58
chore: add "key pairs and accounts" label
seanstrom May 6, 2024
109800d
chore: feature flag wallet-settings
seanstrom May 6, 2024
f93b517
tidy: extact navigate-back function into static defn
seanstrom May 6, 2024
2385ea1
wip: add initial keypairs and accounts list view to wallet settings
seanstrom May 6, 2024
54f3fa0
tweak: wire-up initial action menu for key-pairs
seanstrom May 6, 2024
925c8e3
tidy: extract key-pair container styles into style namespace
seanstrom May 6, 2024
04a1830
tweak: fix dark background for key-pair and account settings
seanstrom May 6, 2024
e65f11e
tidy: refactor on-press handler for key-pair options
seanstrom May 7, 2024
be26ec2
fix: move feature-flag usage to settings screen instead of settings i…
seanstrom May 8, 2024
15e98cd
tidy: remove unneeded key props
seanstrom May 8, 2024
5ab5f04
tidy: clean up de-structuring and passing of props
seanstrom May 8, 2024
a608d44
tidy: use keep with when expressions instead of filter and map expres…
seanstrom May 8, 2024
a4d9804
tidy: rename the wallet-settings feature flag
seanstrom May 9, 2024
84d73dc
tweak: rename and add feature-flags for mobile wallet settings
seanstrom May 9, 2024
b342026
tweak: use scrollview for feature-flags and add spacing between featu…
seanstrom May 9, 2024
fa0f90f
tweak: adjust the way feature-flags are displayed in groups
seanstrom May 9, 2024
0a6e505
tidy: remove unneeded prop
seanstrom May 9, 2024
4722c08
tidy: use bottom-inset for padding key-pair and accounts list
seanstrom May 9, 2024
0ded40f
tidy: change `filterv` to `filter`
seanstrom May 9, 2024
e569b85
tidy: use subscription for building account-props
seanstrom May 9, 2024
a771319
tidy: use subscription to build the entire keypair-account
seanstrom May 9, 2024
8d64555
tweak: use key-pair type to determine default key-pair
seanstrom May 9, 2024
14019f1
tidy: rename component to settings-category-view
seanstrom May 9, 2024
53cd9f6
tidy: use assoc instead of merge
seanstrom May 9, 2024
839a55f
tidy: extract function from subscription
seanstrom May 9, 2024
35dfd82
test: add tests for formatting key-pairs and accounts for wallet sett…
seanstrom May 9, 2024
f49b8bf
tweak: use `match?` instead of `=`
seanstrom May 9, 2024
61f7bfb
tidy: use `swap!` without anonymous functions
seanstrom May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/status_im/contexts/preview/feature_flags/style.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns status-im.contexts.preview.feature-flags.style)

(def container
{:flex 1
:margin-left 20})
{:flex 1
:margin-left 20
:margin-bottom 20})
42 changes: 22 additions & 20 deletions src/status_im/contexts/preview/feature_flags/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@
:on-press #(rf/dispatch [:navigate-back])
:right-side [{:icon-name :i/rotate
:on-press #(ff/reset-flags)}]}]
(doall
(for [context-name ff/feature-flags-categories
:let [context-flags (filter (fn [[k]]
(string/includes? (str k) context-name))
(ff/feature-flags))]]
^{:key (str context-name)}
[rn/view {:style style/container}
[quo/text
context-name]
(doall
(for [i (range (count context-flags))
:let [[flag] (nth context-flags i)]]
^{:key (str context-name flag i)}
[rn/view {:style {:flex-direction :row}}
[quo/selectors
{:type :toggle
:checked? (ff/enabled? flag)
:container-style {:margin-right 8}
:on-change #(ff/toggle flag)}]
[quo/text (second (string/split (name flag) "."))]]))]))])
[rn/scroll-view
(doall
(for [context-name ff/feature-flags-categories
:let [context-flags (filter (fn [[k]]
(= context-name
(first (string/split (str (name k)) "."))))
(ff/feature-flags))]]
^{:key (str context-name)}
[rn/view {:style style/container}
[quo/text
context-name]
(doall
(for [i (range (count context-flags))
:let [[flag] (nth context-flags i)]]
^{:key (str context-name flag i)}
[rn/view {:style {:flex-direction :row}}
[quo/selectors
{:type :toggle
:checked? (ff/enabled? flag)
:container-style {:margin-right 8}
:on-change #(ff/toggle flag)}]
[quo/text (second (string/split (name flag) "."))]]))]))]])
14 changes: 8 additions & 6 deletions src/status_im/contexts/profile/settings/list_items.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns status-im.contexts.profile.settings.list-items
(:require [status-im.common.not-implemented :as not-implemented]
[status-im.config :as config]
[status-im.feature-flags :as ff]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

Expand Down Expand Up @@ -34,12 +35,13 @@
:image :icon
:blur? true
:action :arrow}
{:title (i18n/label :t/wallet)
:on-press #(rf/dispatch [:open-modal :screen/settings.wallet])
:image-props :i/wallet
:image :icon
:blur? true
:action :arrow}
{:title (i18n/label :t/wallet)
:on-press #(rf/dispatch [:open-modal :screen/settings.wallet])
:image-props :i/wallet
:image :icon
:blur? true
:action :arrow
:feature-flag ::ff/settings.wallet-settings}
(when config/show-not-implemented-features?
{:title (i18n/label :t/dapps)
:on-press not-implemented/alert
Expand Down
21 changes: 12 additions & 9 deletions src/status_im/contexts/profile/settings/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@
[status-im.contexts.profile.settings.list-items :as settings.items]
[status-im.contexts.profile.settings.style :as style]
[status-im.contexts.profile.utils :as profile.utils]
[status-im.feature-flags :as ff]
[utils.debounce :as debounce]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn- settings-item-view
(defn show-settings-item?
seanstrom marked this conversation as resolved.
Show resolved Hide resolved
[{:keys [feature-flag]}]
(or (ff/enabled? feature-flag)
seanstrom marked this conversation as resolved.
Show resolved Hide resolved
(nil? feature-flag)))

(defn- settings-category-view
[data]
[rf/delay-render
[quo/category
{:list-type :settings
:container-style {:padding-bottom 12}
:blur? true
:data data}]])
:data (filter show-settings-item? data)}]])

(defn scroll-handler
[event scroll-y]
Expand Down Expand Up @@ -52,8 +58,7 @@
on-scroll (rn/use-callback #(scroll-handler % scroll-y))]
[quo/overlay {:type :shell}
[rn/view
{:key :header
:style (style/navigation-wrapper {:customization-color customization-color
{:style (style/navigation-wrapper {:customization-color customization-color
:inset (:top insets)
:theme theme})}
[quo/page-nav
Expand All @@ -72,20 +77,18 @@
{:options {:message (:universal-profile-url
profile)}}])}]}]]
[rn/flat-list
{:key :list
:header [settings.header/view {:scroll-y scroll-y}]
{:header [settings.header/view {:scroll-y scroll-y}]
:data (settings.items/items (boolean (:mnemonic profile)))
:shows-vertical-scroll-indicator false
:render-fn settings-item-view
:render-fn settings-category-view
:get-item-layout get-item-layout
:footer [footer insets logout-press]
:scroll-event-throttle 16
:on-scroll on-scroll
:bounces false
:over-scroll-mode :never}]
[quo/floating-shell-button
{:key :shell
:jump-to
{:jump-to
{:on-press #(rf/dispatch [:shell/navigate-to-jump-to])
:customization-color customization-color
:label (i18n/label :t/jump-to)}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns status-im.contexts.settings.wallet.keypairs-and-accounts.actions.view
(:require [quo.core :as quo]))

(defn view
seanstrom marked this conversation as resolved.
Show resolved Hide resolved
[props]
[quo/drawer-top props])
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns status-im.contexts.settings.wallet.keypairs-and-accounts.style)

(def title-container
{:padding-horizontal 20
:margin-vertical 12})

(defn page-wrapper
[top-inset]
{:padding-top top-inset
:flex 1})

(defn list-container
[bottom-inset]
{:padding-bottom bottom-inset})

(def keypair-container-style
{:margin-horizontal 20
:margin-vertical 8})
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
(ns status-im.contexts.settings.wallet.keypairs-and-accounts.view
(:require [quo.core :as quo]
[quo.theme]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[status-im.contexts.settings.wallet.keypairs-and-accounts.actions.view :as actions]
[status-im.contexts.settings.wallet.keypairs-and-accounts.style :as style]
[utils.address :as utils]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn navigate-back
[]
(rf/dispatch [:navigate-back]))

(defn on-options-press
[{:keys [theme]
:as props}]
(rf/dispatch [:show-bottom-sheet
{:content (fn [] [actions/view props])
:theme theme}]))
seanstrom marked this conversation as resolved.
Show resolved Hide resolved

(defn- keypair
[{keypair-type :type
:keys [accounts name]}
_ _
{:keys [profile-picture compressed-key customization-color]}]
(let [theme (quo.theme/use-theme)
default-keypair? (= keypair-type :profile)
shortened-key (when default-keypair?
(utils/get-shortened-compressed-key compressed-key))
on-press (rn/use-callback
(fn []
(on-options-press
(cond-> {:theme theme
:blur? true
:title name}
default-keypair?
(assoc :type :default-keypair
:description shortened-key
:customization-color customization-color
:profile-picture profile-picture)
(not default-keypair?)
(assoc :type :keypair
:icon-avatar :i/seed))))
[customization-color default-keypair? name
profile-picture shortened-key theme])]
[quo/keypair
{:blur? false
:status-indicator false
:stored :on-device
:action :options
:accounts accounts
:customization-color customization-color
:container-style style/keypair-container-style
:profile-picture (when default-keypair? profile-picture)
:type (if default-keypair? :default-keypair :other)
:on-options-press on-press
:details {:full-name name
:address shortened-key}}]))

(defn view
[]
(let [insets (safe-area/get-insets)
compressed-key (rf/sub [:profile/compressed-key])
profile-picture (rf/sub [:profile/image])
customization-color (rf/sub [:profile/customization-color])
quo-keypairs-accounts (rf/sub [:wallet/settings-keypairs-accounts])]
[quo/overlay
{:type :shell
:container-style (style/page-wrapper (:top insets))}
[quo/page-nav
{:key :header
:background :blur
:icon-name :i/arrow-left
:on-press navigate-back}]
[rn/view {:style style/title-container}
[quo/standard-title
{:title (i18n/label :t/keypairs-and-accounts)
:accessibility-label :keypairs-and-accounts-header
:customization-color customization-color}]]
[rn/view {:style {:flex 1}}
[rn/flat-list
{:data quo-keypairs-accounts
:render-fn keypair
:render-data {:profile-picture profile-picture
:compressed-key compressed-key
:customization-color customization-color}
:content-container-style (style/list-container (:bottom insets))}]]]))
21 changes: 16 additions & 5 deletions src/status_im/contexts/settings/wallet/wallet_options/view.cljs
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
(ns status-im.contexts.settings.wallet.wallet-options.view
(:require [quo.core :as quo]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[status-im.contexts.settings.wallet.wallet-options.style :as style]
[status-im.feature-flags :as ff]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn open-saved-addresses-settings-modal
[]
(rf/dispatch [:open-modal :screen/settings.saved-addresses]))

(defn open-keypairs-and-accounts-settings-modal
[]
(rf/dispatch [:open-modal :screen/settings.keypairs-and-accounts]))

(defn gen-basic-settings-options
[]
[{:title (i18n/label :t/saved-addresses)
[(when (ff/enabled? ::ff/settings.keypairs-and-accounts)
{:title (i18n/label :t/keypairs-and-accounts)
:blur? true
:on-press open-keypairs-and-accounts-settings-modal
:action :arrow})
{:title (i18n/label :t/saved-addresses)
:blur? true
:on-press open-saved-addresses-settings-modal
:action :arrow}])
Expand All @@ -26,11 +35,13 @@
:blur? true
:list-type :settings}])

(defn navigate-back
[]
(rf/dispatch [:navigate-back]))

seanstrom marked this conversation as resolved.
Show resolved Hide resolved
(defn view
[]
(let [inset-top (safe-area/get-top)
navigate-back (rn/use-callback
#(rf/dispatch [:navigate-back]))]
(let [inset-top (safe-area/get-top)]
[quo/overlay
{:type :shell
:container-style (style/page-wrapper inset-top)}
Expand Down
3 changes: 3 additions & 0 deletions src/status_im/feature_flags.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

(def ^:private initial-flags
{::community.edit-account-selection (enabled-in-env? :FLAG_EDIT_ACCOUNT_SELECTION_ENABLED)
::settings.wallet-settings (enabled-in-env? :FLAG_WALLET_SETTINGS_ENABLED)
::settings.keypairs-and-accounts (enabled-in-env?
:FLAG_WALLET_SETTINGS_KEYPAIRS_AND_ACCOUNTS_ENABLED)
::wallet.activities (enabled-in-env? :FLAG_WALLET_ACTIVITY_ENABLED)
::wallet.assets-modal-hide (enabled-in-env? :FLAG_ASSETS_MODAL_HIDE)
::wallet.assets-modal-manage-tokens (enabled-in-env? :FLAG_ASSETS_MODAL_MANAGE_TOKENS)
Expand Down
7 changes: 7 additions & 0 deletions src/status_im/navigation/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
[status-im.contexts.profile.settings.screens.password.change-password.view :as change-password]
[status-im.contexts.profile.settings.screens.password.view :as settings-password]
[status-im.contexts.profile.settings.view :as settings]
[status-im.contexts.settings.wallet.keypairs-and-accounts.view :as keypairs-and-accounts]
[status-im.contexts.settings.wallet.saved-addresses.view :as saved-addresses-settings]
[status-im.contexts.settings.wallet.wallet-options.view :as wallet-options]
[status-im.contexts.shell.activity-center.view :as activity-center]
Expand Down Expand Up @@ -501,6 +502,12 @@
:options options/transparent-modal-screen-options
:component saved-addresses-settings/view}

{:name :screen/settings.keypairs-and-accounts
:options (merge
options/transparent-modal-screen-options
options/dark-screen)
seanstrom marked this conversation as resolved.
Show resolved Hide resolved
:component keypairs-and-accounts/view}

{:name :screen/settings-messages
:options options/transparent-modal-screen-options
:component settings.messages/view}
Expand Down
29 changes: 29 additions & 0 deletions src/status_im/subs/wallet/wallet.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns status-im.subs.wallet.wallet
(:require [clojure.string :as string]
[re-frame.core :as rf]
[status-im.constants :as constants]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.common.utils.networks :as network-utils]
[status-im.subs.wallet.add-account.address-to-watch]
Expand Down Expand Up @@ -158,6 +159,34 @@
:goerli-enabled? goerli-enabled?})
selected-networks))))

(defn- format-settings-keypair-accounts
[accounts
{:keys [networks size]
:or {networks []
size 32}}]
(->> accounts
(keep (fn [{:keys [path customization-color emoji name address]}]
(when-not (string/starts-with? path constants/path-eip1581)
{:account-props {:customization-color customization-color
:size size
:emoji emoji
:type :default
:name name
:address address}
:networks networks
:state :default
:action :none})))))

(rf/reg-sub
:wallet/settings-keypairs-accounts
:<- [:wallet/keypairs]
(fn [keypairs [_ format-options]]
(->> keypairs
(map (fn [{:keys [accounts name type]}]
{:type (keyword type)
:name name
:accounts (format-settings-keypair-accounts accounts format-options)})))))

(rf/reg-sub
:wallet/derivation-path-state
:<- [:wallet/create-account]
Expand Down