mirror of
https://github.com/status-im/status-react.git
synced 2025-01-23 17:29:08 +00:00
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:
parent
b005eb8181
commit
3ce6a86e9b
@ -14,9 +14,7 @@
|
||||
[react-native.reanimated :as reanimated]))
|
||||
|
||||
(defn drag-gesture
|
||||
[x-pos disabled? track-width sliding-complete?
|
||||
set-sliding-complete
|
||||
on-complete reset-fn]
|
||||
[x-pos disabled? track-width sliding-complete? set-sliding-complete on-complete reset-fn]
|
||||
(-> (gesture/gesture-pan)
|
||||
(gesture/with-test-ID :slide-button-gestures)
|
||||
(gesture/enabled (not disabled?))
|
||||
@ -71,14 +69,16 @@
|
||||
(dimensions :thumb))
|
||||
[dimensions])
|
||||
custom-color (if (= type :danger) :danger customization-color)
|
||||
gesture (rn/use-memo #(drag-gesture x-pos
|
||||
disabled?
|
||||
(dimensions :usable-track)
|
||||
sliding-complete?
|
||||
set-sliding-complete
|
||||
on-complete
|
||||
reset-fn)
|
||||
[sliding-complete? disabled?])]
|
||||
gesture (rn/use-memo
|
||||
(fn []
|
||||
(drag-gesture x-pos
|
||||
disabled?
|
||||
(dimensions :usable-track)
|
||||
sliding-complete?
|
||||
set-sliding-complete
|
||||
on-complete
|
||||
reset-fn))
|
||||
[sliding-complete? disabled? on-complete])]
|
||||
[gesture/gesture-detector
|
||||
{:gesture gesture}
|
||||
[reanimated/view
|
||||
|
@ -7,14 +7,14 @@
|
||||
[{:keys [blur? customization-color theme selected? container-style]}]
|
||||
(merge {:border-radius 16
|
||||
:border-width 1
|
||||
:border-color (if selected?
|
||||
(if blur?
|
||||
colors/white
|
||||
(colors/resolve-color customization-color theme))
|
||||
(if blur?
|
||||
colors/white-opa-5
|
||||
(colors/theme-colors colors/neutral-10 colors/neutral-80 theme)))
|
||||
:padding-bottom 8}
|
||||
:padding-bottom 8
|
||||
:border-color (cond
|
||||
(and selected? blur?) colors/white
|
||||
selected? (colors/resolve-color customization-color theme)
|
||||
blur? colors/white-opa-5
|
||||
:else (colors/theme-colors colors/neutral-10
|
||||
colors/neutral-80
|
||||
theme))}
|
||||
container-style))
|
||||
|
||||
(def header-container
|
||||
|
@ -95,20 +95,23 @@
|
||||
|
||||
(defn view
|
||||
[{:keys [accounts action container-style selected? on-press] :as props}]
|
||||
[rn/pressable
|
||||
{:style (style/container (merge props
|
||||
{:selected? selected?
|
||||
:container-style container-style}))
|
||||
:on-press #(when (= action :selector) (on-press))}
|
||||
[rn/view {:style style/header-container}
|
||||
[avatar props]
|
||||
[rn/view
|
||||
{:style {:margin-left 8
|
||||
:flex 1}}
|
||||
[title-view (assoc props :selected? selected?)]
|
||||
[details-view props]]]
|
||||
[rn/flat-list
|
||||
{:data accounts
|
||||
:render-fn acc-list-card
|
||||
:separator [rn/view {:style {:height 8}}]
|
||||
:style {:padding-horizontal 8}}]])
|
||||
(let [theme (quo.theme/use-theme)]
|
||||
[rn/pressable
|
||||
{:style (style/container (assoc props
|
||||
:selected? selected?
|
||||
:container-style container-style
|
||||
:theme theme))
|
||||
:on-press #(when (= action :selector) (on-press))
|
||||
:pointer-events :box-only}
|
||||
[rn/view {:style style/header-container}
|
||||
[avatar props]
|
||||
[rn/view
|
||||
{:style {:margin-left 8
|
||||
:flex 1}}
|
||||
[title-view (assoc props :selected? selected?)]
|
||||
[details-view props]]]
|
||||
[rn/flat-list
|
||||
{:data accounts
|
||||
:render-fn acc-list-card
|
||||
:separator [rn/view {:style {:height 8}}]
|
||||
:style {:padding-horizontal 8}}]]))
|
||||
|
@ -124,7 +124,7 @@
|
||||
:on-success on-success
|
||||
:on-error (fn [error]
|
||||
(log/error
|
||||
"Failed to resolve next path derivation path"
|
||||
"Failed to resolve next derivation path"
|
||||
{:event :wallet/next-derivation-path
|
||||
:method "accounts_resolveSuggestedPathForKeypair"
|
||||
:error error
|
||||
@ -191,7 +191,7 @@
|
||||
|
||||
(rf/reg-event-fx
|
||||
: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
|
||||
[{:method "wallet_getDerivedAddresses"
|
||||
:params [(security/safe-unmask-data password)
|
||||
@ -199,9 +199,10 @@
|
||||
[derivation-path]]
|
||||
:on-success (fn [[derived-account]]
|
||||
(rf/dispatch [:wallet/add-account
|
||||
(assoc account-preferences :password password)
|
||||
(assoc account-preferences
|
||||
:key-uid key-uid
|
||||
:password password)
|
||||
derived-account]))
|
||||
:on-error #(log/info "Failed to get derived addresses"
|
||||
derived-from-address
|
||||
%)}]]]}))
|
||||
|
||||
:on-error [:wallet/log-rpc-error
|
||||
{:event :wallet/derive-address-and-add-account
|
||||
:params [derived-from-address [derivation-path]]}]}]]]}))
|
||||
|
@ -105,8 +105,7 @@
|
||||
[quo/bottom-actions
|
||||
{:actions :one-action
|
||||
:button-one-label (i18n/label :t/confirm-account-origin)
|
||||
:button-one-props {:disabled? (= selected-keypair selected-key-uid)
|
||||
:customization-color customization-color
|
||||
:button-one-props {:customization-color customization-color
|
||||
:on-press #(rf/dispatch [:wallet/confirm-account-origin
|
||||
selected-key-uid])}
|
||||
:container-style style/bottom-action-container}]]))
|
||||
|
@ -48,7 +48,6 @@
|
||||
:action-props {:on-press #(rf/dispatch [:standard-auth/authorize
|
||||
{:on-auth-success on-auth-success
|
||||
:auth-button-label (i18n/label :t/continue)}])
|
||||
|
||||
:button-text (i18n/label :t/edit)
|
||||
:icon-left :i/face-id
|
||||
:alignment :flex-start}
|
||||
@ -217,6 +216,7 @@
|
||||
[:wallet/derive-address-and-add-account
|
||||
{:password password
|
||||
:derived-from-address derived-from
|
||||
:key-uid key-uid
|
||||
:derivation-path @derivation-path
|
||||
:account-preferences preferences}])))
|
||||
[derived-from])]
|
||||
@ -231,7 +231,7 @@
|
||||
{:account-color @account-color
|
||||
:slide-button-props {:on-auth-success on-auth-success
|
||||
:disabled? (or (empty? @account-name)
|
||||
(= "" @derivation-path)
|
||||
(string/blank? @derivation-path)
|
||||
(some? error))}}
|
||||
[avatar
|
||||
{:account-color @account-color
|
||||
|
@ -215,13 +215,12 @@
|
||||
[:dispatch [:wallet/clear-create-account]]]}))
|
||||
|
||||
(rf/reg-event-fx :wallet/add-account
|
||||
(fn [{:keys [db]}
|
||||
[{:keys [password account-name emoji color type]
|
||||
(fn [_
|
||||
[{:keys [key-uid password account-name emoji color type]
|
||||
:or {type :generated}}
|
||||
{:keys [public-key address path] :as _derived-account}]]
|
||||
(let [lowercase-address (some-> address
|
||||
(string/lower-case))
|
||||
key-uid (get-in db [:wallet :ui :create-account :selected-keypair-uid])
|
||||
string/lower-case)
|
||||
account-config {:key-uid (when (= type :generated) key-uid)
|
||||
:wallet false
|
||||
:chat false
|
||||
|
Loading…
x
Reference in New Issue
Block a user