chore(wallet): connect remove account rpc request (#18601)

This commit is contained in:
Nikolay 2024-02-05 15:29:25 +03:00 committed by GitHub
parent 19ac0eea08
commit 32442945ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 108 additions and 49 deletions

View File

@ -6,14 +6,21 @@
[react-native.linear-gradient :as linear-gradient])) [react-native.linear-gradient :as linear-gradient]))
(defn- view-internal (defn- view-internal
[{:keys [customization-color opacity container-style height] :or {customization-color :blue}}] [{:keys [customization-color opacity container-style height]
(let [color-top (colors/custom-color customization-color 50 20) :or {customization-color :blue}}]
color-bottom (colors/custom-color customization-color 50 0)] ;; `when` added for safety, `linear-gradient` will break if `nil` is passed,
[linear-gradient/linear-gradient ;; the `:or` destructuring won't work because it's only applied when the
{:accessibility-label :gradient-cover ;; `:customization-color` key is non-existent. While deleting an account the key exists
:colors [color-top color-bottom] ;; and has a `nil` value.
:start {:x 0 :y 0} (when customization-color
:end {:x 0 :y 1} (let [color-top (colors/resolve-color customization-color 50 20)
:style (merge (style/root-container opacity height) container-style)}])) color-bottom (colors/resolve-color customization-color 50 0)]
[linear-gradient/linear-gradient
{:accessibility-label :gradient-cover
:colors [color-top color-bottom]
:start {:x 0 :y 0}
:end {:x 0 :y 1}
:style (merge (style/root-container opacity height)
container-style)}])))
(def view (quo.theme/with-theme view-internal)) (def view (quo.theme/with-theme view-internal))

View File

@ -172,4 +172,5 @@
(def wallet-feature-flags (def wallet-feature-flags
{:edit-default-keypair false {:edit-default-keypair false
:bridge-token false}) :bridge-token false
:remove-account false})

View File

