Skip to content

Commit

Permalink
Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ulisesmac committed May 21, 2024
1 parent 340f678 commit 1a6d3a3
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@

(defn store-new-seed-phrase
[{:keys [db]} [{:keys [seed-phrase random-phrase]}]]
{:db (update-in db [:wallet :ui :create-account :new-keypair] assoc
{:db (update-in db
[:wallet :ui :create-account :new-keypair]
assoc
:seed-phrase seed-phrase
:random-phrase random-phrase)
:fx [[:dispatch-later [{:ms 20
:dispatch [:navigate-to :screen/wallet.confirm-backup]}]]]})
:fx [[:dispatch-later
[{:ms 20
:dispatch [:navigate-to :screen/wallet.confirm-backup]}]]]})

(rf/reg-event-fx :wallet/store-new-seed-phrase store-new-seed-phrase)

Expand All @@ -57,11 +60,14 @@
[{:keys [db]} [{:keys [new-account-data keypair-name]}]]
(let [new-account (update new-account-data :mnemonic security/mask-data)]
{:db (-> db
(update-in [:wallet :ui :create-account :new-keypair] assoc
(update-in [:wallet :ui :create-account :new-keypair]
assoc
:new-account-data new-account
:keypair-name keypair-name)
(update-in [:wallet :ui :create-account :new-keypair] dissoc
:seed-phrase :random-phrase))
:keypair-name keypair-name)
(update-in [:wallet :ui :create-account :new-keypair]
dissoc
:seed-phrase
:random-phrase))
:fx [[:dispatch [:navigate-back-to :screen/wallet.create-account]]]}))

(rf/reg-event-fx :wallet/store-account-generated store-account-generated)
Expand Down Expand Up @@ -140,15 +146,15 @@
(fn [{db :db} [password account-preferences]]
(let [{:keys [keypair-name
new-account-data]} (-> db :wallet :ui :create-account :new-keypair)
keypair-with-account (create-account.utils/prepare-new-account
{:keypair-name keypair-name
:account-data new-account-data
:account-preferences account-preferences})
new-address (some-> new-account-data
(create-account.utils/first-derived-account)
(:address)
(string/lower-case))
unmasked-password (security/safe-unmask-data password)]
keypair-with-account (create-account.utils/prepare-new-account
{:keypair-name keypair-name
:account-data new-account-data
:account-preferences account-preferences})
new-address (some-> new-account-data
(create-account.utils/first-derived-account)
(:address)
(string/lower-case))
unmasked-password (security/safe-unmask-data password)]
{:fx [[:json-rpc/call
[{:method "accounts_addKeypair"
:params [unmasked-password keypair-with-account]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(ns status-im.contexts.wallet.add-account.create-account.events-test
(:require
[cljs.test :refer-macros [deftest is]]
[matcher-combinators.test]
[status-im.constants :as constants]
[status-im.contexts.wallet.add-account.create-account.events :as events]
[utils.security.core :as security]))
[cljs.test :refer-macros [deftest is]]
[matcher-combinators.test]
[status-im.constants :as constants]
[status-im.contexts.wallet.add-account.create-account.events :as events]
[utils.security.core :as security]))

(deftest confirm-account-origin
(let [db {:wallet {:ui {:create-account {}}}}
Expand All @@ -25,7 +25,7 @@

(deftest store-account-generated
(let [db {:wallet {:ui {:create-account
{:new-keypair {:seed-phrase "test-secret",
{:new-keypair {:seed-phrase "test-secret"
:random-phrase "random-test"}}}}}
mnemonic "my mnemonic"
masked-mnemonic (security/mask-data mnemonic)
Expand All @@ -43,8 +43,14 @@
[:wallet :ui :create-account :new-keypair :new-account-data]
dissoc
:mnemonic)
unmask-mnemonic #(-> % :wallet :ui :create-account :new-keypair :new-account-data
:mnemonic security/safe-unmask-data)]
unmask-mnemonic #(-> %
:wallet
:ui
:create-account
:new-keypair
:new-account-data
:mnemonic
security/safe-unmask-data)]
(is (= (remove-mnemonic result-db) (remove-mnemonic expected-db)))
(is (= (unmask-mnemonic result-db) (unmask-mnemonic expected-db)))))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
:button-one-props {:disabled? (some false? (vals @checked?))
:customization-color customization-color
:on-press #(rf/dispatch [:wallet/store-new-seed-phrase
{:seed-phrase (security/mask-data @seed-phrase)
{:seed-phrase (security/mask-data
@seed-phrase)
:random-phrase @random-phrase}])}}]
[quo/text
{:size :paragraph-2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns status-im.contexts.wallet.add-account.create-account.utils
(:require [status-im.constants :as constants]))

(defn first-derived-account [account-data]
(defn first-derived-account
[account-data]
(-> account-data :derived first val))

(defn prepare-new-account
Expand Down
140 changes: 77 additions & 63 deletions src/status_im/contexts/wallet/add_account/create_account/view.cljs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
(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.constants :as constants]
[status-im.contexts.wallet.add-account.create-account.style :as style]
[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]
[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.add-account.create-account.style :as style]
[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]
[utils.string]))

(defn- get-keypair-data
[{:keys [title primary-keypair? new-keypair? derivation-path customization-color]}]
Expand Down Expand Up @@ -54,7 +54,8 @@
:description :text
:description-props {:text formatted-path}}]))

