Compare commits

...
Author SHA1 Message Date
Ulises M 127903f077 Remove deprecated custom-color usage 2024-01-26 21:18:57 -06:00
Ulises M a468b62384 Fix linear gradient breaking while deleting an account 2024-01-26 21:17:08 -06:00
Rende11 07258a653a Clean up code issues 2024-01-27 01:51:19 +03:00
Rende11 e81961b3cb Connect remove account rpc request
Remove account

Don't remove default account

Fix account path
2024-01-26 18:48:42 +03:00
7 changed files with 98 additions and 48 deletions
@@ -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))
@@ -32,12 +32,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 +93,16 @@
#(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 #(rf/dispatch [:show-bottom-sheet
(fn [] {:content
[remove-account/view])}])}]]] (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}]
@@ -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))
@@ -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]
@@ -51,7 +51,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 +62,14 @@
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 (rf/dispatch [:show-bottom-sheet
(fn [] {:content
[remove-account/view])}]))}] (fn []
[remove-account/view])}]))})]
:account-name account-name :account-name account-name
:account-emoji emoji :account-emoji emoji
:account-color color :account-color color
+30 -6
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 " %)}]]]})))
+4 -1
View File
@@ -2478,5 +2478,8 @@
"preferred-by-receiver": "Preferred by receiver", "preferred-by-receiver": "Preferred by receiver",
"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",
"watched-account-removed": "Watched address has been removed",
"account-removed": "Account has been removed",
"share-address-title": "{{address}} address"
} }