Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rende11 committed May 1, 2024
1 parent 7b4fcd4 commit e7fa186
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,22 @@

(rf/reg-event-fx :wallet/get-derived-addresses-success get-derived-addresses-success)

;; Import private key

(rf/reg-event-fx
:wallet.import-private-key/set-private-key
:wallet/set-private-key
(fn [{:keys [db]} [value]]
{:db (assoc-in db [:wallet :ui :import-private-key :private-key] value)}))

(rf/reg-event-fx
:wallet.import-private-key/set-public-address
:wallet/set-public-address
(fn [{:keys [db]} [value]]
{:db (assoc-in db [:wallet :ui :import-private-key :public-address] value)}))

(rf/reg-event-fx
:wallet.import-private-key/set-key-pair-name
:wallet/set-key-pair-name
(fn [{:keys [db]} [value]]
{:db (assoc-in db [:wallet :ui :import-private-key :key-pair-name] value)}))

(rf/reg-event-fx
:wallet.import-private-key/clear-data
:wallet/clear-private-key-data
(fn [{:keys [db]} _]
{:db (update-in db [:wallet :ui] dissoc :import-private-key)}))
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns status-im.contexts.wallet.add-account.create-account.import-private-key.add-key-pair-name.view
(:require
[clojure.string :as string]
[quo.core :as quo]
[react-native.core :as rn]
[status-im.common.floating-button-page.view :as floating-button-page]
Expand All @@ -9,23 +10,27 @@
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(def keypair-name-max-length 15)
(def keypair-name-min-length 5)
(def ^:private keypair-name-max-length 15)
(def ^:private keypair-name-min-length 5)

(def error-messages
{:too-long (i18n/label :t/key-name-error-length)
:too-short (i18n/label :t/key-name-error-too-short {:count keypair-name-min-length})
:emoji (i18n/label :t/key-name-error-emoji)
:special-char (i18n/label :t/key-name-error-special-char)})

(defn- navigate-back
[]
(rf/dispatch [:navigate-back]))

(defn view
[]
(let [customization-color (rf/sub [:profile/customization-color])
key-pair-name (rf/sub [:wallet.import-private-key/key-pair-name])
[error set-error] (rn/use-state)
[error set-error] (rn/use-state nil)
on-change-text (rn/use-callback
(fn [value]
(rf/dispatch [:wallet.import-private-key/set-key-pair-name value])
(rf/dispatch [:wallet/set-key-pair-name value])
(cond
(validators/has-emojis? value)
(set-error :emoji)
Expand All @@ -36,20 +41,19 @@
(> (count value) keypair-name-max-length)
(set-error :too-long)

(and (seq value) (< (count value) keypair-name-min-length))
(< 0 (count value) keypair-name-min-length)
(set-error :too-short)

:else (set-error nil))))

disabled? (or (some? error) (empty? key-pair-name))]
disabled? (or (some? error) (string/blank? key-pair-name))]
[rn/view {:flex 1}
[floating-button-page/view
{:customization-color customization-color
:header [quo/page-nav
{:background :white
:type :no-title
:icon-name :i/arrow-left
:on-press #(rf/dispatch [:navigate-back])}]
:on-press navigate-back}]
:footer [quo/button
{:customization-color customization-color
:disabled? disabled?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns status-im.contexts.wallet.add-account.create-account.import-private-key.private-key.view
(:require
[clojure.string :as string]
[quo.core :as quo]
[quo.theme :as theme]
[react-native.clipboard :as clipboard]
Expand All @@ -26,14 +27,15 @@
(do
(set-flow-state :scanning)
;; TODO get real address
(rf/dispatch [:wallet.import-private-key/set-public-address
;; Should be fixed in #18819
(rf/dispatch [:wallet/set-public-address
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"])
(js/setTimeout set-flow-state 400 (rand-nth [:active-address :inactive-address]))))))
500))

on-change (rn/use-callback
(fn [v]
(rf/dispatch [:wallet.import-private-key/set-private-key v])
(rf/dispatch [:wallet/set-private-key v])
(check-address v)))
on-paste (rn/use-callback
(fn []
Expand Down Expand Up @@ -96,7 +98,7 @@
public-address (rf/sub [:wallet.import-private-key/public-address])
[flow-state set-flow-state] (rn/use-state)
error? (= :invalid-private-key flow-state)]
(rn/use-mount #(rf/dispatch [:wallet.import-private-key/clear-data]))
(rn/use-mount #(rf/dispatch [:wallet/clear-private-key-data]))
[rn/view {:flex 1}
[floating-button-page/view
{:customization-color customization-color
Expand All @@ -114,7 +116,7 @@
(i18n/label :t/import-private-key-info)])
[quo/button
{:customization-color customization-color
:disabled? (or (empty? private-key) error?)
:disabled? (or (string/blank? private-key) error?)
:on-press #(rf/dispatch [:navigate-to
:screen/wallet.add-key-pair-name])}
(i18n/label :t/continue)]]}
Expand Down

0 comments on commit e7fa186

Please sign in to comment.