|
1 | 1 | (ns status-im.contexts.wallet.create-account.select-keypair.view
|
2 | 2 | (:require
|
| 3 | + [clojure.string :as string] |
3 | 4 | [quo.core :as quo]
|
4 | 5 | [react-native.core :as rn]
|
| 6 | + [status-im.constants :as constants] |
5 | 7 | [status-im.contexts.profile.utils :as profile.utils]
|
6 | 8 | [status-im.contexts.wallet.create-account.select-keypair.style :as style]
|
7 | 9 | [utils.address :as utils]
|
8 | 10 | [utils.i18n :as i18n]
|
9 | 11 | [utils.re-frame :as rf]))
|
10 | 12 |
|
11 |
| -(defn keypair-options |
| 13 | +(defn- keypair-options |
12 | 14 | []
|
13 | 15 | [quo/action-drawer
|
14 | 16 | [[{:icon :i/add
|
|
26 | 28 | :accessibility-label :import-private-key
|
27 | 29 | :label (i18n/label :t/import-private-key)}]]])
|
28 | 30 |
|
29 |
| -(def accounts |
30 |
| - [{:account-props {:customization-color :turquoise |
31 |
| - :size 32 |
32 |
| - :emoji "\uD83C\uDFB2" |
33 |
| - :type :default |
34 |
| - :name "Trip to Vegas" |
35 |
| - :address "0x0ah...71a"} |
36 |
| - :networks [{:network-name :ethereum :short-name "eth"} |
37 |
| - {:network-name :optimism :short-name "opt"}] |
38 |
| - :state :default |
39 |
| - :action :none}]) |
| 31 | +(defn- parse-accounts |
| 32 | + [given-accounts] |
| 33 | + (->> given-accounts |
| 34 | + (filter (fn [{:keys [path]}] |
| 35 | + (not (string/starts-with? path constants/path-eip1581)))) |
| 36 | + (map (fn [{:keys [customization-color emoji name address]}] |
| 37 | + {:account-props {:customization-color customization-color |
| 38 | + :size 32 |
| 39 | + :emoji emoji |
| 40 | + :type :default |
| 41 | + :name name |
| 42 | + :address address} |
| 43 | + :networks [{:network-name :ethereum :short-name "eth"} |
| 44 | + {:network-name :optimism :short-name "opt"} |
| 45 | + {:network-name :arbitrum :short-name "arb1"}] |
| 46 | + :state :default |
| 47 | + :action :none})))) |
40 | 48 |
|
| 49 | +(defn- keypair |
| 50 | + [item index _ {:keys [profile-picture compressed-key]}] |
| 51 | + (let [main-account (first (:accounts item)) |
| 52 | + color (:customization-color main-account) |
| 53 | + accounts (parse-accounts (:accounts item))] |
| 54 | + [quo/keypair |
| 55 | + {:customization-color color |
| 56 | + :profile-picture (when (zero? index) profile-picture) |
| 57 | + :status-indicator false |
| 58 | + :type (if (zero? index) :default-keypair :other) |
| 59 | + :stored :on-device |
| 60 | + :on-options-press #(js/alert "Options pressed") |
| 61 | + :action :selector |
| 62 | + :blur? false |
| 63 | + :details {:full-name (:name item) |
| 64 | + :address (when (zero? index) |
| 65 | + (utils/get-shortened-compressed-key compressed-key))} |
| 66 | + :accounts accounts |
| 67 | + :default-selected? (zero? index) |
| 68 | + :container-style {:margin-horizontal 20 |
| 69 | + :margin-vertical 8}}])) |
41 | 70 | (defn view
|
42 | 71 | []
|
43 |
| - (let [{:keys [public-key compressed-key |
44 |
| - customization-color]} (rf/sub [:profile/profile]) |
45 |
| - [display-name _] (rf/sub [:contacts/contact-two-names-by-identity public-key]) |
46 |
| - profile-with-image (rf/sub [:profile/profile-with-image]) |
47 |
| - profile-picture (profile.utils/photo profile-with-image)] |
| 72 | + (let [{:keys [compressed-key customization-color]} (rf/sub [:profile/profile]) |
| 73 | + profile-with-image (rf/sub [:profile/profile-with-image]) |
| 74 | + keypairs (rf/sub [:wallet/keypairs]) |
| 75 | + profile-picture (profile.utils/photo profile-with-image)] |
48 | 76 | [rn/view {:style {:flex 1}}
|
49 | 77 | [quo/page-nav
|
50 | 78 | {:icon-name :i/close
|
|
60 | 88 | [:show-bottom-sheet {:content keypair-options}])}
|
61 | 89 | :description :text
|
62 | 90 | :description-text (i18n/label :t/keypairs-description)}]
|
63 |
| - [quo/keypair |
64 |
| - {:customization-color customization-color |
65 |
| - :profile-picture profile-picture |
66 |
| - :status-indicator false |
67 |
| - :type :default-keypair |
68 |
| - :stored :on-device |
69 |
| - :on-options-press #(js/alert "Options pressed") |
70 |
| - :action :selector |
71 |
| - :blur? false |
72 |
| - :details {:full-name display-name |
73 |
| - :address (utils/get-shortened-compressed-key compressed-key)} |
74 |
| - :accounts accounts |
75 |
| - :container-style {:margin-horizontal 20 |
76 |
| - :margin-vertical 8}}] |
| 91 | + [rn/flat-list |
| 92 | + {:data keypairs |
| 93 | + :render-fn keypair |
| 94 | + :render-data {:profile-picture profile-picture |
| 95 | + :compressed-key compressed-key} |
| 96 | + :content-container-style {:padding-bottom 60}}] |
77 | 97 | [quo/bottom-actions
|
78 | 98 | {:actions :one-action
|
79 | 99 | :button-one-label (i18n/label :t/confirm-account-origin)
|
|
0 commit comments