parent
9e5b8b5f9c
commit
fc801213ef
|
@ -4,19 +4,18 @@
|
||||||
[react-native.platform :as platform]))
|
[react-native.platform :as platform]))
|
||||||
|
|
||||||
(defn container
|
(defn container
|
||||||
[{:keys [blur? customization-color theme selected?]}]
|
[{:keys [blur? customization-color theme selected? container-style]}]
|
||||||
{:border-radius 16
|
(merge {:border-radius 16
|
||||||
:border-width 1
|
:border-width 1
|
||||||
:border-color (if selected?
|
:border-color (if selected?
|
||||||
(if blur?
|
(if blur?
|
||||||
colors/white
|
colors/white
|
||||||
(colors/theme-colors (colors/custom-color customization-color 50)
|
(colors/resolve-color customization-color theme))
|
||||||
(colors/custom-color customization-color 60)
|
|
||||||
theme))
|
|
||||||
(if blur?
|
(if blur?
|
||||||
colors/white-opa-5
|
colors/white-opa-5
|
||||||
(colors/theme-colors colors/neutral-10 colors/neutral-80 theme)))
|
(colors/theme-colors colors/neutral-10 colors/neutral-80 theme)))
|
||||||
:padding-bottom 8})
|
:padding-bottom 8}
|
||||||
|
container-style))
|
||||||
|
|
||||||
(def header-container
|
(def header-container
|
||||||
{:padding-horizontal 12
|
{:padding-horizontal 12
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
[quo.foundations.colors :as colors]
|
[quo.foundations.colors :as colors]
|
||||||
[quo.theme :as quo.theme]
|
[quo.theme :as quo.theme]
|
||||||
[react-native.core :as rn]
|
[react-native.core :as rn]
|
||||||
[reagent.core :as reagent]
|
|
||||||
[utils.i18n :as i18n]))
|
[utils.i18n :as i18n]))
|
||||||
|
|
||||||
(defn keypair-string
|
(defn keypair-string
|
||||||
|
@ -34,7 +33,7 @@
|
||||||
:profile-picture profile-picture}]
|
:profile-picture profile-picture}]
|
||||||
[icon-avatar/icon-avatar
|
[icon-avatar/icon-avatar
|
||||||
{:size :size-32
|
{:size :size-32
|
||||||
:icon :i/placeholder
|
:icon :i/seed
|
||||||
:border? true}]))
|
:border? true}]))
|
||||||
|
|
||||||
(defn title-view
|
(defn title-view
|
||||||
|
@ -91,23 +90,23 @@
|
||||||
[account-list-card/view item])
|
[account-list-card/view item])
|
||||||
|
|
||||||
(defn- view-internal
|
(defn- view-internal
|
||||||
[{:keys [default-selected?]}]
|
[{:keys [accounts action container-style selected? on-press] :as props}]
|
||||||
(let [selected? (reagent/atom default-selected?)]
|
|
||||||
(fn [{:keys [accounts action container-style] :as props}]
|
|
||||||
[rn/pressable
|
[rn/pressable
|
||||||
{:style (merge (style/container (merge props {:selected? @selected?})) container-style)
|
{:style (style/container (merge props
|
||||||
:on-press #(when (= action :selector) (reset! selected? (not @selected?)))}
|
{:selected? selected?
|
||||||
|
:container-style container-style}))
|
||||||
|
:on-press #(when (= action :selector) (on-press))}
|
||||||
[rn/view {:style style/header-container}
|
[rn/view {:style style/header-container}
|
||||||
[avatar props]
|
[avatar props]
|
||||||
[rn/view
|
[rn/view
|
||||||
{:style {:margin-left 8
|
{:style {:margin-left 8
|
||||||
:flex 1}}
|
:flex 1}}
|
||||||
[title-view (assoc props :selected? @selected?)]
|
[title-view (assoc props :selected? selected?)]
|
||||||
[details-view props]]]
|
[details-view props]]]
|
||||||
[rn/flat-list
|
[rn/flat-list
|
||||||
{:data accounts
|
{:data accounts
|
||||||
:render-fn acc-list-card
|
:render-fn acc-list-card
|
||||||
:separator [rn/view {:style {:height 8}}]
|
:separator [rn/view {:style {:height 8}}]
|
||||||
:style {:padding-horizontal 8}}]])))
|
:style {:padding-horizontal 8}}]])
|
||||||
|
|
||||||
(def view (quo.theme/with-theme view-internal))
|
(def view (quo.theme/with-theme view-internal))
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
(ns status-im.contexts.wallet.create-account.events
|
||||||
|
(:require [status-im.contexts.wallet.data-store :as data-store]
|
||||||
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
|
(defn get-keypairs-success
|
||||||
|
[{:keys [db]} [keypairs]]
|
||||||
|
(let [parsed-keypairs (data-store/parse-keypairs keypairs)
|
||||||
|
default-key-uid (:key-uid (first parsed-keypairs))]
|
||||||
|
{:db (-> db
|
||||||
|
(assoc-in [:wallet :keypairs] parsed-keypairs)
|
||||||
|
(assoc-in [:wallet :ui :create-account :selected-keypair-uid] default-key-uid))}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx :wallet/get-keypairs-success get-keypairs-success)
|
||||||
|
|
||||||
|
(defn confirm-account-origin
|
||||||
|
[{:keys [db]} [key-uid]]
|
||||||
|
{:db (assoc-in db [:wallet :ui :create-account :selected-keypair-uid] key-uid)
|
||||||
|
:fx [[:dispatch [:navigate-back]]]})
|
||||||
|
|
||||||
|
(rf/reg-event-fx :wallet/confirm-account-origin confirm-account-origin)
|
||||||
|
|
||||||
|
(defn store-secret-phrase
|
||||||
|
[{:keys [db]} [{:keys [secret-phrase random-phrase]}]]
|
||||||
|
{:db (-> db
|
||||||
|
(assoc-in [:wallet :ui :create-account :secret-phrase] secret-phrase)
|
||||||
|
(assoc-in [:wallet :ui :create-account :random-phrase] random-phrase))
|
||||||
|
:fx [[:dispatch-later [{:ms 20 :dispatch [:navigate-to :screen/wallet.check-your-backup]}]]]})
|
||||||
|
|
||||||
|
(rf/reg-event-fx :wallet/store-secret-phrase store-secret-phrase)
|
||||||
|
|
||||||
|
(defn new-keypair-created
|
||||||
|
[{:keys [db]} [{:keys [new-keypair]}]]
|
||||||
|
{:db (assoc-in db [:wallet :ui :create-account :new-keypair] new-keypair)
|
||||||
|
:fx [[:dispatch [:navigate-back-to :wallet-create-account]]]})
|
||||||
|
|
||||||
|
(rf/reg-event-fx :wallet/new-keypair-created new-keypair-created)
|
||||||
|
|
||||||
|
(defn new-keypair-continue
|
||||||
|
[{:keys [db]} [{:keys [keypair-name]}]]
|
||||||
|
(let [secret-phrase (get-in db [:wallet :ui :create-account :secret-phrase])]
|
||||||
|
{:fx [[:effects.wallet/create-account-from-mnemonic
|
||||||
|
{:secret-phrase secret-phrase
|
||||||
|
:keypair-name keypair-name}]]}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx :wallet/new-keypair-continue new-keypair-continue)
|
||||||
|
|
||||||
|
(defn clear-new-keypair
|
||||||
|
[{:keys [db]}]
|
||||||
|
{:db (update-in db [:wallet :ui :create-account] dissoc :new-keypair)})
|
||||||
|
|
||||||
|
(rf/reg-event-fx :wallet/clear-new-keypair clear-new-keypair)
|
|
@ -0,0 +1,44 @@
|
||||||
|
(ns status-im.contexts.wallet.create-account.events-test
|
||||||
|
(:require
|
||||||
|
[cljs.test :refer-macros [deftest is]]
|
||||||
|
matcher-combinators.test
|
||||||
|
[status-im.contexts.wallet.create-account.events :as events]))
|
||||||
|
|
||||||
|
(deftest confirm-account-origin
|
||||||
|
(let [db {:wallet {:ui {:create-account {}}}}
|
||||||
|
props ["key-uid"]
|
||||||
|
expected-db {:wallet {:ui {:create-account {:selected-keypair-uid "key-uid"}}}}
|
||||||
|
effects (events/confirm-account-origin {:db db} props)
|
||||||
|
result-db (:db effects)]
|
||||||
|
(is (match? result-db expected-db))))
|
||||||
|
|
||||||
|
(deftest store-secret-phrase
|
||||||
|
(let [db {}
|
||||||
|
props [{:secret-phrase "test-secret" :random-phrase "random-test"}]
|
||||||
|
expected-db {:wallet {:ui {:create-account {:secret-phrase "test-secret"
|
||||||
|
:random-phrase "random-test"}}}}
|
||||||
|
effects (events/store-secret-phrase {:db db} props)
|
||||||
|
result-db (:db effects)]
|
||||||
|
(is (match? result-db expected-db))))
|
||||||
|
|
||||||
|
(deftest new-keypair-created
|
||||||
|
(let [db {}
|
||||||
|
props [{:new-keypair "test-keypair"}]
|
||||||
|
expected-db {:wallet {:ui {:create-account {:new-keypair "test-keypair"}}}}
|
||||||
|
effects (events/new-keypair-created {:db db} props)
|
||||||
|
result-db (:db effects)]
|
||||||
|
(is (match? result-db expected-db))))
|
||||||
|
|
||||||
|
(deftest new-keypair-continue
|
||||||
|
(let [db {:wallet {:ui {:create-account {:secret-phrase "test-secret"}}}}
|
||||||
|
props [{:keypair-name "test-keypair"}]
|
||||||
|
expected-effects [[:effects.wallet/create-account-from-mnemonic
|
||||||
|
{:secret-phrase "test-secret" :keypair-name "test-keypair"}]]
|
||||||
|
effects (events/new-keypair-continue {:db db} props)]
|
||||||
|
(is (match? effects {:fx expected-effects}))))
|
||||||
|
|
||||||
|
(deftest clear-new-keypair
|
||||||
|
(let [db {:wallet {:ui {:create-account {:new-keypair "test-keypair"}}}}
|
||||||
|
expected-db {:wallet {:ui {:create-account {}}}}
|
||||||
|
effects (events/clear-new-keypair {:db db})]
|
||||||
|
(is (match? (:db effects) expected-db))))
|
|
@ -4,7 +4,6 @@
|
||||||
[quo.core :as quo]
|
[quo.core :as quo]
|
||||||
[react-native.core :as rn]
|
[react-native.core :as rn]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
[status-im.contexts.profile.utils :as profile.utils]
|
|
||||||
[status-im.contexts.wallet.create-account.select-keypair.style :as style]
|
[status-im.contexts.wallet.create-account.select-keypair.style :as style]
|
||||||
[utils.address :as utils]
|
[utils.address :as utils]
|
||||||
[utils.i18n :as i18n]
|
[utils.i18n :as i18n]
|
||||||
|
@ -47,7 +46,7 @@
|
||||||
:action :none}))))
|
:action :none}))))
|
||||||
|
|
||||||
(defn- keypair
|
(defn- keypair
|
||||||
[item index _ {:keys [profile-picture compressed-key]}]
|
[item index _ {:keys [profile-picture compressed-key selected-key-uid set-selected-key-uid]}]
|
||||||
(let [main-account (first (:accounts item))
|
(let [main-account (first (:accounts item))
|
||||||
color (:customization-color main-account)
|
color (:customization-color main-account)
|
||||||
accounts (parse-accounts (:accounts item))]
|
accounts (parse-accounts (:accounts item))]
|
||||||
|
@ -63,16 +62,19 @@
|
||||||
:details {:full-name (:name item)
|
:details {:full-name (:name item)
|
||||||
:address (when (zero? index)
|
:address (when (zero? index)
|
||||||
(utils/get-shortened-compressed-key compressed-key))}
|
(utils/get-shortened-compressed-key compressed-key))}
|
||||||
|
:on-press #(set-selected-key-uid (:key-uid item))
|
||||||
:accounts accounts
|
:accounts accounts
|
||||||
:default-selected? (zero? index)
|
:selected? (= selected-key-uid (:key-uid item))
|
||||||
:container-style {:margin-horizontal 20
|
:container-style {:margin-horizontal 20
|
||||||
:margin-vertical 8}}]))
|
:margin-vertical 8}}]))
|
||||||
(defn view
|
(defn view
|
||||||
[]
|
[]
|
||||||
(let [{:keys [compressed-key customization-color]} (rf/sub [:profile/profile])
|
(let [compressed-key (rf/sub [:profile/compressed-key])
|
||||||
profile-with-image (rf/sub [:profile/profile-with-image])
|
customization-color (rf/sub [:profile/customization-color])
|
||||||
keypairs (rf/sub [:wallet/keypairs])
|
keypairs (rf/sub [:wallet/keypairs])
|
||||||
profile-picture (profile.utils/photo profile-with-image)]
|
selected-keypair (rf/sub [:wallet/selected-keypair-uid])
|
||||||
|
profile-picture (rf/sub [:profile/image])
|
||||||
|
[selected-key-uid set-selected-key-uid] (rn/use-state selected-keypair)]
|
||||||
[rn/view {:style {:flex 1}}
|
[rn/view {:style {:flex 1}}
|
||||||
[quo/page-nav
|
[quo/page-nav
|
||||||
{:icon-name :i/close
|
{:icon-name :i/close
|
||||||
|
@ -92,11 +94,16 @@
|
||||||
{:data keypairs
|
{:data keypairs
|
||||||
:render-fn keypair
|
:render-fn keypair
|
||||||
:render-data {:profile-picture profile-picture
|
:render-data {:profile-picture profile-picture
|
||||||
:compressed-key compressed-key}
|
:compressed-key compressed-key
|
||||||
|
:selected-key-uid selected-key-uid
|
||||||
|
:set-selected-key-uid set-selected-key-uid}
|
||||||
|
:initial-num-to-render 1
|
||||||
:content-container-style {:padding-bottom 60}}]
|
:content-container-style {:padding-bottom 60}}]
|
||||||
[quo/bottom-actions
|
[quo/bottom-actions
|
||||||
{:actions :one-action
|
{:actions :one-action
|
||||||
:button-one-label (i18n/label :t/confirm-account-origin)
|
:button-one-label (i18n/label :t/confirm-account-origin)
|
||||||
:button-one-props {:disabled? true
|
:button-one-props {:disabled? (= selected-keypair selected-key-uid)
|
||||||
:customization-color customization-color}
|
:customization-color customization-color
|
||||||
|
:on-press #(rf/dispatch [:wallet/confirm-account-origin
|
||||||
|
selected-key-uid])}
|
||||||
:container-style style/bottom-action-container}]]))
|
:container-style style/bottom-action-container}]]))
|
||||||
|
|
|
@ -23,17 +23,19 @@
|
||||||
|
|
||||||
|
|
||||||
(defn- get-keypair-data
|
(defn- get-keypair-data
|
||||||
[primary-name derivation-path account-color {:keys [keypair-name]}]
|
[{:keys [title primary-keypair? new-keypair? derivation-path customization-color]}]
|
||||||
[{:title (or keypair-name (i18n/label :t/keypair-title {:name primary-name}))
|
[{:title title
|
||||||
:image (if keypair-name :icon :avatar)
|
:image (if primary-keypair? :avatar :icon)
|
||||||
:image-props (if keypair-name
|
:image-props (if primary-keypair?
|
||||||
:i/seed
|
{:full-name (utils.string/get-initials title 1)
|
||||||
{:full-name (utils.string/get-initials primary-name 1)
|
|
||||||
:size :xxs
|
:size :xxs
|
||||||
:customization-color account-color})
|
:customization-color customization-color}
|
||||||
:action (when-not keypair-name :button)
|
:i/seed)
|
||||||
|
:action (when-not new-keypair? :button)
|
||||||
:action-props {:on-press (fn []
|
:action-props {:on-press (fn []
|
||||||
(rf/dispatch [:navigate-to :screen/wallet.select-keypair]))
|
(ff/alert ::ff/wallet.bridge-token
|
||||||
|
#(rf/dispatch [:navigate-to
|
||||||
|
:screen/wallet.select-keypair])))
|
||||||
:button-text (i18n/label :t/edit)
|
:button-text (i18n/label :t/edit)
|
||||||
:alignment :flex-start}
|
:alignment :flex-start}
|
||||||
:description :text
|
:description :text
|
||||||
|
@ -42,13 +44,7 @@
|
||||||
:image :icon
|
:image :icon
|
||||||
:image-props :i/derivated-path
|
:image-props :i/derivated-path
|
||||||
:action :button
|
:action :button
|
||||||
:action-props {:on-press (fn []
|
:action-props {:on-press #(js/alert "Coming soon!")
|
||||||
(ff/alert ::ff/wallet.network-filter
|
|
||||||
#(rf/dispatch [:navigate-to
|
|
||||||
:screen/wallet.edit-derivation-path
|
|
||||||
{:customization-color account-color}])))
|
|
||||||
|
|
||||||
|
|
||||||
:button-text (i18n/label :t/edit)
|
:button-text (i18n/label :t/edit)
|
||||||
:icon-left :i/placeholder
|
:icon-left :i/placeholder
|
||||||
:alignment :flex-start}
|
:alignment :flex-start}
|
||||||
|
@ -56,24 +52,51 @@
|
||||||
:description-props {:text (string/replace derivation-path #"/" " / ")}}])
|
:description-props {:text (string/replace derivation-path #"/" " / ")}}])
|
||||||
|
|
||||||
(defn- f-view
|
(defn- f-view
|
||||||
[]
|
[{:keys [theme]}]
|
||||||
|
(let [account-name (reagent/atom "")
|
||||||
|
account-color (reagent/atom (rand-nth colors/account-colors))
|
||||||
|
emoji (reagent/atom (emoji-picker.utils/random-emoji))]
|
||||||
|
(fn []
|
||||||
(let [top (safe-area/get-top)
|
(let [top (safe-area/get-top)
|
||||||
bottom (safe-area/get-bottom)
|
bottom (safe-area/get-bottom)
|
||||||
account-color (reagent/atom (rand-nth colors/account-colors))
|
{window-width :width} (rn/get-window)
|
||||||
emoji (reagent/atom (emoji-picker.utils/random-emoji))
|
number-of-accounts (count (rf/sub
|
||||||
number-of-accounts (count (rf/sub [:wallet/accounts-without-watched-accounts]))
|
[:wallet/accounts-without-watched-accounts]))
|
||||||
account-name (reagent/atom "")
|
{:keys [address customization-color]} (rf/sub [:profile/profile])
|
||||||
|
{:keys [new-keypair]} (rf/sub [:wallet/create-account])
|
||||||
|
keypairs (rf/sub [:wallet/keypairs])
|
||||||
|
selected-keypair-uid (rf/sub [:wallet/selected-keypair-uid])
|
||||||
placeholder (i18n/label :t/default-account-placeholder
|
placeholder (i18n/label :t/default-account-placeholder
|
||||||
{:number (inc number-of-accounts)})
|
{:number (inc number-of-accounts)})
|
||||||
derivation-path (reagent/atom (utils/get-derivation-path number-of-accounts))
|
derivation-path (utils/get-derivation-path
|
||||||
{:keys [public-key address]} (rf/sub [:profile/profile])
|
number-of-accounts)
|
||||||
on-change-text #(reset! account-name %)
|
keypair (some #(when (= (:key-uid %) selected-keypair-uid)
|
||||||
primary-name (first (rf/sub [:contacts/contact-two-names-by-identity
|
%)
|
||||||
public-key]))
|
keypairs)
|
||||||
{window-width :width} (rn/get-window)]
|
primary-keypair? (= selected-keypair-uid (:key-uid (first keypairs)))
|
||||||
(fn [{:keys [theme]}]
|
create-new-keypair-account #(rf/dispatch
|
||||||
(let [{:keys [new-keypair]} (rf/sub [:wallet/create-account])]
|
[:wallet/add-keypair-and-create-account
|
||||||
(rn/use-unmount #(rf/dispatch [:wallet/clear-new-keypair]))
|
{:sha3-pwd (security/safe-unmask-data %)
|
||||||
|
:new-keypair
|
||||||
|
(create-account.utils/prepare-new-keypair
|
||||||
|
{:new-keypair new-keypair
|
||||||
|
: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}])
|
||||||
|
keypair-title (or (:keypair-name new-keypair)
|
||||||
|
(if primary-keypair?
|
||||||
|
(i18n/label :t/keypair-title
|
||||||
|
{:name (:name keypair)})
|
||||||
|
(:name keypair)))]
|
||||||
[rn/view {:style {:flex 1}}
|
[rn/view {:style {:flex 1}}
|
||||||
[quo/page-nav
|
[quo/page-nav
|
||||||
{:type :no-title
|
{:type :no-title
|
||||||
|
@ -105,7 +128,7 @@
|
||||||
[quo/title-input
|
[quo/title-input
|
||||||
{:customization-color @account-color
|
{:customization-color @account-color
|
||||||
:placeholder placeholder
|
:placeholder placeholder
|
||||||
:on-change-text on-change-text
|
:on-change-text #(reset! account-name %)
|
||||||
:max-length constants/wallet-account-name-max-length
|
:max-length constants/wallet-account-name-max-length
|
||||||
:blur? true
|
:blur? true
|
||||||
:disabled? false
|
:disabled? false
|
||||||
|
@ -128,32 +151,19 @@
|
||||||
[quo/category
|
[quo/category
|
||||||
{:list-type :settings
|
{:list-type :settings
|
||||||
:label (i18n/label :t/origin)
|
:label (i18n/label :t/origin)
|
||||||
:data (get-keypair-data primary-name @derivation-path @account-color new-keypair)}]
|
:data (get-keypair-data {:title keypair-title
|
||||||
|
:primary-keypair? primary-keypair?
|
||||||
|
:new-keypair? (boolean new-keypair)
|
||||||
|
:derivation-path derivation-path
|
||||||
|
:customization-color customization-color})}]
|
||||||
[standard-auth/slide-button
|
[standard-auth/slide-button
|
||||||
{:size :size-48
|
{:size :size-48
|
||||||
:track-text (i18n/label :t/slide-to-create-account)
|
:track-text (i18n/label :t/slide-to-create-account)
|
||||||
:customization-color @account-color
|
:customization-color @account-color
|
||||||
:on-auth-success (fn [entered-password]
|
:on-auth-success (fn [password]
|
||||||
(if new-keypair
|
(if new-keypair
|
||||||
(rf/dispatch
|
(create-new-keypair-account password)
|
||||||
[:wallet/add-keypair-and-create-account
|
(create-existing-keypair-account password)))
|
||||||
{:sha3-pwd (security/safe-unmask-data
|
|
||||||
entered-password)
|
|
||||||
:new-keypair (create-account.utils/prepare-new-keypair
|
|
||||||
{:new-keypair new-keypair
|
|
||||||
:address address
|
|
||||||
:account-name @account-name
|
|
||||||
:account-color @account-color
|
|
||||||
:emoji @emoji
|
|
||||||
:derivation-path
|
|
||||||
@derivation-path})}])
|
|
||||||
(rf/dispatch [:wallet/derive-address-and-add-account
|
|
||||||
{:sha3-pwd (security/safe-unmask-data
|
|
||||||
entered-password)
|
|
||||||
:emoji @emoji
|
|
||||||
:color @account-color
|
|
||||||
:path @derivation-path
|
|
||||||
:account-name @account-name}])))
|
|
||||||
:auth-button-label (i18n/label :t/confirm)
|
:auth-button-label (i18n/label :t/confirm)
|
||||||
:disabled? (empty? @account-name)
|
:disabled? (empty? @account-name)
|
||||||
:container-style (style/slide-button-container bottom)}]]))))
|
:container-style (style/slide-button-container bottom)}]]))))
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
(ns status-im.contexts.wallet.data-store
|
(ns status-im.contexts.wallet.data-store
|
||||||
(:require
|
(:require
|
||||||
|
[camel-snake-kebab.core :as csk]
|
||||||
[camel-snake-kebab.extras :as cske]
|
[camel-snake-kebab.extras :as cske]
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
|
@ -104,22 +105,33 @@
|
||||||
:nativeCurrencySymbol :native-currency-symbol
|
:nativeCurrencySymbol :native-currency-symbol
|
||||||
:nativeCurrencyName :native-currency-symbol})))
|
:nativeCurrencyName :native-currency-symbol})))
|
||||||
|
|
||||||
(defn rename-color-id-in-data
|
(defn sort-keypairs
|
||||||
[data]
|
[keypairs]
|
||||||
|
(sort-by #(if (some (fn [account]
|
||||||
|
(string/starts-with? (:path account) constants/path-eip1581))
|
||||||
|
(:accounts %))
|
||||||
|
0
|
||||||
|
1)
|
||||||
|
keypairs))
|
||||||
|
|
||||||
|
(defn sort-and-rename-keypairs
|
||||||
|
[keypairs]
|
||||||
|
(let [sorted-keypairs (sort-keypairs keypairs)]
|
||||||
(map (fn [item]
|
(map (fn [item]
|
||||||
(update item
|
(update item
|
||||||
:accounts
|
:accounts
|
||||||
(fn [accounts]
|
(fn [accounts]
|
||||||
(map (fn [account]
|
(map
|
||||||
(let [renamed-account (set/rename-keys account
|
(fn [{:keys [colorId] :as account}]
|
||||||
{:colorId :customization-color})]
|
(assoc account
|
||||||
(if (contains? account :colorId)
|
:customization-color
|
||||||
renamed-account
|
(if (seq colorId)
|
||||||
(assoc renamed-account :customization-color :blue))))
|
(keyword colorId)
|
||||||
|
:blue)))
|
||||||
accounts))))
|
accounts))))
|
||||||
data))
|
sorted-keypairs)))
|
||||||
|
|
||||||
(defn parse-keypairs
|
(defn parse-keypairs
|
||||||
[keypairs]
|
[keypairs]
|
||||||
(let [renamed-data (rename-color-id-in-data keypairs)]
|
(let [renamed-data (sort-and-rename-keypairs keypairs)]
|
||||||
(cske/transform-keys transforms/->kebab-case-keyword renamed-data)))
|
(cske/transform-keys csk/->kebab-case-keyword renamed-data)))
|
||||||
|
|
|
@ -178,14 +178,15 @@
|
||||||
:wallet assoc
|
:wallet assoc
|
||||||
:navigate-to-account address
|
:navigate-to-account address
|
||||||
:new-account? true)
|
:new-account? true)
|
||||||
:fx [[:dispatch [:wallet/get-accounts]]]}))
|
:fx [[:dispatch [:wallet/get-accounts]]
|
||||||
|
[:dispatch [:wallet/clear-new-keypair]]]}))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/add-account
|
(rf/reg-event-fx :wallet/add-account
|
||||||
(fn [{:keys [db]}
|
(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]}]]
|
{:keys [public-key address path]}]]
|
||||||
(let [lowercase-address (if address (string/lower-case address) address)
|
(let [lowercase-address (if address (string/lower-case address) address)
|
||||||
key-uid (get-in db [:profile/profile :key-uid])
|
key-uid (get-in db [:wallet :ui :create-account :selected-keypair-uid])
|
||||||
account-config {:key-uid (when (= type :generated) key-uid)
|
account-config {:key-uid (when (= type :generated) key-uid)
|
||||||
:wallet false
|
:wallet false
|
||||||
:chat false
|
:chat false
|
||||||
|
@ -233,12 +234,6 @@
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/get-keypairs get-keypairs)
|
(rf/reg-event-fx :wallet/get-keypairs get-keypairs)
|
||||||
|
|
||||||
(defn get-keypairs-success
|
|
||||||
[{:keys [db]} [keypairs]]
|
|
||||||
{:db (assoc-in db [:wallet :keypairs] (data-store/parse-keypairs keypairs))})
|
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/get-keypairs-success get-keypairs-success)
|
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/bridge-select-token
|
(rf/reg-event-fx :wallet/bridge-select-token
|
||||||
(fn [{:keys [db]} [{:keys [token stack-id]}]]
|
(fn [{:keys [db]} [{:keys [token stack-id]}]]
|
||||||
(let [to-address (get-in db [:wallet :current-viewing-account-address])]
|
(let [to-address (get-in db [:wallet :current-viewing-account-address])]
|
||||||
|
@ -410,37 +405,6 @@
|
||||||
:subject title
|
:subject title
|
||||||
:message content})]]}))
|
:message content})]]}))
|
||||||
|
|
||||||
(defn store-secret-phrase
|
|
||||||
[{:keys [db]} [{:keys [secret-phrase random-phrase]}]]
|
|
||||||
{:db (-> db
|
|
||||||
(assoc-in [:wallet :ui :create-account :secret-phrase] secret-phrase)
|
|
||||||
(assoc-in [:wallet :ui :create-account :random-phrase] random-phrase))
|
|
||||||
:fx [[:dispatch-later [{:ms 20 :dispatch [:navigate-to :screens/wallet.check-your-backup]}]]]})
|
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/store-secret-phrase store-secret-phrase)
|
|
||||||
|
|
||||||
(defn new-keypair-created
|
|
||||||
[{:keys [db]} [{:keys [new-keypair]}]]
|
|
||||||
{:db (assoc-in db [:wallet :ui :create-account :new-keypair] new-keypair)
|
|
||||||
:fx [[:dispatch [:navigate-back-to :wallet-create-account]]]})
|
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/new-keypair-created new-keypair-created)
|
|
||||||
|
|
||||||
(defn new-keypair-continue
|
|
||||||
[{:keys [db]} [{:keys [keypair-name]}]]
|
|
||||||
(let [secret-phrase (get-in db [:wallet :ui :create-account :secret-phrase])]
|
|
||||||
{:fx [[:effects.wallet/create-account-from-mnemonic
|
|
||||||
{:secret-phrase secret-phrase
|
|
||||||
:keypair-name keypair-name}]]}))
|
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/new-keypair-continue new-keypair-continue)
|
|
||||||
|
|
||||||
(defn clear-new-keypair
|
|
||||||
[{:keys [db]}]
|
|
||||||
{:db (update-in db [:wallet :ui :create-account] dissoc :new-keypair)})
|
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/clear-new-keypair clear-new-keypair)
|
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:wallet/blockchain-status-changed
|
:wallet/blockchain-status-changed
|
||||||
(fn [{:keys [db]} [{:keys [message]}]]
|
(fn [{:keys [db]} [{:keys [message]}]]
|
||||||
|
|
|
@ -24,37 +24,6 @@
|
||||||
result-db (:db effects)]
|
result-db (:db effects)]
|
||||||
(is (match? result-db expected-db))))))
|
(is (match? result-db expected-db))))))
|
||||||
|
|
||||||
(deftest store-secret-phrase
|
|
||||||
(let [db {}
|
|
||||||
props [{:secret-phrase "test-secret" :random-phrase "random-test"}]
|
|
||||||
expected-db {:wallet {:ui {:create-account {:secret-phrase "test-secret"
|
|
||||||
:random-phrase "random-test"}}}}
|
|
||||||
effects (events/store-secret-phrase {:db db} props)
|
|
||||||
result-db (:db effects)]
|
|
||||||
(is (match? result-db expected-db))))
|
|
||||||
|
|
||||||
(deftest new-keypair-created
|
|
||||||
(let [db {}
|
|
||||||
props [{:new-keypair "test-keypair"}]
|
|
||||||
expected-db {:wallet {:ui {:create-account {:new-keypair "test-keypair"}}}}
|
|
||||||
effects (events/new-keypair-created {:db db} props)
|
|
||||||
result-db (:db effects)]
|
|
||||||
(is (match? result-db expected-db))))
|
|
||||||
|
|
||||||
(deftest new-keypair-continue
|
|
||||||
(let [db {:wallet {:ui {:create-account {:secret-phrase "test-secret"}}}}
|
|
||||||
props [{:keypair-name "test-keypair"}]
|
|
||||||
expected-effects [[:effects.wallet/create-account-from-mnemonic
|
|
||||||
{:secret-phrase "test-secret" :keypair-name "test-keypair"}]]
|
|
||||||
effects (events/new-keypair-continue {:db db} props)]
|
|
||||||
(is (match? effects {:fx expected-effects}))))
|
|
||||||
|
|
||||||
(deftest clear-new-keypair
|
|
||||||
(let [db {:wallet {:ui {:create-account {:new-keypair "test-keypair"}}}}
|
|
||||||
expected-db {:wallet {:ui {:create-account {}}}}
|
|
||||||
effects (events/clear-new-keypair {:db db})]
|
|
||||||
(is (match? (:db effects) expected-db))))
|
|
||||||
|
|
||||||
(deftest store-collectibles
|
(deftest store-collectibles
|
||||||
(testing "flush-collectibles"
|
(testing "flush-collectibles"
|
||||||
(let [collectible-1 {:collectible-data {:image-url "https://..." :animation-url "https://..."}
|
(let [collectible-1 {:collectible-data {:image-url "https://..." :animation-url "https://..."}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
status-im.contexts.profile.settings.events
|
status-im.contexts.profile.settings.events
|
||||||
status-im.contexts.shell.share.events
|
status-im.contexts.shell.share.events
|
||||||
status-im.contexts.syncing.events
|
status-im.contexts.syncing.events
|
||||||
|
status-im.contexts.wallet.create-account.events
|
||||||
status-im.contexts.wallet.effects
|
status-im.contexts.wallet.effects
|
||||||
status-im.contexts.wallet.events
|
status-im.contexts.wallet.events
|
||||||
status-im.contexts.wallet.send.events
|
status-im.contexts.wallet.send.events
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
(defonce ^:private feature-flags-config
|
(defonce ^:private feature-flags-config
|
||||||
(reagent/atom
|
(reagent/atom
|
||||||
{::wallet.edit-default-keypair true
|
{::wallet.edit-default-keypair (enabled-in-env? :FLAG_EDIT_DEFAULT_KEYPAIR)
|
||||||
::wallet.bridge-token (enabled-in-env? :FLAG_BRIDGE_TOKEN_ENABLED)
|
::wallet.bridge-token (enabled-in-env? :FLAG_BRIDGE_TOKEN_ENABLED)
|
||||||
::wallet.edit-derivation-path (enabled-in-env? :FLAG_EDIT_DERIVATION_PATH)
|
::wallet.edit-derivation-path (enabled-in-env? :FLAG_EDIT_DERIVATION_PATH)
|
||||||
::wallet.remove-account (enabled-in-env? :FLAG_REMOVE_ACCOUNT_ENABLED)
|
::wallet.remove-account (enabled-in-env? :FLAG_REMOVE_ACCOUNT_ENABLED)
|
||||||
|
|
|
@ -126,6 +126,12 @@
|
||||||
(fn [profile]
|
(fn [profile]
|
||||||
(:peer-syncing-enabled? profile)))
|
(:peer-syncing-enabled? profile)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
:profile/compressed-key
|
||||||
|
:<- [:profile/profile]
|
||||||
|
(fn [{:keys [compressed-key]}]
|
||||||
|
compressed-key))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:multiaccount/contact
|
:multiaccount/contact
|
||||||
:<- [:profile/profile]
|
:<- [:profile/profile]
|
||||||
|
@ -351,6 +357,12 @@
|
||||||
(fn [[profile ens-names port font-file] [_ avatar-opts]]
|
(fn [[profile ens-names port font-file] [_ avatar-opts]]
|
||||||
(replace-multiaccount-image-uri profile ens-names port font-file avatar-opts)))
|
(replace-multiaccount-image-uri profile ens-names port font-file avatar-opts)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
:profile/image
|
||||||
|
:<- [:profile/profile-with-image]
|
||||||
|
(fn [profile]
|
||||||
|
(profile.utils/photo profile)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:profile/login-profile
|
:profile/login-profile
|
||||||
:<- [:profile/login]
|
:<- [:profile/login]
|
||||||
|
|
|
@ -99,6 +99,11 @@
|
||||||
:<- [:wallet]
|
:<- [:wallet]
|
||||||
:-> :keypairs)
|
:-> :keypairs)
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:wallet/selected-keypair-uid
|
||||||
|
:<- [:wallet/create-account]
|
||||||
|
:-> :selected-keypair-uid)
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/accounts
|
:wallet/accounts
|
||||||
:<- [:wallet]
|
:<- [:wallet]
|
||||||
|
|
|
@ -535,3 +535,10 @@
|
||||||
#(assoc-in % [:wallet :ui :search-address :valid-ens-or-address?] true))
|
#(assoc-in % [:wallet :ui :search-address :valid-ens-or-address?] true))
|
||||||
(is
|
(is
|
||||||
(rf/sub [sub-name]))))
|
(rf/sub [sub-name]))))
|
||||||
|
|
||||||
|
(h/deftest-sub :wallet/selected-keypair-uid
|
||||||
|
[sub-name]
|
||||||
|
(testing "returns selected keypair uid"
|
||||||
|
(swap! rf-db/app-db
|
||||||
|
#(assoc-in % [:wallet :ui :create-account :selected-keypair-uid] "key-uid"))
|
||||||
|
(is (= "key-uid" (rf/sub [sub-name])))))
|
||||||
|
|
Loading…
Reference in New Issue