@ -9,6 +9,7 @@
[react-native.gesture :as gesture] [react-native.gesture :as gesture]
[react-native.platform :as platform] [react-native.platform :as platform]
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.config :as config]
[status-im.contexts.wallet.common.sheets.account-options.style :as style] [status-im.contexts.wallet.common.sheets.account-options.style :as style]
[status-im.contexts.wallet.common.sheets.remove-account.view :as remove-account] [status-im.contexts.wallet.common.sheets.remove-account.view :as remove-account]
[status-im.contexts.wallet.common.utils :as utils] [status-im.contexts.wallet.common.utils :as utils]
@ -32,12 +33,13 @@
(defn- options (defn- options
[{:keys [theme show-account-selector? options-height]}] [{:keys [theme show-account-selector? options-height]}]
(let [{:keys [name color emoji address watch-only?]} (rf/sub [:wallet/current-viewing-account]) (let [{:keys [name color emoji address watch-only?
network-preference-details (rf/sub [:wallet/network-preference-details]) default-account?]} (rf/sub [:wallet/current-viewing-account])
multichain-address (utils/get-multichain-address network-preference-details (rf/sub [:wallet/network-preference-details])
network-preference-details multichain-address (utils/get-multichain-address
address) network-preference-details
share-title (str name " " (i18n/label :t/address))] address)
share-title (i18n/label :t/share-address-title {:address name})]
[rn/view [rn/view
{:on-layout #(reset! options-height (oops/oget % "nativeEvent.layout.height")) {:on-layout #(reset! options-height (oops/oget % "nativeEvent.layout.height"))
:style (when show-account-selector? style/options-container)} :style (when show-account-selector? style/options-container)}
@ -92,15 +94,19 @@
#(rf/dispatch [:wallet/share-account #(rf/dispatch [:wallet/share-account
{:title share-title :content multichain-address}]) {:title share-title :content multichain-address}])
600))} 600))}
{:add-divider? (not show-account-selector?) (when-not default-account?
:icon :i/delete {:add-divider? (not show-account-selector?)
:accessibility-label :remove-account :icon :i/delete
:label (i18n/label :t/remove-account) :accessibility-label :remove-account
:danger? true :label (i18n/label :t/remove-account)
:on-press #(rf/dispatch [:show-bottom-sheet :danger? true
{:content :on-press (fn []
(fn [] (if (:remove-account config/wallet-feature-flags)
[remove-account/view])}])}]]] (rf/dispatch [:show-bottom-sheet
{:content
(fn []
[remove-account/view])}])
(js/alert "Feature disabled in config file")))})]]]
(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

@ -11,13 +11,17 @@
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn- footer (defn- footer
[{:keys [submit-disabled?]}] [{:keys [address submit-disabled? toast-message]}]
[quo/bottom-actions [quo/bottom-actions
{:actions :2-actions {:actions :2-actions
:customization-color :danger :customization-color :danger
:button-one-label (i18n/label :t/remove) :button-one-label (i18n/label :t/remove)
:button-one-props {:on-press #(js/alert "Will be implemented") :button-one-props {:on-press
:type :danger (fn []
(rf/dispatch [:wallet/remove-account
{:address address
:toast-message toast-message}]))
:type :danger
:disabled? submit-disabled?} :disabled? submit-disabled?}
:button-two-label (i18n/label :t/cancel) :button-two-label (i18n/label :t/cancel)
:button-two-props {:on-press #(rf/dispatch [:hide-bottom-sheet]) :button-two-props {:on-press #(rf/dispatch [:hide-bottom-sheet])
@ -26,7 +30,7 @@
(defn- recovery-phase-flow (defn- recovery-phase-flow
[] []
(let [confirmed? (reagent/atom false)] (let [confirmed? (reagent/atom false)]
(fn [{:keys [name emoji path color] :as _account}] (fn [{:keys [address name emoji path color] :as _account}]
(let [formatted-path (utils/format-derivation-path path)] (let [formatted-path (utils/format-derivation-path path)]
[:<> [:<>
[quo/drawer-top [quo/drawer-top
@ -64,10 +68,13 @@
:checked? @confirmed? :checked? @confirmed?
:on-change #(swap! confirmed? not)}] :on-change #(swap! confirmed? not)}]
[quo/text (i18n/label :t/remove-account-confirmation)]] [quo/text (i18n/label :t/remove-account-confirmation)]]
[footer {:submit-disabled? (not @confirmed?)}]])))) [footer
{:submit-disabled? (not @confirmed?)
:address address
:toast-message (i18n/label :t/account-removed)}]]))))
(defn- watched-address-flow (defn- watched-address-flow
[{:keys [name emoji color] :as _account}] [{:keys [address name emoji color] :as _account}]
[:<> [:<>
[quo/drawer-top [quo/drawer-top
{:title (i18n/label :t/remove-watched-address-title) {:title (i18n/label :t/remove-watched-address-title)
@ -79,13 +86,17 @@
[rn/view {:style style/desc-container} [rn/view {:style style/desc-container}
[quo/text {:weight :medium} [quo/text {:weight :medium}
(i18n/label :t/remove-watched-address-desc)]] (i18n/label :t/remove-watched-address-desc)]]
[footer {:submit-disabled? false}]]) [footer
{:submit-disabled? false
:address address
:toast-message (i18n/label :t/watched-account-removed)}]])
(defn- view-internal (defn- view-internal
[] []
(let [{:keys [type] :as account} (rf/sub [:wallet/current-viewing-account])] (let [{:keys [type] :as account} (rf/sub [:wallet/current-viewing-account])]
(case type (case type
:generated [recovery-phase-flow account] :generated [recovery-phase-flow account]
:watch [watched-address-flow account]))) :watch [watched-address-flow account]
nil)))
(def view (quo.theme/with-theme view-internal)) (def view (quo.theme/with-theme view-internal))

View File

@ -33,6 +33,7 @@
(update :test-preferred-chain-ids chain-ids-string->set) (update :test-preferred-chain-ids chain-ids-string->set)
(update :type keyword) (update :type keyword)
(update :color #(if (seq %) (keyword %) constants/account-default-customization-color)) (update :color #(if (seq %) (keyword %) constants/account-default-customization-color))
(assoc :default-account? (:wallet account))
add-keys-to-account)) add-keys-to-account))
(defn rpc->accounts (defn rpc->accounts
@ -49,7 +50,8 @@
:color :colorId}) :color :colorId})
(update :prodPreferredChainIds chain-ids-set->string) (update :prodPreferredChainIds chain-ids-set->string)
(update :testPreferredChainIds chain-ids-set->string) (update :testPreferredChainIds chain-ids-set->string)
(dissoc :watch-only?))) (dissoc :watch-only?)
(dissoc :default-account?)))
(defn- rpc->balances-per-chain (defn- rpc->balances-per-chain
[token] [token]

View File

@ -2,6 +2,7 @@
(:require [quo.core :as quo] (:require [quo.core :as quo]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.config :as config]
[status-im.contexts.wallet.common.screen-base.create-or-edit-account.view [status-im.contexts.wallet.common.screen-base.create-or-edit-account.view
:as create-or-edit-account] :as create-or-edit-account]
[status-im.contexts.wallet.common.sheets.network-preferences.view [status-im.contexts.wallet.common.sheets.network-preferences.view
@ -51,7 +52,7 @@
:updated-key :name :updated-key :name
:new-value @edited-account-name}))] :new-value @edited-account-name}))]
(fn [] (fn []
(let [{:keys [name emoji address color watch-only?] (let [{:keys [name emoji address color watch-only? default-account?]
:as account} (rf/sub [:wallet/current-viewing-account]) :as account} (rf/sub [:wallet/current-viewing-account])
network-details (rf/sub [:wallet/network-preference-details]) network-details (rf/sub [:wallet/network-preference-details])
test-networks-enabled? (rf/sub [:profile/test-networks-enabled?]) test-networks-enabled? (rf/sub [:profile/test-networks-enabled?])
@ -62,13 +63,16 @@
button-disabled? (or (nil? @edited-account-name) button-disabled? (or (nil? @edited-account-name)
(= name @edited-account-name))] (= name @edited-account-name))]
[create-or-edit-account/view [create-or-edit-account/view
{:page-nav-right-side [{:icon-name :i/delete {:page-nav-right-side [(when-not default-account?
:on-press {:icon-name :i/delete
(fn [] :on-press
(rf/dispatch [:show-bottom-sheet (fn []
{:content (if (:remove-account config/wallet-feature-flags)
(fn [] (rf/dispatch [:show-bottom-sheet
[remove-account/view])}]))}] {:content
(fn []
[remove-account/view])}])
(js/alert "Feature disabled in config file")))})]
:account-name account-name :account-name account-name
:account-emoji emoji :account-emoji emoji
:account-color color :account-color color

View File

@ -7,6 +7,7 @@
[status-im.contexts.wallet.events.collectibles] [status-im.contexts.wallet.events.collectibles]
[status-im.contexts.wallet.item-types :as item-types] [status-im.contexts.wallet.item-types :as item-types]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.collection]
[utils.ethereum.chain :as chain] [utils.ethereum.chain :as chain]
[utils.ethereum.eip.eip55 :as eip55] [utils.ethereum.eip.eip55 :as eip55]
[utils.i18n :as i18n] [utils.i18n :as i18n]
@ -51,10 +52,9 @@
wallet-db (get db :wallet) wallet-db (get db :wallet)
new-account? (:new-account? wallet-db) new-account? (:new-account? wallet-db)
navigate-to-account (:navigate-to-account wallet-db)] navigate-to-account (:navigate-to-account wallet-db)]
{:db (reduce (fn [db {:keys [address] :as account}] {:db (assoc-in db
(assoc-in db [:wallet :accounts address] account)) [:wallet :accounts]
db (utils.collection/index-by :address (data-store/rpc->accounts wallet-accounts)))
(data-store/rpc->accounts wallet-accounts))
:fx [[:dispatch [:wallet/get-wallet-token]] :fx [[:dispatch [:wallet/get-wallet-token]]
[:dispatch [:wallet/request-collectibles {:start-at-index 0 :new-request? true}]] [:dispatch [:wallet/request-collectibles {:start-at-index 0 :new-request? true}]]
(when new-account? (when new-account?
@ -84,6 +84,30 @@
{:error % {:error %
:event :wallet/save-account})}]]]})) :event :wallet/save-account})}]]]}))
(rf/reg-event-fx
:wallet/show-account-deleted-toast
(fn [_ [toast-message]]
{:fx [[:dispatch [:toasts/upsert {:type :positive :text toast-message}]]]}))
(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]]]}))
(rf/reg-event-fx
:wallet/remove-account
(fn [_ [{:keys [address toast-message]}]]
{:fx [[:json-rpc/call
[{:method "accounts_deleteAccount"
:params [address]
:on-success [:wallet/remove-account-success toast-message]
:on-error #(log/info "failed to remove account "
{:error %
:event :wallet/remove-account})}]]]}))
(rf/reg-event-fx (rf/reg-event-fx
:wallet/get-wallet-token :wallet/get-wallet-token
(fn [{:keys [db]}] (fn [{:keys [db]}]
@ -133,10 +157,10 @@
(rf/reg-event-fx :wallet/create-derived-addresses (rf/reg-event-fx :wallet/create-derived-addresses
(fn [{:keys [db]} [{:keys [sha3-pwd path]} on-success]] (fn [{:keys [db]} [{:keys [sha3-pwd path]} on-success]]
(let [{:keys [wallet-root-address]} (:profile/profile db)] (let [{:keys [address]} (:profile/profile db)]
{:fx [[:json-rpc/call {:fx [[:json-rpc/call
[{:method "wallet_getDerivedAddresses" [{:method "wallet_getDerivedAddresses"
:params [sha3-pwd wallet-root-address [path]] :params [sha3-pwd address [path]]
:on-success on-success :on-success on-success
:on-error #(log/info "failed to derive address " %)}]]]}))) :on-error #(log/info "failed to derive address " %)}]]]})))

View File

@ -4,6 +4,7 @@ const transformIgnorePatterns = () => {
'@react-native-community', '@react-native-community',
'@react-native-community/blur', '@react-native-community/blur',
'react-native', 'react-native',
'react-native-config',
'react-native-background-timer', 'react-native-background-timer',
'react-native-gifted-charts', 'react-native-gifted-charts',
'react-native-haptic-feedback', 'react-native-haptic-feedback',

View File

@ -2483,5 +2483,8 @@
"not-preferred-by-receiver": "Not preferred by receiver", "not-preferred-by-receiver": "Not preferred by receiver",
"apply-changes": "Apply changes", "apply-changes": "Apply changes",
"receiver-networks-warning": "Changing these settings may result in sending tokens to networks the recipient doesn't use", "receiver-networks-warning": "Changing these settings may result in sending tokens to networks the recipient doesn't use",
"no-routes-found-confirmation": "No routes found. Token type may not be supported or you may don't have enough ETH to cover gas." "no-routes-found-confirmation": "No routes found. Token type may not be supported or you may don't have enough ETH to cover gas.",
"watched-account-removed": "Watched address has been removed",
"account-removed": "Account has been removed",
"share-address-title": "{{address}} address"
} }