Skip to content

Commit

Permalink
WIP: Create an account based on a keypair
Browse files Browse the repository at this point in the history
  • Loading branch information
ulisesmac committed Apr 8, 2024
1 parent 55b1600 commit d33b0dc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/status_im/contexts/wallet/create_account/utils.cljs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)}]))
32 changes: 17 additions & 15 deletions src/status_im/contexts/wallet/create_account/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand Down Expand Up @@ -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])
Expand All @@ -94,25 +95,27 @@
: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
{:name (:name selected-keypair)})
(: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]))
Expand All @@ -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))
Expand Down
21 changes: 12 additions & 9 deletions src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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]]]}))

Expand All @@ -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]}]]
Expand Down

0 comments on commit d33b0dc

Please sign in to comment.