(defn- avatar [{:keys [account-color emoji on-select-emoji]}]
(defn- avatar
[{:keys [account-color emoji on-select-emoji]}]
[rn/view {:style style/account-avatar-container}
[quo/account-avatar
{:customization-color account-color
Expand All @@ -70,7 +71,8 @@
:container-style style/reaction-button-container}
:i/reaction]])

(defn- input [_]
(defn- input
[_]
(let [placeholder (i18n/label :t/default-account-placeholder)]
(fn [{:keys [account-color account-name on-change-text]}]
[quo/title-input
Expand All @@ -83,7 +85,8 @@
:default-value account-name
:container-style style/title-input-container}])))

(defn- color-picker [_]
(defn- color-picker
[_]
(let [{window-width :width} (rn/get-window)
color-picker-style {:padding-vertical 12
:padding-left (responsiveness/iphone-11-Pro-20-pixel-from-width
Expand All @@ -103,7 +106,8 @@
:on-change set-account-color
:container-style color-picker-style}]])])))

(defn- new-account-origin [{:keys [keypair-title derivation-path customization-color]}]
(defn- new-account-origin
[{:keys [keypair-title derivation-path customization-color]}]
(let [{keypair-name :name} (rf/sub [:wallet/selected-keypair])
primary? (rf/sub [:wallet/selected-primary-keypair?])
keypair-name (or keypair-title
Expand All @@ -120,7 +124,8 @@
:derivation-path derivation-path
:customization-color customization-color})}]]))

(defn- floating-button [_ & _]
(defn- floating-button
[_ & _]
(let [top (safe-area/get-top)
bottom (safe-area/get-bottom)
header [quo/page-nav
Expand All @@ -141,11 +146,11 @@
:header header
:footer [standard-auth/slide-button
(assoc slide-button-props
:size :size-48
:track-text (i18n/label :t/slide-to-create-account)
:customization-color account-color
:auth-button-label (i18n/label :t/confirm)
:container-style (style/slide-button-container bottom))]}]
:size :size-48
:track-text (i18n/label :t/slide-to-create-account)
:customization-color account-color
:auth-button-label (i18n/label :t/confirm)
:container-style (style/slide-button-container bottom))]}]
children))))

(defn add-new-keypair-variant
Expand All @@ -166,17 +171,21 @@
:slide-button-props {:on-auth-success on-auth-success
:disabled? (empty? @account-name)
:dependencies [new-account-data]}}
[avatar {:account-color @account-color
:emoji @emoji
:on-select-emoji set-emoji}]
[input {:account-color @account-color
:account-name @account-name
:on-change-text on-change-text}]
[color-picker {:account-color @account-color
:set-account-color set-account-color}]
[new-account-origin {:derivation-path constants/wallet-initial-derivation-path
:customization-color customization-color
:keypair-title keypair-name}]]))))
[avatar
{:account-color @account-color
:emoji @emoji
:on-select-emoji set-emoji}]
[input
{:account-color @account-color
:account-name @account-name
:on-change-text on-change-text}]
[color-picker
{:account-color @account-color
:set-account-color set-account-color}]
[new-account-origin
{:derivation-path constants/wallet-initial-derivation-path
:customization-color customization-color
:keypair-title keypair-name}]]))))

