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]))
(defn- view-internal
[{:keys [customization-color opacity container-style height] :or {customization-color :blue}}]
(let [color-top (colors/custom-color customization-color 50 20)
color-bottom (colors/custom-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)}]))
[{:keys [customization-color opacity container-style height]
:or {customization-color :blue}}]
;; `when` added for safety, `linear-gradient` will break if `nil` is passed,
;; the `:or` destructuring won't work because it's only applied when the
;; `:customization-color` key is non-existent. While deleting an account the key exists
;; and has a `nil` value.
(when customization-color
(let [color-top (colors/resolve-color customization-color 50 20)
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))
@@ -32,12 +32,13 @@
(defn- options
[{:keys [theme show-account-selector? options-height]}]
(let [{:keys [name color emoji address watch-only?]} (rf/sub [:wallet/current-viewing-account])
network-preference-details (rf/sub [:wallet/network-preference-details])
multichain-address (utils/get-multichain-address
network-preference-details
address)
share-title (str name " " (i18n/label :t/address))]
(let [{:keys [name color emoji address watch-only?
default-account?]} (rf/sub [:wallet/current-viewing-account])
network-preference-details (rf/sub [:wallet/network-preference-details])
multichain-address (utils/get-multichain-address
network-preference-details
address)
share-title (i18n/label :t/share-address-title {:address name})]
[rn/view
{:on-layout #(reset! options-height (oops/oget % "nativeEvent.layout.height"))
:style (when show-account-selector? style/options-container)}
@@ -92,15 +93,16 @@
#(rf/dispatch [:wallet/share-account
{:title share-title :content multichain-address}])
600))}
{:add-divider? (not show-account-selector?)
:icon :i/delete
:accessibility-label :remove-account
:label (i18n/label :t/remove-account)
:danger? true
:on-press #(rf/dispatch [:show-bottom-sheet
{:content
(fn []
[remove-account/view])}])}]]]
(when-not default-account?
{:add-divider? (not show-account-selector?)
:icon :i/delete
:accessibility-label :remove-account
:label (i18n/label :t/remove-account)
:danger? true
:on-press #(rf/dispatch [:show-bottom-sheet
{:content
(fn []
[remove-account/view])}])})]]]
(when show-account-selector?
[:<>
[quo/divider-line {:container-style style/divider-label}]
@@ -11,13 +11,17 @@
[utils.re-frame :as rf]))
(defn- footer
[{:keys [submit-disabled?]}]
[{: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 #(js/alert "Will be implemented")
:type :danger
: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])
@@ -26,7 +30,7 @@
(defn- recovery-phase-flow
[]
(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)]
[:<>
[quo/drawer-top
@@ -64,10 +68,13 @@
:checked? @confirmed?
:on-change #(swap! confirmed? not)}]
[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
[{:keys [name emoji color] :as _account}]
[{:keys [address name emoji color] :as _account}]
[:<>
[quo/drawer-top
{:title (i18n/label :t/remove-watched-address-title)
@@ -79,13 +86,17 @@
[rn/view {:style style/desc-container}
[quo/text {:weight :medium}
(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
[]
(let [{:keys [type] :as account} (rf/sub [:wallet/current-viewing-account])]
(case type
:generated [recovery-phase-flow account]
:watch [watched-address-flow account])))
:watch [watched-address-flow account]
nil)))
(def view (quo.theme/with-theme view-internal))
@@ -33,6 +33,7 @@
(update :test-preferred-chain-ids chain-ids-string->set)
(update :type keyword)
(update :color #(if (seq %) (keyword %) constants/account-default-customization-color))
(assoc :default-account? (:wallet account))
add-keys-to-account))
(defn rpc->accounts
@@ -49,7 +50,8 @@
:color :colorId})
(update :prodPreferredChainIds chain-ids-set->string)
(update :testPreferredChainIds chain-ids-set->string)
(dissoc :watch-only?)))
(dissoc :watch-only?)
(dissoc :default-account?)))
(defn- rpc->balances-per-chain
[token]
@@ -51,7 +51,7 @@
:updated-key :name
:new-value @edited-account-name}))]
(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])
network-details (rf/sub [:wallet/network-preference-details])
test-networks-enabled? (rf/sub [:profile/test-networks-enabled?])
@@ -62,13 +62,14 @@
button-disabled? (or (nil? @edited-account-name)
(= name @edited-account-name))]
[create-or-edit-account/view
{:page-nav-right-side [{:icon-name :i/delete
:on-press
(fn []
(rf/dispatch [:show-bottom-sheet
{:content
(fn []
[remove-account/view])}]))}]
{:page-nav-right-side [(when-not default-account?
{:icon-name :i/delete
:on-press
(fn []
(rf/dispatch [:show-bottom-sheet
{:content
(fn []
[remove-account/view])}]))})]
:account-name account-name
:account-emoji emoji
:account-color color
+30 -6
View File
@@ -7,6 +7,7 @@
[status-im.contexts.wallet.events.collectibles]
[status-im.contexts.wallet.item-types :as item-types]
[taoensso.timbre :as log]
[utils.collection]
[utils.ethereum.chain :as chain]
[utils.ethereum.eip.eip55 :as eip55]
[utils.i18n :as i18n]
@@ -51,10 +52,9 @@
wallet-db (get db :wallet)
new-account? (:new-account? wallet-db)
navigate-to-account (:navigate-to-account wallet-db)]
{:db (reduce (fn [db {:keys [address] :as account}]
(assoc-in db [:wallet :accounts address] account))
db
(data-store/rpc->accounts wallet-accounts))
{:db (assoc-in db
[:wallet :accounts]
(utils.collection/index-by :address (data-store/rpc->accounts wallet-accounts)))
:fx [[:dispatch [:wallet/get-wallet-token]]
[:dispatch [:wallet/request-collectibles {:start-at-index 0 :new-request? true}]]
(when new-account?
@@ -84,6 +84,30 @@
{:error %
: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
:wallet/get-wallet-token
(fn [{:keys [db]}]
@@ -133,10 +157,10 @@
(rf/reg-event-fx :wallet/create-derived-addresses
(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
[{:method "wallet_getDerivedAddresses"
:params [sha3-pwd wallet-root-address [path]]
:params [sha3-pwd address [path]]
:on-success on-success
:on-error #(log/info "failed to derive address " %)}]]]})))
+4 -1
View File
@@ -2478,5 +2478,8 @@
"preferred-by-receiver": "Preferred by receiver",
"not-preferred-by-receiver": "Not preferred by receiver",
"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"
}