Skip to content

Commit 2d78a8b

Browse files
J-Son89yevh-berdnyk
authored andcommitted
chore(wallet): hook up qr scanner on watch only flow. (#17829)
1 parent 3952bfe commit 2d78a8b

File tree

15 files changed

+219
-82
lines changed

15 files changed

+219
-82
lines changed

src/quo/components/info/info_message.cljs

+16-18
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,17 @@
33
[quo.components.icon :as quo.icons]
44
[quo.components.markdown.text :as text]
55
[quo.foundations.colors :as colors]
6-
[quo.theme :as theme]
6+
[quo.theme :as quo.theme]
77
[react-native.core :as rn]))
88

9-
(def themes
10-
{:light {:default colors/neutral-50
11-
:success colors/success-50
12-
:error colors/danger-50}
13-
:dark {:default colors/neutral-40
14-
:success colors/success-60
15-
:error colors/danger-60}})
16-
179
(defn get-color
18-
[k]
19-
(get-in themes [(theme/get-theme) k]))
10+
[k theme]
11+
(case k
12+
:success (colors/resolve-color :success theme)
13+
:error (colors/resolve-color :danger theme)
14+
(colors/theme-colors colors/neutral-50 colors/neutral-40 theme)))
2015

21-
(defn info-message
16+
(defn view-internal
2217
"[info-message opts \"message\"]
2318
opts
2419
{:type :default/:success/:error
@@ -27,11 +22,11 @@
2722
:text-color colors/white ;; text color override
2823
:icon-color colors/white ;; icon color override
2924
:no-icon-color? false ;; disable tint color for icon"
30-
[{:keys [type size icon text-color icon-color no-icon-color? style]} message]
25+
[{:keys [type size theme icon text-color icon-color no-icon-color? style accessibility-label]} message]
3126
(let [weight (if (= size :default) :regular :medium)
3227
icon-size (if (= size :default) 16 12)
3328
size (if (= size :default) :paragraph-2 :label)
34-
text-color (or text-color (get-color type))
29+
text-color (or text-color (get-color type theme))
3530
icon-color (or icon-color text-color)]
3631
[rn/view
3732
{:style (merge {:flex-direction :row
@@ -42,7 +37,10 @@
4237
:no-color no-icon-color?
4338
:size icon-size}]
4439
[text/text
45-
{:size size
46-
:weight weight
47-
:style {:color text-color
48-
:margin-horizontal 4}} message]]))
40+
{:accessibility-label accessibility-label
41+
:size size
42+
:weight weight
43+
:style {:color text-color
44+
:margin-horizontal 4}} message]]))
45+
46+
(def info-message (quo.theme/with-theme view-internal))

