From d0d7310e82c939ca2e428f3dcfc1f7821c340044 Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Fri, 15 Mar 2024 21:20:28 +0000 Subject: [PATCH] feat(wallet): add ability to remove wallet account (#19121) --- .../contexts/wallet/edit_account/view.cljs | 12 +-- src/status_im/contexts/wallet/events.cljs | 14 +++- src/status_im/contexts/wallet/home/view.cljs | 83 ++++++++++--------- .../wallet/sheets/account_options/view.cljs | 9 +- .../wallet/sheets/remove_account/view.cljs | 25 +++--- src/status_im/feature_flags.cljs | 1 - 6 files changed, 74 insertions(+), 70 deletions(-) diff --git a/src/status_im/contexts/wallet/edit_account/view.cljs b/src/status_im/contexts/wallet/edit_account/view.cljs index 54ca0068c8..dc8efa3e83 100644 --- a/src/status_im/contexts/wallet/edit_account/view.cljs +++ b/src/status_im/contexts/wallet/edit_account/view.cljs @@ -9,7 +9,6 @@ [status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences] [status-im.contexts.wallet.sheets.remove-account.view :as remove-account] - [status-im.feature-flags :as ff] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -67,13 +66,10 @@ [create-or-edit-account/view {:page-nav-right-side [(when-not default-account? {:icon-name :i/delete - :on-press - #(ff/alert ::ff/wallet.remove-account - (fn [] - (rf/dispatch [:show-bottom-sheet - {:content - (fn [] - [remove-account/view])}])))})] + :on-press #(rf/dispatch [:show-bottom-sheet + {:content + (fn [] + [remove-account/view])}])})] :account-name account-name :account-emoji emoji :account-color color diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 3a7dff828e..455699c3ab 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -95,10 +95,16 @@ (rf/reg-event-fx :wallet/remove-account-success (fn [_ [toast-message _]] - {:fx [[:dispatch [:hide-bottom-sheet]] - [:dispatch [:pop-to-root :shell-stack]] - [:dispatch [:wallet/get-accounts]] - [:dispatch [:wallet/show-account-deleted-toast toast-message]]]})) + {:fx [[:dispatch [:wallet/get-accounts]] + [:dispatch-later + {:ms 100 + :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 :wallet/remove-account diff --git a/src/status_im/contexts/wallet/home/view.cljs b/src/status_im/contexts/wallet/home/view.cljs index f55cb91973..578a7ea188 100644 --- a/src/status_im/contexts/wallet/home/view.cljs +++ b/src/status_im/contexts/wallet/home/view.cljs @@ -2,7 +2,6 @@ (:require [quo.core :as quo] [react-native.core :as rn] - [reagent.core :as reagent] [status-im.common.home.top-nav.view :as common.top-nav] [status-im.contexts.wallet.home.style :as style] [status-im.contexts.wallet.home.tabs.view :as tabs] @@ -39,39 +38,49 @@ (defn view [] - (let [selected-tab (reagent/atom (:id (first tabs-data)))] - (fn [] - (let [tokens-loading? (rf/sub [:wallet/tokens-loading?]) - networks (rf/sub [:wallet/network-details]) - account-cards-data (rf/sub [:wallet/account-cards-data]) - cards (conj account-cards-data (new-account-card-data)) - {:keys [formatted-balance]} (rf/sub [:wallet/aggregated-tokens-and-balance])] - [rn/view {:style (style/home-container)} - [common.top-nav/view] - [rn/view {:style style/overview-container} - [quo/wallet-overview - {:state (if tokens-loading? :loading :default) - :time-frame :none - :metrics :none - :balance formatted-balance - :networks networks - :dropdown-on-press #(ff/alert ::ff/wallet.network-filter - (fn [] - (rf/dispatch [:show-bottom-sheet - {:content network-filter/view}])))}]] - [quo/wallet-graph {:time-frame :empty}] - [rn/flat-list - {:style style/accounts-list - :content-container-style style/accounts-list-container - :data cards - :horizontal true - :separator [rn/view {:style style/separator}] - :render-fn (fn [item] [quo/account-card item]) - :shows-horizontal-scroll-indicator false}] - [quo/tabs - {:style style/tabs - :size 32 - :default-active @selected-tab - :data tabs-data - :on-change #(reset! selected-tab %)}] - [tabs/view {:selected-tab @selected-tab}]])))) + (let [[selected-tab set-selected-tab] (rn/use-state (:id (first tabs-data))) + account-list-ref (rn/use-ref-atom nil) + tokens-loading? (rf/sub [:wallet/tokens-loading?]) + networks (rf/sub [:wallet/network-details]) + account-cards-data (rf/sub [:wallet/account-cards-data]) + cards (conj account-cards-data (new-account-card-data)) + + {: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)} + [common.top-nav/view] + [rn/view {:style style/overview-container} + [quo/wallet-overview + {:state (if tokens-loading? :loading :default) + :time-frame :none + :metrics :none + :balance formatted-balance + :networks networks + :dropdown-on-press #(ff/alert ::ff/wallet.network-filter + (fn [] + (rf/dispatch [:show-bottom-sheet + {:content network-filter/view}])))}]] + [quo/wallet-graph {:time-frame :empty}] + [rn/flat-list + {:ref #(reset! account-list-ref %) + :style style/accounts-list + :content-container-style style/accounts-list-container + :data cards + :horizontal true + :separator [rn/view {:style style/separator}] + :render-fn (fn [item] [quo/account-card item]) + :shows-horizontal-scroll-indicator false}] + [quo/tabs + {:style style/tabs + :size 32 + :default-active selected-tab + :data tabs-data + :on-change #(set-selected-tab %)}] + [tabs/view {:selected-tab selected-tab}]])) diff --git a/src/status_im/contexts/wallet/sheets/account_options/view.cljs b/src/status_im/contexts/wallet/sheets/account_options/view.cljs index b6ace83348..5e6fc4ece5 100644 --- a/src/status_im/contexts/wallet/sheets/account_options/view.cljs +++ b/src/status_im/contexts/wallet/sheets/account_options/view.cljs @@ -12,7 +12,6 @@ [status-im.contexts.wallet.common.utils :as utils] [status-im.contexts.wallet.sheets.account-options.style :as style] [status-im.contexts.wallet.sheets.remove-account.view :as remove-account] - [status-im.feature-flags :as ff] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -99,12 +98,8 @@ :accessibility-label :remove-account :label (i18n/label :t/remove-account) :danger? true - :on-press #(ff/alert ::ff/wallet.remove-account - (fn [] - (rf/dispatch [:show-bottom-sheet - {:content - (fn [] - [remove-account/view])}])))})]]] + :on-press #(rf/dispatch [:show-bottom-sheet + {:content remove-account/view}])})]]] (when show-account-selector? [:<> [quo/divider-line {:container-style style/divider-label}] diff --git a/src/status_im/contexts/wallet/sheets/remove_account/view.cljs b/src/status_im/contexts/wallet/sheets/remove_account/view.cljs index d504e65f89..169f48074d 100644 --- a/src/status_im/contexts/wallet/sheets/remove_account/view.cljs +++ b/src/status_im/contexts/wallet/sheets/remove_account/view.cljs @@ -13,19 +13,18 @@ (defn- footer [{:keys [address submit-disabled? toast-message]}] [quo/bottom-actions - {:actions :2-actions - :customization-color :danger - :button-one-label (i18n/label :t/remove) - :button-one-props {:on-press - (fn [] - (rf/dispatch [:wallet/remove-account - {:address address - :toast-message toast-message}])) - :type :danger - :disabled? submit-disabled?} - :button-two-label (i18n/label :t/cancel) - :button-two-props {:on-press #(rf/dispatch [:hide-bottom-sheet]) - :type :grey}}]) + {:actions :two-actions + :button-one-label (i18n/label :t/remove) + :button-one-props {:on-press + (fn [] + (rf/dispatch [:wallet/remove-account + {:address address + :toast-message toast-message}])) + :type :danger + :disabled? submit-disabled?} + :button-two-label (i18n/label :t/cancel) + :button-two-props {:on-press #(rf/dispatch [:hide-bottom-sheet]) + :type :grey}}]) (defn- recovery-phase-flow [] diff --git a/src/status_im/feature_flags.cljs b/src/status_im/feature_flags.cljs index 0d0ddb7ed8..df9fd4398e 100644 --- a/src/status_im/feature_flags.cljs +++ b/src/status_im/feature_flags.cljs @@ -12,7 +12,6 @@ (reagent/atom {::wallet.edit-default-keypair true ::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) ::profile.new-contact-ui (enabled-in-env? :FLAG_NEW_CONTACT_UI_ENABLED)}))