From 8f51babd432649a7a4f87119f12a6d0565709504 Mon Sep 17 00:00:00 2001 From: Ulises M Date: Tue, 16 Apr 2024 09:23:19 -0600 Subject: [PATCH] WIP: trying to call import mnemonic --- .../new_keypair/check_your_backup/view.cljs | 4 +- .../add_account/create_account/utils.cljs | 49 ++++++++++--------- .../add_account/create_account/view.cljs | 8 +-- src/status_im/contexts/wallet/effects.cljs | 2 +- src/status_im/contexts/wallet/events.cljs | 34 ++++++++++--- 5 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/status_im/contexts/wallet/add_account/create_account/new_keypair/check_your_backup/view.cljs b/src/status_im/contexts/wallet/add_account/create_account/new_keypair/check_your_backup/view.cljs index 9d443f24fa2a..c68bf1110b09 100644 --- a/src/status_im/contexts/wallet/add_account/create_account/new_keypair/check_your_backup/view.cljs +++ b/src/status_im/contexts/wallet/add_account/create_account/new_keypair/check_your_backup/view.cljs @@ -79,8 +79,8 @@ (reset! incorrect-count 0) (reset! show-error? false) (when (= @quiz-index questions-count) - (rf/dispatch [:navigate-to - :screen/wallet.keypair-name]))) + (rf/dispatch + [:navigate-to :screen/wallet.keypair-name]))) (do (when (> @incorrect-count 0) (rf/dispatch [:show-bottom-sheet diff --git a/src/status_im/contexts/wallet/add_account/create_account/utils.cljs b/src/status_im/contexts/wallet/add_account/create_account/utils.cljs index 880a4a9bb901..3c9938e4ddcb 100644 --- a/src/status_im/contexts/wallet/add_account/create_account/utils.cljs +++ b/src/status_im/contexts/wallet/add_account/create_account/utils.cljs @@ -1,33 +1,34 @@ (ns status-im.contexts.wallet.add-account.create-account.utils) (defn prepare-new-keypair - [{:keys [new-keypair account-name account-color emoji]}] - (let [base-account (val (first (:derived new-keypair)))] - (assoc new-keypair + [{{:keys [keypair-name keyUid publicKey derived address] + :as new-keypair} :new-keypair + {:keys [account-name account-color emoji]} :new-account}] + (let [account-to-create (val (first derived))] + {:key-uid keyUid + :mnemonic (:mnemonic new-keypair) + :name keypair-name + :type :seed + :derived-from address + :accounts [{:address (:address account-to-create) + :type :seed + :name account-name + :emoji emoji ;; what public key? + :colorID account-color + :key-uid keyUid + :public-key (:publicKey account-to-create) + :path "m/44'/60'/0'/0/0"}]}) + + + #_(assoc new-keypair :name (:keypair-name new-keypair) :key-uid (:keyUid new-keypair) - :derived-from (:address new-keypair) + :derived-from address :type :seed - :accounts [{:keypair-name (:keypair-name new-keypair) - :key-uid (:keyUid new-keypair) - :seed-phrase (:mnemonic new-keypair) - :public-key (:publicKey base-account) - :type :seed - :name account-name - :emoji emoji - :colorID account-color - :path "m/44'/60'/0'/0" - :address (:address base-account)}])) - - #_(assoc new-keypair - :name (:keypair-name new-keypair) - :key-uid (:keyUid new-keypair) - :derived-from address - :type :seed - :accounts [{:keypair-name (:keypair-name new-keypair) - :key-uid (:keyUid new-keypair) - :seed-phrase (:mnemonic new-keypair) - :public-key (:publicKey new-keypair) + :accounts [{:keypair-name (:keypair-name new-keypair) + :key-uid (:keyUid new-keypair) + :seed-phrase (:mnemonic new-keypair) + :public-key (:publicKey new-keypair) :type :seed :name account-name :emoji emoji diff --git a/src/status_im/contexts/wallet/add_account/create_account/view.cljs b/src/status_im/contexts/wallet/add_account/create_account/view.cljs index 67d882932529..09c0631e2500 100644 --- a/src/status_im/contexts/wallet/add_account/create_account/view.cljs +++ b/src/status_im/contexts/wallet/add_account/create_account/view.cljs @@ -83,10 +83,10 @@ [:wallet/add-keypair-and-create-account {:sha3-pwd (security/safe-unmask-data %) :new-keypair (create-account.utils/prepare-new-keypair - {:new-keypair new-keypair - :account-name @account-name - :account-color @account-color - :emoji @emoji})}]) + {:new-keypair new-keypair + :new-account {:account-name @account-name + :account-color @account-color + :emoji @emoji}})}]) create-existing-keypair-account (fn [password] (let [acc-details {:sha3-pwd (security/safe-unmask-data password) :address (:derived-from selected-keypair) diff --git a/src/status_im/contexts/wallet/effects.cljs b/src/status_im/contexts/wallet/effects.cljs index bdad187eefa4..b7590bc2307f 100644 --- a/src/status_im/contexts/wallet/effects.cljs +++ b/src/status_im/contexts/wallet/effects.cljs @@ -14,7 +14,7 @@ (fn [{:keys [secret-phrase keypair-name]}] (native-module/create-account-from-mnemonic {:MnemonicPhrase (string/join " " secret-phrase) - :paths ["m/44'/60'/0'/0"]} + :paths ["m/44'/60'/0'/0/0"]} (fn [new-keypair] (rf/dispatch [:wallet/new-keypair-created {:new-keypair (assoc new-keypair :keypair-name keypair-name)}]))))) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 3d3bb6d0b745..9ec6b7e1c946 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -211,16 +211,34 @@ :on-success [:wallet/add-account-success lowercase-address] :on-error #(log/info "failed to create account " % account-config)}]]]}))) +(rf/reg-event-fx + :wallet/create-keypair-with-account + (fn [_ [{:keys [sha3-pwd new-keypair address]}]] + {:fx [[:json-rpc/call + [{:method "accounts_addKeypair" + :params [sha3-pwd new-keypair] + :on-success [:wallet/add-account-success address] + :on-error #(log/info "failed to create keypair " %)}]]]} + )) + (defn add-keypair-and-create-account - [_ [{:keys [sha3-pwd new-keypair]}]] - (let [lowercase-address (if (:address new-keypair) - (string/lower-case (:address new-keypair)) - (:address new-keypair))] + [_ [{:keys [sha3-pwd new-keypair :as x]}]] + (def -p x) + (def --c [sha3-pwd new-keypair]) + (let [lowercase-address (some-> new-keypair :address string/lower-case)] {:fx [[:json-rpc/call - [{:method "accounts_addKeypair" - :params [sha3-pwd new-keypair] - :on-success [:wallet/add-account-success lowercase-address] - :on-error #(log/info "failed to create keypair " %)}]]]})) + [{:method "accounts_importMnemonic" + :params [sha3-pwd (:mnemonic new-keypair)] + :on-success #(js/alert %) + #_[:wallet/create-keypair-with-account {:sha3-pwd sha3-pwd + :new-keypair new-keypair + :address lowercase-address}] + :on-error #(log/info "failed to import Mnemonic " %)}]]]} + #_{:fx [[:json-rpc/call + [{:method "accounts_addKeypair" + :params [sha3-pwd new-keypair] + :on-success [:wallet/add-account-success lowercase-address] + :on-error #(log/info "failed to create keypair " %)}]]]})) (rf/reg-event-fx :wallet/add-keypair-and-create-account add-keypair-and-create-account)