Skip to content

Commit

Permalink
WIP: trying to call import mnemonic
Browse files Browse the repository at this point in the history
  • Loading branch information
ulisesmac committed Apr 16, 2024
1 parent f22d7aa commit 8f51bab
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 25 additions & 24 deletions src/status_im/contexts/wallet/add_account/create_account/utils.cljs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/contexts/wallet/effects.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}])))))
34 changes: 26 additions & 8 deletions src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8f51bab

Please sign in to comment.