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
: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

View File

@ -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

View File

@ -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}]]))

View File

@ -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}]

View File

@ -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
[]

View File

@ -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)}))