(defn derive-account-variant
[{:keys [on-change-text set-account-color set-emoji]
Expand All @@ -187,39 +196,44 @@
(fn [{:keys [customization-color]}]
(let [{:keys [derived-from
key-uid]} (rf/sub [:wallet/selected-keypair])
on-auth-success (rn/use-callback
(fn [password]
(let [preferences {:account-name @account-name
:color @account-color
:emoji @emoji}]
(rf/dispatch
[:wallet/derive-address-and-add-account
{:password password
:derived-from-address derived-from
:derivation-path @derivation-path
:account-preferences preferences}])))
[derived-from])]
on-auth-success (rn/use-callback
(fn [password]
(let [preferences {:account-name @account-name
:color @account-color
:emoji @emoji}]
(rf/dispatch
[:wallet/derive-address-and-add-account
{:password password
:derived-from-address derived-from
:derivation-path @derivation-path
:account-preferences preferences}])))
[derived-from])]
(rn/use-effect
#(rf/dispatch
[:wallet/next-derivation-path {:on-success set-derivation-path
:keypair-uid key-uid}])
[:wallet/next-derivation-path
{:on-success set-derivation-path
:keypair-uid key-uid}])
[key-uid])

[floating-button
{:account-color @account-color
:slide-button-props {:on-auth-success on-auth-success
:disabled? (or (empty? @account-name)
(= "" @derivation-path))}}
[avatar {:account-color @account-color
:emoji @emoji
:on-select-emoji set-emoji}]
[input {:account-color @account-color
:account-name @account-name
:on-change-text on-change-text}]
[color-picker {:account-color @account-color
:set-account-color set-account-color}]
[new-account-origin {:derivation-path @derivation-path
:customization-color customization-color}]]))))
[avatar
{:account-color @account-color
:emoji @emoji
:on-select-emoji set-emoji}]
[input
{:account-color @account-color
:account-name @account-name
:on-change-text on-change-text}]
[color-picker
{:account-color @account-color
:set-account-color set-account-color}]
[new-account-origin
{:derivation-path @derivation-path
:customization-color customization-color}]]))))

(defn view
[_]
Expand Down
39 changes: 20 additions & 19 deletions src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
(ns status-im.contexts.wallet.events
(:require
[camel-snake-kebab.extras :as cske]
[clojure.string :as string]
[react-native.platform :as platform]
[status-im.constants :as constants]
[status-im.contexts.settings.wallet.events]
[status-im.contexts.wallet.common.utils.networks :as network-utils]
[status-im.contexts.wallet.data-store :as data-store]
[status-im.contexts.wallet.db :as db]
[status-im.contexts.wallet.item-types :as item-types]
[taoensso.timbre :as log]
[utils.collection]
[utils.ethereum.chain :as chain]
[utils.ethereum.eip.eip55 :as eip55]
[utils.i18n :as i18n]
[utils.number]
[utils.re-frame :as rf]
[utils.security.core :as security]
[utils.transforms :as transforms]))
[camel-snake-kebab.extras :as cske]
[clojure.string :as string]
[react-native.platform :as platform]
[status-im.constants :as constants]
[status-im.contexts.settings.wallet.events]
[status-im.contexts.wallet.common.utils.networks :as network-utils]
[status-im.contexts.wallet.data-store :as data-store]
[status-im.contexts.wallet.db :as db]
[status-im.contexts.wallet.item-types :as item-types]
[taoensso.timbre :as log]
[utils.collection]
[utils.ethereum.chain :as chain]
[utils.ethereum.eip.eip55 :as eip55]
[utils.i18n :as i18n]
[utils.number]
[utils.re-frame :as rf]
[utils.security.core :as security]
[utils.transforms :as transforms]))

(rf/reg-event-fx :wallet/show-account-created-toast
(fn [{:keys [db]} [address]]
Expand Down Expand Up @@ -187,7 +187,8 @@
[{:keys [password account-name emoji color type]
:or {type :generated}}
{:keys [public-key address path] :as _derived-account}]]
(let [lowercase-address (some-> address (string/lower-case))
(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 Down

0 comments on commit 1a6d3a3

Please sign in to comment.