feat(wallet): add ability to remove wallet account (#19121)

This commit is contained in:
Jamie Caprani 2024-03-15 21:20:28 +00:00 committed by GitHub
parent 219dd7cb46
commit d0d7310e82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 74 additions and 70 deletions

View File

@ -9,7 +9,6 @@
[status-im.contexts.wallet.sheets.network-preferences.view [status-im.contexts.wallet.sheets.network-preferences.view
:as network-preferences] :as network-preferences]
[status-im.contexts.wallet.sheets.remove-account.view :as remove-account] [status-im.contexts.wallet.sheets.remove-account.view :as remove-account]
[status-im.feature-flags :as ff]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -67,13 +66,10 @@
[create-or-edit-account/view [create-or-edit-account/view
{:page-nav-right-side [(when-not default-account? {:page-nav-right-side [(when-not default-account?
{:icon-name :i/delete {:icon-name :i/delete
:on-press :on-press #(rf/dispatch [:show-bottom-sheet
#(ff/alert ::ff/wallet.remove-account
(fn []
(rf/dispatch [:show-bottom-sheet
{:content {:content
(fn [] (fn []
[remove-account/view])}])))})] [remove-account/view])}])})]
:account-name account-name :account-name account-name
:account-emoji emoji :account-emoji emoji
:account-color color :account-color color

View File

@ -95,10 +95,16 @@
(rf/reg-event-fx (rf/reg-event-fx
:wallet/remove-account-success :wallet/remove-account-success
(fn [_ [toast-message _]] (fn [_ [toast-message _]]
{:fx [[:dispatch [:hide-bottom-sheet]] {:fx [[:dispatch [:wallet/get-accounts]]
[:dispatch [:pop-to-root :shell-stack]] [:dispatch-later
[:dispatch [:wallet/get-accounts]] {:ms 100
[:dispatch [:wallet/show-account-deleted-toast toast-message]]]})) :dispatch [:hide-bottom-sheet]}]
[:dispatch-later
{:ms 100
:dispatch [:pop-to-root :shell-stack]}]
[:dispatch-later
{:ms 100
:dispatch [:wallet/show-account-deleted-toast toast-message]}]]}))
(rf/reg-event-fx (rf/reg-event-fx
:wallet/remove-account :wallet/remove-account

View File

@ -2,7 +2,6 @@
(:require (:require
[quo.core :as quo] [quo.core :as quo]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent]
[status-im.common.home.top-nav.view :as common.top-nav] [status-im.common.home.top-nav.view :as common.top-nav]
[status-im.contexts.wallet.home.style :as style] [status-im.contexts.wallet.home.style :as style]
[status-im.contexts.wallet.home.tabs.view :as tabs] [status-im.contexts.wallet.home.tabs.view :as tabs]
@ -39,13 +38,22 @@
(defn view (defn view
[] []
(let [selected-tab (reagent/atom (:id (first tabs-data)))] (let [[selected-tab set-selected-tab] (rn/use-state (:id (first tabs-data)))
(fn [] account-list-ref (rn/use-ref-atom nil)
(let [tokens-loading? (rf/sub [:wallet/tokens-loading?]) tokens-loading? (rf/sub [:wallet/tokens-loading?])
networks (rf/sub [:wallet/network-details]) networks (rf/sub [:wallet/network-details])
account-cards-data (rf/sub [:wallet/account-cards-data]) account-cards-data (rf/sub [:wallet/account-cards-data])
cards (conj account-cards-data (new-account-card-data)) cards (conj account-cards-data (new-account-card-data))
{:keys [formatted-balance]} (rf/sub [:wallet/aggregated-tokens-and-balance])] {:keys [formatted-balance]} (rf/sub [:wallet/aggregated-tokens-and-balance])]
(rn/use-effect (fn []
(when (and @account-list-ref (pos? (count cards)))
(.scrollToOffset ^js @account-list-ref
#js
{:animated true
:offset 0}
)))
[(count cards)])
[rn/view {:style (style/home-container)} [rn/view {:style (style/home-container)}
[common.top-nav/view] [common.top-nav/view]
[rn/view {:style style/overview-container} [rn/view {:style style/overview-container}
@ -61,7 +69,8 @@
{:content network-filter/view}])))}]] {:content network-filter/view}])))}]]
[quo/wallet-graph {:time-frame :empty}] [quo/wallet-graph {:time-frame :empty}]
[rn/flat-list [rn/flat-list
{:style style/accounts-list {:ref #(reset! account-list-ref %)
:style style/accounts-list
:content-container-style style/accounts-list-container :content-container-style style/accounts-list-container
:data cards :data cards
:horizontal true :horizontal true
@ -71,7 +80,7 @@
[quo/tabs [quo/tabs
{:style style/tabs {:style style/tabs
:size 32 :size 32
:default-active @selected-tab :default-active selected-tab
:data tabs-data :data tabs-data
:on-change #(reset! selected-tab %)}] :on-change #(set-selected-tab %)}]
[tabs/view {:selected-tab @selected-tab}]])))) [tabs/view {:selected-tab selected-tab}]]))

View File

@ -12,7 +12,6 @@
[status-im.contexts.wallet.common.utils :as utils] [status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.sheets.account-options.style :as style] [status-im.contexts.wallet.sheets.account-options.style :as style]
[status-im.contexts.wallet.sheets.remove-account.view :as remove-account] [status-im.contexts.wallet.sheets.remove-account.view :as remove-account]
[status-im.feature-flags :as ff]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -99,12 +98,8 @@
:accessibility-label :remove-account :accessibility-label :remove-account
:label (i18n/label :t/remove-account) :label (i18n/label :t/remove-account)
:danger? true :danger? true
:on-press #(ff/alert ::ff/wallet.remove-account :on-press #(rf/dispatch [:show-bottom-sheet
(fn [] {:content remove-account/view}])})]]]
(rf/dispatch [:show-bottom-sheet
{:content
(fn []
[remove-account/view])}])))})]]]
(when show-account-selector? (when show-account-selector?
[:<> [:<>
[quo/divider-line {:container-style style/divider-label}] [quo/divider-line {:container-style style/divider-label}]

View File

@ -13,8 +13,7 @@
(defn- footer (defn- footer
[{:keys [address submit-disabled? toast-message]}] [{:keys [address submit-disabled? toast-message]}]
[quo/bottom-actions [quo/bottom-actions
{:actions :2-actions {:actions :two-actions
:customization-color :danger
:button-one-label (i18n/label :t/remove) :button-one-label (i18n/label :t/remove)
:button-one-props {:on-press :button-one-props {:on-press
(fn [] (fn []

View File

@ -12,7 +12,6 @@
(reagent/atom (reagent/atom
{::wallet.edit-default-keypair true {::wallet.edit-default-keypair true
::wallet.bridge-token (enabled-in-env? :FLAG_BRIDGE_TOKEN_ENABLED) ::wallet.bridge-token (enabled-in-env? :FLAG_BRIDGE_TOKEN_ENABLED)
::wallet.remove-account (enabled-in-env? :FLAG_REMOVE_ACCOUNT_ENABLED)
::wallet.network-filter (enabled-in-env? :FLAG_NETWORK_FILTER_ENABLED) ::wallet.network-filter (enabled-in-env? :FLAG_NETWORK_FILTER_ENABLED)
::profile.new-contact-ui (enabled-in-env? :FLAG_NEW_CONTACT_UI_ENABLED)})) ::profile.new-contact-ui (enabled-in-env? :FLAG_NEW_CONTACT_UI_ENABLED)}))