src/status_im2/common/password_authentication/view.cljs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
:on-change-text #(reset! entered-password %)}]
3232
(when (not-empty error)
3333
[quo/info-message
34-
{:type :error
35-
:size :default
36-
:icon :i/info
37-
:style {:margin-top 8}}
34+
{:type :error
35+
:size :default
36+
:icon :i/info
37+
:containstyle {:margin-top 8}}
3838
(i18n/label :t/oops-wrong-password)])
3939
[quo/button
4040
{:container-style {:margin-bottom 12 :margin-top 40}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(ns status-im2.contexts.wallet.add-address-to-watch.component-spec
2+
(:require
3+
[re-frame.core :as re-frame]
4+
[status-im2.contexts.wallet.add-address-to-watch.view :as add-address-to-watch]
5+
[test-helpers.component :as h]))
6+
7+
(defn setup-subs
8+
[subscriptions]
9+
(doseq [keyval subscriptions]
10+
(re-frame/reg-sub
11+
(key keyval)
12+
(fn [_] (val keyval)))))
13+
14+
(h/describe "select address for watch only account"
15+
(h/test "validation messages show for already used addressed"
16+
(setup-subs {:wallet/scanned-address nil
17+
:wallet/addresses (set
18+
["0x12E838Ae1f769147b12956485dc56e57138f3AC8"
19+
"0x22E838Ae1f769147b12956485dc56e57138f3AC8"])
20+
:profile/customization-color :blue})
21+
(h/render [add-address-to-watch/view])
22+
(h/is-falsy (h/query-by-label-text :error-message))
23+
(h/fire-event :change-text
24+
(h/get-by-label-text :add-address-to-watch)
25+
"0x12E838Ae1f769147b12956485dc56e57138f3AC8")
26+
(h/is-truthy (h/get-by-translation-text :address-already-in-use))))
27+
28+
(h/test "validation messages show for invalid address"
29+
(setup-subs {:wallet/scanned-address nil
30+
:wallet/addresses (set
31+
["0x12E838Ae1f769147b12956485dc56e57138f3AC8"
32+
"0x22E838Ae1f769147b12956485dc56e57138f3AC8"])
33+
:profile/customization-color :blue})
34+
(h/render [add-address-to-watch/view])
35+
(h/is-falsy (h/query-by-label-text :error-message))
36+
(h/fire-event :change-text (h/get-by-label-text :add-address-to-watch) "0x12E838Ae1f769147b")
37+
(h/is-truthy (h/get-by-translation-text :invalid-address)))
38+

src/status_im2/contexts/wallet/add_address_to_watch/confirm_address/style.cljs

-11
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,7 @@
33
(def container
44
{:flex 1})
55

6-
(def input
7-
{:margin-right 12
8-
:flex 1})
9-
106
(def data-item
117
{:margin-horizontal 20
128
:padding-vertical 8
139
:padding-horizontal 12})
14-
15-
(defn button-container
16-
[bottom]
17-
{:position :absolute
18-
:bottom (+ bottom 12)
19-
:left 20
20-
:right 20})

src/status_im2/contexts/wallet/add_address_to_watch/confirm_address/view.cljs

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
[clojure.string :as string]
44
[quo.core :as quo]
55
[quo.foundations.colors :as colors]
6-
[quo.theme :as quo.theme]
76
[re-frame.core :as re-frame]
87
[react-native.core :as rn]
98
[reagent.core :as reagent]
@@ -14,13 +13,12 @@
1413
[utils.i18n :as i18n]
1514
[utils.re-frame :as rf]))
1615

