|
9 | 9 | [status-im.ui.components.copyable-text :as copyable-text]
|
10 | 10 | [reagent.core :as reagent]
|
11 | 11 | [quo.core :as quo]
|
12 |
| - [status-im.ui.components.topbar :as topbar])) |
| 12 | + [status-im.ui.components.topbar :as topbar] |
| 13 | + [status-im.utils.security :as security])) |
| 14 | + |
| 15 | +(defn not-valid-password? [password] |
| 16 | + (< (count (security/safe-unmask-data password)) 6)) |
| 17 | + |
| 18 | +(defn delete-account [_] |
| 19 | + (let [password (reagent/atom nil) |
| 20 | + text-input-ref (atom nil) |
| 21 | + error (reagent/atom nil)] |
| 22 | + (fn [account] |
| 23 | + (when (and @text-input-ref error (not @password)) |
| 24 | + (.clear ^js @text-input-ref)) |
| 25 | + [react/view {:padding 20 :width 300} |
| 26 | + [quo/text-input |
| 27 | + {:style {:margin-bottom 40} |
| 28 | + :label (i18n/label :t/password) |
| 29 | + :show-cancel false |
| 30 | + :secure-text-entry true |
| 31 | + :return-key-type :next |
| 32 | + :on-submit-editing nil |
| 33 | + :auto-focus true |
| 34 | + :on-change-text #(reset! password (security/mask-data %)) |
| 35 | + :get-ref #(reset! text-input-ref %) |
| 36 | + :error (when (and @error (not @password)) |
| 37 | + (if (= :wrong-password @error) |
| 38 | + (i18n/label :t/wrong-password) |
| 39 | + (str @error)))}] |
| 40 | + [quo/button {:on-press (fn [] |
| 41 | + (re-frame/dispatch [:wallet.accounts/delete-key |
| 42 | + account |
| 43 | + @password |
| 44 | + #(reset! error :wrong-password)]) |
| 45 | + (reset! password nil)) |
| 46 | + :theme :negative |
| 47 | + :accessibility-label :delete-account-confirm |
| 48 | + :disabled (not-valid-password? @password)} |
| 49 | + (i18n/label :t/delete)]]))) |
13 | 50 |
|
14 | 51 | (defview colors-popover [selected-color on-press]
|
15 | 52 | (letsubs [width [:dimensions/window-width]]
|
|
19 | 56 | (for [color colors/account-colors]
|
20 | 57 | ^{:key color}
|
21 | 58 | [react/touchable-highlight {:on-press #(on-press color)}
|
22 |
| - [react/view {:height 52 :background-color color :border-radius 8 :width (* 0.7 width) |
23 |
| - :justify-content :center :padding-left 12 :margin-bottom 16} |
| 59 | + [react/view {:height 52 :background-color color :border-radius 8 :width (* 0.7 width) |
| 60 | + :justify-content :center :padding-left 12 :margin-bottom 16} |
24 | 61 | [react/view {:height 32 :width 32 :border-radius 20 :align-items :center :justify-content :center
|
25 | 62 | :background-color colors/black-transparent}
|
26 | 63 | (when (= selected-color color)
|
|
42 | 79 | (letsubs [{:keys [address color path type] :as account} [:multiaccount/current-account]
|
43 | 80 | new-account (reagent/atom nil)
|
44 | 81 | keycard? [:keycard-multiaccount?]]
|
45 |
| - [react/keyboard-avoiding-view {:style {:flex 1} |
| 82 | + [react/keyboard-avoiding-view {:style {:flex 1} |
46 | 83 | :ignore-offset true}
|
47 | 84 | [topbar/topbar
|
48 | 85 | (cond-> {:title (i18n/label :t/account-settings)}
|
49 |
| - (and @new-account (not= "" (:name @new-account))) |
50 |
| - (assoc :right-accessories [{:label (i18n/label :t/apply) |
51 |
| - :on-press |
52 |
| - #(do |
53 |
| - (re-frame/dispatch [:wallet.accounts/save-account |
54 |
| - account |
55 |
| - @new-account]) |
56 |
| - (reset! new-account nil))}]))] |
| 86 | + (and @new-account (not= "" (:name @new-account))) |
| 87 | + (assoc :right-accessories [{:label (i18n/label :t/apply) |
| 88 | + :on-press |
| 89 | + #(do |
| 90 | + (re-frame/dispatch [:wallet.accounts/save-account |
| 91 | + account |
| 92 | + @new-account]) |
| 93 | + (reset! new-account nil))}]))] |
57 | 94 | [react/scroll-view {:keyboard-should-persist-taps :handled
|
58 | 95 | :style {:flex 1}}
|
59 | 96 | [react/view {:padding-bottom 28 :padding-top 10}
|
|
72 | 109 | (swap! new-account assoc :color new-color)
|
73 | 110 | (re-frame/dispatch [:hide-popover]))]
|
74 | 111 | :style {:max-height "60%"}}])}
|
75 |
| - [react/view {:height 52 :margin-top 12 :background-color (or (:color @new-account) color) |
| 112 | + [react/view {:height 52 :margin-top 12 :background-color (or (:color @new-account) color) |
76 | 113 | :border-radius 8
|
77 |
| - :align-items :flex-end :justify-content :center :padding-right 12} |
| 114 | + :align-items :flex-end :justify-content :center :padding-right 12} |
78 | 115 | [icons/icon :main-icons/dropdown {:color colors/white}]]]
|
79 | 116 | [property (i18n/label :t/type)
|
80 | 117 | (case type
|
81 |
| - :watch (i18n/label :t/watch-only) |
| 118 | + :watch (i18n/label :t/watch-only) |
82 | 119 | (:key :seed) (i18n/label :t/off-status-tree)
|
83 | 120 | (i18n/label :t/on-status-tree))]
|
84 | 121 | [property (i18n/label :t/wallet-address)
|
|
98 | 135 | (i18n/label (if keycard?
|
99 | 136 | :t/keycard
|
100 | 137 | :t/this-device))])]
|
101 |
| - (when (= type :watch) |
| 138 | + (when (#{:key :seed :watch} type) |
102 | 139 | [react/view
|
103 | 140 | [react/view {:margin-bottom 8 :margin-top 28 :height 1 :background-color colors/gray-lighter}]
|
104 | 141 | [quo/list-item
|
105 | 142 | {:theme :negative
|
106 | 143 | :title (i18n/label :t/delete-account)
|
107 |
| - :on-press #(re-frame/dispatch [:wallet.settings/show-delete-account-confirmation account])}]])]]])) |
| 144 | + :on-press #(if (= :watch type) |
| 145 | + (re-frame/dispatch [:wallet.settings/show-delete-account-confirmation account]) |
| 146 | + (re-frame/dispatch [:show-popover {:view [delete-account account]}]))}]])]]])) |
0 commit comments