Skip to content

Commit

Permalink
WIP: derivation path suggestion fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ulisesmac committed Apr 16, 2024
1 parent fbac5e1 commit f22d7aa
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 59 deletions.
87 changes: 43 additions & 44 deletions src/status_im/contexts/wallet/add_account/create_account/view.cljs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
(ns status-im.contexts.wallet.add-account.create-account.view
(:require
[clojure.string :as string]
[quo.core :as quo]
[quo.foundations.colors :as colors]
[quo.theme :as quo.theme]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[reagent.core :as reagent]
[status-im.common.emoji-picker.utils :as emoji-picker.utils]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.common.standard-authentication.core :as standard-auth]
[status-im.contexts.wallet.events.accounts]
[status-im.contexts.wallet.add-account.create-account.style :as style]
[status-im.contexts.wallet.add-account.create-account.utils :as create-account.utils]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.sheets.account-origin.view :as account-origin]
[status-im.feature-flags :as ff]
[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]))
[clojure.string :as string]
[quo.core :as quo]
[quo.foundations.colors :as colors]
[quo.theme :as quo.theme]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[reagent.core :as reagent]
[status-im.common.emoji-picker.utils :as emoji-picker.utils]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.common.standard-authentication.core :as standard-auth]
[status-im.constants :as constants]
[status-im.contexts.wallet.events.accounts]
[status-im.contexts.wallet.add-account.create-account.style :as style]
[status-im.contexts.wallet.add-account.create-account.utils :as create-account.utils]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.sheets.account-origin.view :as account-origin]
[status-im.feature-flags :as ff]
[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]))

(defn- get-keypair-data
[{:keys [title primary-keypair? new-keypair? derivation-path customization-color]}]
Expand Down Expand Up @@ -75,36 +76,33 @@
(let [{:keys [customization-color
address]} (rf/sub [:profile/profile])
{:keys [new-keypair]} (rf/sub [:wallet/create-account])
_ (println
"NEW KEYPAIR:\n "
new-keypair "\n"
"-----\n")
selected-keypair (rf/sub [:wallet/selected-keypair])
_ (println "\n"
(:key-uid selected-keypair) "\n"
"Derived from: " (:derived-from selected-keypair) "\n"
@derivation-path
"________\n")

primary? (rf/sub [:wallet/selected-keypair-primary?])
placeholder (i18n/label :t/default-account-placeholder)
create-new-keypair-account #(rf/dispatch
[: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
:account-name @account-name
:account-color @account-color
:emoji @emoji})}])
create-existing-keypair-account (fn [password]
(rf/dispatch
[:wallet/derive-address-and-add-account
{:sha3-pwd (security/safe-unmask-data password)
:address (:derived-from selected-keypair)
:emoji @emoji
:color @account-color
:path @derivation-path
:account-name @account-name}]))
(let [acc-details {:sha3-pwd (security/safe-unmask-data password)
:address (:derived-from selected-keypair)
:emoji @emoji
:color @account-color
:path @derivation-path
:account-name @account-name}]
(rf/dispatch
[:wallet/get-derived-addresses
{:account-details acc-details
:on-success (fn [derived-address-details]
;; TODO: only pass the event vector
(rf/dispatch
[:wallet/add-account
acc-details
(first derived-address-details)]))}])))
keypair-title (or (:keypair-name new-keypair)
(if primary?
(i18n/label :t/keypair-title
Expand All @@ -116,6 +114,7 @@
: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]))
[floating-button-page/view
Expand Down
24 changes: 9 additions & 15 deletions src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@
{:db (update-in db [:wallet :ui] dissoc :scanned-address)})

(rf/reg-event-fx
:wallet/create-derived-addresses
(fn [_ [{:keys [sha3-pwd address path] :as x} on-success]]
:wallet/get-derived-addresses
(fn [_ [{{:keys [sha3-pwd address path] :as x} :account-details
on-success :on-success}]]
(def --x x)
{:fx [[:json-rpc/call
[{:method "wallet_getDerivedAddresses"
Expand All @@ -187,9 +188,10 @@

(rf/reg-event-fx :wallet/add-account
(fn [{:keys [db]}
[{:keys [sha3-pwd emoji account-name color type] :or {type :generated}}
[{:keys [sha3-pwd emoji account-name color type]
:or {type :generated}}
{:keys [public-key address path]}]]
(let [lowercase-address (if address (string/lower-case address) address)
(let [lowercase-address (some-> address (string/lower-case))
key-uid (get-in db [:wallet :ui :create-account :selected-keypair-uid])
account-config {:key-uid (when (= type :generated) key-uid)
:wallet false
Expand All @@ -203,20 +205,12 @@
:colorID color}]
{:fx [[:json-rpc/call
[{:method "accounts_addAccount"
:params [(when (= type :generated) sha3-pwd) account-config]
:params [(when (= type :generated)
sha3-pwd)
account-config]
:on-success [:wallet/add-account-success lowercase-address]
:on-error #(log/info "failed to create account " % account-config)}]]]})))

;; TODO: remove superfluous event
(rf/reg-event-fx
:wallet/derive-address-and-add-account
(fn [_ [account-details]]
(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]]]})))

(defn add-keypair-and-create-account
[_ [{:keys [sha3-pwd new-keypair]}]]
(let [lowercase-address (if (:address new-keypair)
Expand Down
1 change: 1 addition & 0 deletions src/tests/contract_test/wallet_recovered_account_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
(is (= integration-constants/derivation-path (:path (first response))))))

(deftest wallet-get-derived-addressess-contract-test
;; TODO: event renamed
(h/test-async :wallet/create-derived-addresses
(fn []
(promesa/let [sha3-pwd-hash (native-module/sha3 integration-constants/password)
Expand Down

0 comments on commit f22d7aa

Please sign in to comment.