fix(wallet): Account derivation for added keypairs (#20536)

* Fix color of non-selected keypairs

* Fix pressable area in keypairs

* Make validation more robust

* Make confirm button always pressable

* Fix wrong sentence in errors

* Solve account creation by fixing a memoized callback

* Improve logging
This commit is contained in:
Ulises Manuel 2024-06-26 12:10:16 -06:00 committed by GitHub
parent b005eb8181
commit 3ce6a86e9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 53 additions and 51 deletions

View File

@ -14,9 +14,7 @@
[react-native.reanimated :as reanimated])) [react-native.reanimated :as reanimated]))
(defn drag-gesture (defn drag-gesture
[x-pos disabled? track-width sliding-complete? [x-pos disabled? track-width sliding-complete? set-sliding-complete on-complete reset-fn]
set-sliding-complete
on-complete reset-fn]
(-> (gesture/gesture-pan) (-> (gesture/gesture-pan)
(gesture/with-test-ID :slide-button-gestures) (gesture/with-test-ID :slide-button-gestures)
(gesture/enabled (not disabled?)) (gesture/enabled (not disabled?))
@ -71,14 +69,16 @@
(dimensions :thumb)) (dimensions :thumb))
[dimensions]) [dimensions])
custom-color (if (= type :danger) :danger customization-color) custom-color (if (= type :danger) :danger customization-color)
gesture (rn/use-memo #(drag-gesture x-pos gesture (rn/use-memo
disabled? (fn []
(dimensions :usable-track) (drag-gesture x-pos
sliding-complete? disabled?
set-sliding-complete (dimensions :usable-track)
on-complete sliding-complete?
reset-fn) set-sliding-complete
[sliding-complete? disabled?])] on-complete
reset-fn))
[sliding-complete? disabled? on-complete])]
[gesture/gesture-detector [gesture/gesture-detector
{:gesture gesture} {:gesture gesture}
[reanimated/view [reanimated/view

View File

@ -7,14 +7,14 @@
[{:keys [blur? customization-color theme selected? container-style]}] [{:keys [blur? customization-color theme selected? container-style]}]
(merge {:border-radius 16 (merge {:border-radius 16
:border-width 1 :border-width 1
:border-color (if selected? :padding-bottom 8
(if blur? :border-color (cond
colors/white (and selected? blur?) colors/white
(colors/resolve-color customization-color theme)) selected? (colors/resolve-color customization-color theme)
(if blur? blur? colors/white-opa-5
colors/white-opa-5 :else (colors/theme-colors colors/neutral-10
(colors/theme-colors colors/neutral-10 colors/neutral-80 theme))) colors/neutral-80
:padding-bottom 8} theme))}
container-style)) container-style))
(def header-container (def header-container

View File

@ -95,20 +95,23 @@
(defn view (defn view
[{:keys [accounts action container-style selected? on-press] :as props}] [{:keys [accounts action container-style selected? on-press] :as props}]
[rn/pressable (let [theme (quo.theme/use-theme)]
{:style (style/container (merge props [rn/pressable
{:selected? selected? {:style (style/container (assoc props
:container-style container-style})) :selected? selected?
:on-press #(when (= action :selector) (on-press))} :container-style container-style
[rn/view {:style style/header-container} :theme theme))
[avatar props] :on-press #(when (= action :selector) (on-press))
[rn/view :pointer-events :box-only}
{:style {:margin-left 8 [rn/view {:style style/header-container}
:flex 1}} [avatar props]
[title-view (assoc props :selected? selected?)] [rn/view
[details-view props]]] {:style {:margin-left 8
[rn/flat-list :flex 1}}
{:data accounts [title-view (assoc props :selected? selected?)]
:render-fn acc-list-card [details-view props]]]
:separator [rn/view {:style {:height 8}}] [rn/flat-list
:style {:padding-horizontal 8}}]]) {:data accounts
:render-fn acc-list-card
:separator [rn/view {:style {:height 8}}]
:style {:padding-horizontal 8}}]]))

View File

@ -124,7 +124,7 @@
:on-success on-success :on-success on-success
:on-error (fn [error] :on-error (fn [error]
(log/error (log/error
"Failed to resolve next path derivation path" "Failed to resolve next derivation path"
{:event :wallet/next-derivation-path {:event :wallet/next-derivation-path
:method "accounts_resolveSuggestedPathForKeypair" :method "accounts_resolveSuggestedPathForKeypair"
:error error :error error
@ -191,7 +191,7 @@
(rf/reg-event-fx (rf/reg-event-fx
:wallet/derive-address-and-add-account :wallet/derive-address-and-add-account
(fn [_ [{:keys [password derived-from-address derivation-path account-preferences]}]] (fn [_ [{:keys [password derived-from-address derivation-path account-preferences key-uid]}]]
{:fx [[:json-rpc/call {:fx [[:json-rpc/call
[{:method "wallet_getDerivedAddresses" [{:method "wallet_getDerivedAddresses"
:params [(security/safe-unmask-data password) :params [(security/safe-unmask-data password)
@ -199,9 +199,10 @@
[derivation-path]] [derivation-path]]
:on-success (fn [[derived-account]] :on-success (fn [[derived-account]]
(rf/dispatch [:wallet/add-account (rf/dispatch [:wallet/add-account
(assoc account-preferences :password password) (assoc account-preferences
:key-uid key-uid
:password password)
derived-account])) derived-account]))
:on-error #(log/info "Failed to get derived addresses" :on-error [:wallet/log-rpc-error
derived-from-address {:event :wallet/derive-address-and-add-account
%)}]]]})) :params [derived-from-address [derivation-path]]}]}]]]}))

View File

@ -105,8 +105,7 @@
[quo/bottom-actions [quo/bottom-actions
{:actions :one-action {:actions :one-action
:button-one-label (i18n/label :t/confirm-account-origin) :button-one-label (i18n/label :t/confirm-account-origin)
:button-one-props {:disabled? (= selected-keypair selected-key-uid) :button-one-props {:customization-color customization-color
:customization-color customization-color
:on-press #(rf/dispatch [:wallet/confirm-account-origin :on-press #(rf/dispatch [:wallet/confirm-account-origin
selected-key-uid])} selected-key-uid])}
:container-style style/bottom-action-container}]])) :container-style style/bottom-action-container}]]))

