From d33b0dce20762214d83810ace14924f91ad1c2db Mon Sep 17 00:00:00 2001 From: Ulises M Date: Mon, 8 Apr 2024 17:53:45 -0600 Subject: [PATCH] WIP: Create an account based on a keypair --- .../contexts/wallet/create_account/utils.cljs | 4 +-- .../contexts/wallet/create_account/view.cljs | 32 ++++++++++--------- src/status_im/contexts/wallet/events.cljs | 21 ++++++------ 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/status_im/contexts/wallet/create_account/utils.cljs b/src/status_im/contexts/wallet/create_account/utils.cljs index 7af9ddb1e8ed..4ceda5aaa682 100644 --- a/src/status_im/contexts/wallet/create_account/utils.cljs +++ b/src/status_im/contexts/wallet/create_account/utils.cljs @@ -1,7 +1,7 @@ (ns status-im.contexts.wallet.create-account.utils) (defn prepare-new-keypair - [{:keys [new-keypair address account-name account-color emoji derivation-path]}] + [{:keys [new-keypair address account-name account-color emoji]}] (assoc new-keypair :name (:keypair-name new-keypair) :key-uid (:keyUid new-keypair) @@ -15,5 +15,5 @@ :type :seed :emoji emoji :colorID account-color - :path derivation-path + :path "m/44'/60'/0'/0/0" :address (:address new-keypair)}])) diff --git a/src/status_im/contexts/wallet/create_account/view.cljs b/src/status_im/contexts/wallet/create_account/view.cljs index c7ecc7c4ee97..383e557cadc5 100644 --- a/src/status_im/contexts/wallet/create_account/view.cljs +++ b/src/status_im/contexts/wallet/create_account/view.cljs @@ -19,6 +19,7 @@ [utils.i18n :as i18n] [utils.re-frame :as rf] [utils.responsiveness :as responsiveness] + [status-im.common.json-rpc.events :as json-rpc] [utils.security.core :as security] [utils.string])) @@ -75,7 +76,7 @@ address]} (rf/sub [:profile/profile]) {:keys [new-keypair]} (rf/sub [:wallet/create-account]) _ (println - "\n" + "NEW KEYPAIR:\n " new-keypair "\n" "-----\n") selected-keypair (rf/sub [:wallet/selected-keypair]) @@ -94,15 +95,17 @@ :address address :account-name @account-name :account-color @account-color - :emoji @emoji - :derivation-path @derivation-path})}]) - create-existing-keypair-account #(rf/dispatch - [:wallet/derive-address-and-add-account - {:sha3-pwd (security/safe-unmask-data %) - :emoji @emoji - :color @account-color - :path @derivation-path - :account-name @account-name}]) + :emoji @emoji})}]) + create-existing-keypair-account (fn [password] + (println "DERIVE AND ADD!") + (def --p (security/safe-unmask-data password)) + (rf/dispatch + [:wallet/derive-address-and-add-account + {:sha3-pwd (security/safe-unmask-data password) + :emoji @emoji + :color @account-color + :path @derivation-path + :account-name @account-name}])) keypair-title (or (:keypair-name new-keypair) (if primary? (i18n/label :t/keypair-title @@ -110,9 +113,9 @@ (:name selected-keypair)))] (rn/use-effect #(rf/dispatch - [:wallet/new-derivation-path-for-selected-keypair {:on-success set-derivation-path - :keypair-uid (or (:keyUid new-keypair) - (:key-uid selected-keypair))}]) + [:wallet/new-derivation-path {:on-success set-derivation-path + :keypair-uid (or (:keyUid new-keypair) + (:key-uid selected-keypair))}]) [(:key-uid selected-keypair) (:keyUid new-keypair)]) (rn/use-unmount #(rf/dispatch [:wallet/clear-new-keypair])) @@ -135,8 +138,7 @@ :on-auth-success (fn [password] (if new-keypair (create-new-keypair-account password) - (create-existing-keypair-account - password))) + (create-existing-keypair-account password))) :auth-button-label (i18n/label :t/confirm) :disabled? (or (empty? @account-name) (= "" @derivation-path)) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 10b3ff35f1b2..f82a5253f877 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -169,9 +169,12 @@ [{:keys [db]}] {:db (update-in db [:wallet :ui] dissoc :scanned-address)}) -(rf/reg-event-fx :wallet/create-derived-addresses - (fn [{:keys [db]} [{:keys [sha3-pwd path]} on-success]] +(rf/reg-event-fx + :wallet/create-derived-addresses + (fn [{:keys [db]} [{:keys [sha3-pwd path] :as x} on-success]] + (def --x x) (let [{:keys [address]} (:profile/profile db)] + (def --a address) {:fx [[:json-rpc/call [{:method "wallet_getDerivedAddresses" :params [sha3-pwd address [path]] @@ -180,10 +183,9 @@ (rf/reg-event-fx :wallet/add-account-success (fn [{:keys [db]} [address]] - {:db (update db - :wallet assoc - :navigate-to-account address - :new-account? true) + {:db (-> db + (assoc-in [:wallet :navigate-to-account] address) + (assoc-in [:wallet :new-account?] true)) :fx [[:dispatch [:wallet/get-accounts]] [:dispatch [:wallet/clear-new-keypair]]]})) @@ -207,15 +209,16 @@ [{:method "accounts_addAccount" :params [(when (= type :generated) sha3-pwd) account-config] :on-success [:wallet/add-account-success lowercase-address] - :on-error #(log/info "failed to create account " %)}]]]}))) + :on-error #(log/info "failed to create account " % account-config)}]]]}))) (rf/reg-event-fx :wallet/derive-address-and-add-account - (fn [_ [account-details]] + (fn [_ [account-details derive-from]] (let [on-success (fn [derived-address-details] (rf/dispatch [:wallet/add-account account-details (first derived-address-details)]))] - {:fx [[:dispatch [:wallet/create-derived-addresses account-details on-success]]]}))) + {:fx [[:dispatch + [:wallet/create-derived-addresses account-details on-success]]]}))) (defn add-keypair-and-create-account [_ [{:keys [sha3-pwd new-keypair]}]]