17-
(defn- view-internal
16+
(defn view
1817
[]
1918
(let [{:keys [address]} (rf/sub [:get-screen-params])
2019
number-of-accounts (count (rf/sub [:profile/wallet-accounts]))
2120
account-name (reagent/atom (i18n/label :t/default-account-name
2221
{:number (inc number-of-accounts)}))
23-
address-title (i18n/label :t/watch-address)
2422
account-color (reagent/atom (rand-nth colors/account-colors))
2523
account-emoji (reagent/atom (emoji-picker.utils/random-emoji))
2624
on-change-name #(reset! account-name %)
@@ -40,8 +38,9 @@
4038
:on-change-name on-change-name
4139
:on-change-color on-change-color
4240
:on-change-emoji on-change-emoji
41+
:watch-only? true
4342
:bottom-action? true
44-
:bottom-action-label :t/create-account
43+
:bottom-action-label :t/add-watched-address
4544
:bottom-action-props {:customization-color @account-color
4645
:disabled? (string/blank? @account-name)
4746
:on-press #(re-frame/dispatch [:navigate-to
@@ -51,11 +50,9 @@
5150
:right-icon :i/advanced
5251
:icon-right? true
5352
:emoji @account-emoji
54-
:title address-title
53+
:title (i18n/label :t/watched-address)
5554
:subtitle address
5655
:status :default
5756
:size :default
5857
:container-style style/data-item
5958
:on-press #(js/alert "To be implemented")}]]])))
60-
61-
(def view (quo.theme/with-theme view-internal))

src/status_im2/contexts/wallet/add_address_to_watch/style.cljs

+16-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@
55
:margin-top 12
66
:margin-bottom 20})
77

8-
(def input-container
9-
{:flex-direction :row
10-
:padding-horizontal 20
11-
:align-items :flex-end})
12-
138
(def button-container
149
{:position :absolute
1510
:bottom 22
1611
:left 20
1712
:right 20})
13+
14+
(def scan
15+
{:align-self
16+
:flex-end})
17+
18+
(def input
19+
{:flex 1
20+
:margin-right 12})
21+
22+
(def input-container
23+
{:flex-direction :row
24+
:margin-horizontal 20})
25+
26+
(def info-message
27+
{:margin-top 8
28+
:margin-left 20})

src/status_im2/contexts/wallet/add_address_to_watch/view.cljs

+88-25
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,114 @@
22
(:require
33
[clojure.string :as string]
44
[quo.core :as quo]
5-
[quo.theme :as quo.theme]
6-
[re-frame.core :as re-frame]
75
[react-native.clipboard :as clipboard]
86
[react-native.core :as rn]
97
[reagent.core :as reagent]
108
[status-im2.contexts.wallet.add-address-to-watch.style :as style]
9+
[status-im2.contexts.wallet.common.validation :as validation]
1110
[utils.i18n :as i18n]
1211
[utils.re-frame :as rf]))
1312

14-
(defn view-internal
13+
(defn validate-message
14+
[addresses]
15+
(fn [s]
16+
(cond
17+
(or (= s nil) (= s "")) nil
18+
(contains? addresses s) (i18n/label :t/address-already-in-use)
19+
(not (or (validation/eth-address? s)
20+
(validation/ens-name? s))) (i18n/label :t/invalid-address)
21+
:else nil)))
22+
23+
(defn- address-input
24+
[{:keys [input-value validation-msg validate
25+
clear-input]}]
26+
(let [scanned-address (rf/sub [:wallet/scanned-address])
27+
empty-input? (and (string/blank? @input-value)
28+
(string/blank? scanned-address))
29+
30+
on-change-text (fn [new-text]
31+
(reset! validation-msg (validate new-text))
32+
(reset! input-value new-text)
33+
(when (and scanned-address (not= scanned-address new-text))
34+
(rf/dispatch [:wallet/clean-scanned-address])))
35+
paste-on-input #(clipboard/get-string
36+
(fn [clipboard-text]
37+
(on-change-text clipboard-text)))]
38+
(rn/use-effect (fn []
39+
(when-not (string/blank? scanned-address)
40+
(on-change-text scanned-address)))
41+
[scanned-address])
42+
[rn/view
43+
{:style style/input-container}
44+
[quo/input
45+
{:accessibility-label :add-address-to-watch
46+
:placeholder (i18n/label :t/address-placeholder)
47+
:container-style style/input
48+
:label (i18n/label :t/eth-or-ens)
49+
:auto-capitalize :none
50+
:multiline? true
51+
:on-clear clear-input
52+
:return-key-type :done
53+
:clearable? (not empty-input?)
54+
:on-change-text on-change-text
55+
:button (when empty-input?
56+
{:on-press paste-on-input
57+
:text (i18n/label :t/paste)})
58+
:value @input-value}]
59+
[quo/button
60+
{:type :outline
61+
:on-press (fn []
62+
(rn/dismiss-keyboard!)
63+
(rf/dispatch [:open-modal :scan-address]))
64+
:container-style style/scan
65+
:size 40
66+
:icon-only? true}
67+
:i/scan]]))
68+
69+
(defn view
1570
[]
16-
(let [input-value (reagent/atom "")
71+
(let [addresses (rf/sub [:wallet/addresses])
72+
input-value (reagent/atom nil)
73+
validate (validate-message (set addresses))
74+
validation-msg (reagent/atom (validate
75+
@input-value))
76+
clear-input (fn []
77+
(reset! input-value nil)
78+
(reset! validation-msg nil)
79+
(rf/dispatch [:wallet/clean-scanned-address]))
1780
customization-color (rf/sub [:profile/customization-color])]
81+
(rf/dispatch [:wallet/clean-scanned-address])
1882
(fn []
1983
[rn/view
2084
{:style {:flex 1}}
2185
[quo/page-nav
2286
{:type :no-title
2387
:icon-name :i/close
24-
:on-press #(rf/dispatch [:navigate-back])}]
88+
:on-press (fn []
89+
(rf/dispatch [:wallet/clean-scanned-address])
90+
(rf/dispatch [:navigate-back]))}]
2591
[quo/text-combinations
2692
{:container-style style/header-container
2793
:title (i18n/label :t/add-address)
2894
:description (i18n/label :t/enter-eth)}]
29-
[rn/view {:style style/input-container}
30-
[quo/input
31-
{:label (i18n/label :t/eth-or-ens)
32-
:button {:on-press (fn [] (clipboard/get-string #(reset! input-value %)))
33-
:text (i18n/label :t/paste)}
34-
:placeholder (str "0x123abc... " (string/lower-case (i18n/label :t/or)) " bob.eth")
35-
:container-style {:margin-right 12
36-
:flex 1}
37-
:weight :monospace
38-
:on-change-text #(reset! input-value %)
39-
:default-value @input-value}]
40-
[quo/button
41-
{:icon-only? true
42-
:type :outline} :i/scan]]
95+
[:f> address-input
96+
{:input-value input-value
97+
:validate validate
98+
:validation-msg validation-msg
99+
:clear-input clear-input}]
100+
(when @validation-msg
101+
[quo/info-message
102+
{:accessibility-label :error-message
103+
:size :default
104+
:icon :i/info
105+
:type :error
106+
:style style/info-message}
107+
@validation-msg])
43108
[quo/button
44109
{:customization-color customization-color
45-
:disabled? (clojure.string/blank? @input-value)
46-
:on-press #(re-frame/dispatch [:navigate-to
47-
:confirm-address-to-watch
48-
{:address @input-value}])
110+
:disabled? (string/blank? @input-value)
111+
:on-press #(rf/dispatch [:navigate-to
112+
:confirm-address-to-watch
113+
{:address @input-value}])
49114
:container-style style/button-container}
50115
(i18n/label :t/continue)]])))
51-
52-
(def view (quo.theme/with-theme view-internal))

src/status_im2/contexts/wallet/common/screen_base/create_or_edit_account/view.cljs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
(ns status-im2.contexts.wallet.common.screen-base.create-or-edit-account.view
22
(:require [quo.core :as quo]
3-
[quo.theme :as quo.theme]
43
[react-native.core :as rn]
54
[react-native.safe-area :as safe-area]
65
[status-im2.constants :as constants]
76
[status-im2.contexts.wallet.common.screen-base.create-or-edit-account.style :as style]
87
[utils.i18n :as i18n]
98
[utils.re-frame :as rf]))
109

11-
(defn- view-internal
10+
(defn view
1211
[{:keys [margin-top? page-nav-right-side account-name account-color account-emoji on-change-name
1312
on-change-color
1413
on-change-emoji on-focus on-blur section-label bottom-action?
1514
bottom-action-label bottom-action-props
16-
custom-bottom-action]} & children]
15+
custom-bottom-action watch-only?]} & children]
1716
(let [{:keys [top bottom]} (safe-area/get-insets)
1817
margin-top (if (false? margin-top?) 0 top)
1918
{window-width :width} (rn/get-window)]
@@ -36,7 +35,7 @@
3635
{:customization-color account-color
3736
:size 80
3837
:emoji account-emoji
39-
:type :default}]
38+
:type (if watch-only? :watch-only :default)}]
4039
[quo/button
4140
{:size 32
4241
:type :grey
@@ -81,5 +80,3 @@
8180
:type :primary}
8281
bottom-action-props)
8382
(i18n/label bottom-action-label)])])]))
84-
85-
(def view (quo.theme/with-theme view-internal))

0 commit comments

Comments
 (0)