View File

@ -48,7 +48,6 @@
:action-props {:on-press #(rf/dispatch [:standard-auth/authorize :action-props {:on-press #(rf/dispatch [:standard-auth/authorize
{:on-auth-success on-auth-success {:on-auth-success on-auth-success
:auth-button-label (i18n/label :t/continue)}]) :auth-button-label (i18n/label :t/continue)}])
:button-text (i18n/label :t/edit) :button-text (i18n/label :t/edit)
:icon-left :i/face-id :icon-left :i/face-id
:alignment :flex-start} :alignment :flex-start}
@ -217,6 +216,7 @@
[:wallet/derive-address-and-add-account [:wallet/derive-address-and-add-account
{:password password {:password password
:derived-from-address derived-from :derived-from-address derived-from
:key-uid key-uid
:derivation-path @derivation-path :derivation-path @derivation-path
:account-preferences preferences}]))) :account-preferences preferences}])))
[derived-from])] [derived-from])]
@ -231,7 +231,7 @@
{:account-color @account-color {:account-color @account-color
:slide-button-props {:on-auth-success on-auth-success :slide-button-props {:on-auth-success on-auth-success
:disabled? (or (empty? @account-name) :disabled? (or (empty? @account-name)
(= "" @derivation-path) (string/blank? @derivation-path)
(some? error))}} (some? error))}}
[avatar [avatar
{:account-color @account-color {:account-color @account-color

View File

@ -215,13 +215,12 @@
[:dispatch [:wallet/clear-create-account]]]})) [:dispatch [:wallet/clear-create-account]]]}))
(rf/reg-event-fx :wallet/add-account (rf/reg-event-fx :wallet/add-account
(fn [{:keys [db]} (fn [_
[{:keys [password account-name emoji color type] [{:keys [key-uid password account-name emoji color type]
:or {type :generated}} :or {type :generated}}
{:keys [public-key address path] :as _derived-account}]] {:keys [public-key address path] :as _derived-account}]]
(let [lowercase-address (some-> address (let [lowercase-address (some-> address
(string/lower-case)) string/lower-case)
key-uid (get-in db [:wallet :ui :create-account :selected-keypair-uid])
account-config {:key-uid (when (= type :generated) key-uid) account-config {:key-uid (when (= type :generated) key-uid)
:wallet false :wallet false
:chat false :chat false