Skip to content

Commit 9df6a14

Browse files
briansztamfateribrkhalil
authored andcommitted
feat: implement saved address component (#17398)
Signed-off-by: Brian Sztamfater <[email protected]>
1 parent 87a4460 commit 9df6a14

File tree

7 files changed

+211
-0
lines changed

7 files changed

+211
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
(ns quo2.components.list-items.saved-address.component-spec
2+
(:require [test-helpers.component :as h]
3+
[quo2.components.list-items.saved-address.view :as saved-address]
4+
[quo2.foundations.colors :as colors]))
5+
6+
(h/describe "List items: saved address"
7+
(h/test "default render"
8+
(h/render [saved-address/view])
9+
(h/is-truthy (h/query-by-label-text :container)))
10+
11+
(h/test "on-press-in changes state to :pressed"
12+
(h/render [saved-address/view])
13+
(h/fire-event :on-press-in (h/get-by-label-text :container))
14+
(h/wait-for #(h/has-style (h/query-by-label-text :container)
15+
{:backgroundColor (colors/custom-color :blue 50 5)})))
16+
17+
(h/test "on-press-in changes state to :pressed with blur? enabled"
18+
(h/render [saved-address/view {:blur? true}])
19+
(h/fire-event :on-press-in (h/get-by-label-text :container))
20+
(h/wait-for #(h/has-style (h/query-by-label-text :container)
21+
{:backgroundColor colors/white-opa-5})))
22+
23+
(h/test "on-press-out changes state to :active"
24+
(h/render [saved-address/view])
25+
(h/fire-event :on-press-in (h/get-by-label-text :container))
26+
(h/fire-event :on-press-out (h/get-by-label-text :container))
27+
(h/wait-for #(h/has-style (h/query-by-label-text :container)
28+
{:backgroundColor (colors/custom-color :blue 50 10)})))
29+
30+
(h/test "on-press-out changes state to :active with blur? enabled"
31+
(h/render [saved-address/view {:blur? true}])
32+
(h/fire-event :on-press-in (h/get-by-label-text :container))
33+
(h/fire-event :on-press-out (h/get-by-label-text :container))
34+
(h/wait-for #(h/has-style (h/query-by-label-text :container)
35+
{:backgroundColor colors/white-opa-10})))
36+
37+
(h/test "on-press-out calls on-press"
38+
(let [on-press (h/mock-fn)]
39+
(h/render [saved-address/view {:on-press on-press}])
40+
(h/fire-event :on-press-in (h/get-by-label-text :container))
41+
(h/fire-event :on-press-out (h/get-by-label-text :container))
42+
(h/was-called on-press)))
43+
44+
(h/test "renders options button if type :action"
45+
(let [on-options-press (h/mock-fn)]
46+
(h/render [saved-address/view
47+
{:type :action
48+
:on-options-press on-options-press}])
49+
(h/is-truthy (h/query-by-label-text :options-button))
50+
(h/fire-event :on-press (h/get-by-label-text :options-button))
51+
(h/was-called on-options-press))))
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(ns quo2.components.list-items.saved-address.style
2+
(:require [quo2.foundations.colors :as colors]))
3+
4+
(defn- background-color
5+
[{:keys [state blur? customization-color]}]
6+
(cond (and (or (= state :pressed) (= state :selected)) (not blur?))
7+
(colors/custom-color customization-color 50 5)
8+
(and (or (= state :pressed) (= state :selected)) blur?)
9+
colors/white-opa-5
10+
(and (= state :active) (not blur?))
11+
(colors/custom-color customization-color 50 10)
12+
(and (= state :active) blur?)
13+
colors/white-opa-10
14+
(and (= state :pressed) blur?) colors/white-opa-10
15+
:else :transparent))
16+
17+
(defn container
18+
[props]
19+
{:height 56
20+
:border-radius 12
21+
:background-color (background-color props)
22+
:flex-direction :row
23+
:align-items :center
24+
:padding-horizontal 12
25+
:padding-vertical 6
26+
:justify-content :space-between})
27+
28+
(def left-container
29+
{:flex-direction :row
30+
:align-items :center})
31+
32+
(def name-text
33+
{:height 22})
34+
35+
(def account-container
36+
{:margin-left 8})
37+
38+
(defn account-address
39+
[blur? theme]
40+
{:color (if blur?
41+
colors/white-opa-40
42+
(colors/theme-colors colors/neutral-50 colors/neutral-40 theme))})
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
(ns quo2.components.list-items.saved-address.view
2+
(:require [quo2.components.avatars.wallet-user-avatar :as wallet-user-avatar]
3+
[quo2.components.markdown.text :as text]
4+
[quo2.foundations.colors :as colors]
5+
[quo2.theme :as quo.theme]
6+
[react-native.core :as rn]
7+
[quo2.components.list-items.saved-address.style :as style]
8+
[reagent.core :as reagent]
9+
[quo2.components.icon :as icon]
10+
[clojure.string :as string]))
11+
12+
(defn- left-container
13+
[{:keys [blur? theme name address customization-color]}]
14+
(let [names (remove string/blank? (string/split name " "))
15+
first-name (if (> (count names) 0) (first names) "")
16+
last-name (if (> (count names) 1) (last names) "")]
17+
[rn/view {:style style/left-container}
18+
[wallet-user-avatar/wallet-user-avatar
19+
{:size :medium
20+
:f-name first-name
21+
:l-name last-name
22+
:color customization-color}]
23+
[rn/view {:style style/account-container}
24+
[text/text
25+
{:weight :semi-bold
26+
:size :paragraph-1
27+
:style style/name-text}
28+
name]
29+
[text/text {:size :paragraph-2}
30+
[text/text
31+
{:size :paragraph-2
32+
:weight :monospace
33+
:style (style/account-address blur? theme)}
34+
address]]]]))
35+
36+
(defn- internal-view
37+
[]
38+
(let [state (reagent/atom :default)
39+
active? (atom false)
40+
timer (atom nil)
41+
on-press-in (fn []
42+
(when-not (= @state :selected)
43+
(reset! timer (js/setTimeout #(reset! state :pressed) 100))))]
44+
(fn [{:keys [blur? user-props customization-color
45+
on-press
46+
on-options-press
47+
theme]
48+
:or {customization-color :blue
49+
blur? false}}]
50+
(let [on-press-out (fn []
51+
(let [new-state (if @active? :default :active)]
52+
(when @timer (js/clearTimeout @timer))
53+
(reset! timer nil)
54+
(reset! active? (= new-state :active))
55+
(reset! state new-state)
56+
(when on-press
57+
(on-press))))]
58+
[rn/pressable
59+
{:style (style/container
60+
{:state @state :blur? blur? :customization-color customization-color})
61+
:on-press-in on-press-in
62+
:on-press-out on-press-out
63+
:accessibility-label :container}
64+
[left-container
65+
{:blur? blur?
66+
:theme theme
67+
:name (:name user-props)
68+
:address (:address user-props)
69+
:customization-color (:customization-color user-props)}]
70+
[rn/pressable
71+
{:accessibility-label :options-button
72+
:on-press #(when on-options-press
73+
(on-options-press))}
74+
[icon/icon :i/options
75+
{:color (if blur?
76+
colors/white-opa-70
77+
(colors/theme-colors colors/neutral-50 colors/neutral-40 theme))}]]]))))
78+
79+
(def view (quo.theme/with-theme internal-view))

src/quo2/core.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
quo2.components.list-items.dapp.view
7171
quo2.components.list-items.menu-item
7272
quo2.components.list-items.preview-list.view
73+
quo2.components.list-items.saved-address.view
7374
quo2.components.list-items.token-value.view
7475
quo2.components.list-items.user-list
7576
quo2.components.loaders.skeleton-list.view
@@ -261,6 +262,7 @@
261262
(def preview-list quo2.components.list-items.preview-list.view/view)
262263
(def user-list quo2.components.list-items.user-list/user-list)
263264
(def community-list-item quo2.components.list-items.community.view/view)
265+
(def saved-address quo2.components.list-items.saved-address.view/view)
264266
(def token-value quo2.components.list-items.token-value.view/view)
265267

266268
;;;; Loaders

src/quo2/core_spec.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
[quo2.components.list-items.channel.component-spec]
4141
[quo2.components.list-items.community.component-spec]
4242
[quo2.components.list-items.dapp.component-spec]
43+
[quo2.components.list-items.saved-address.component-spec]
4344
[quo2.components.list-items.token-value.component-spec]
4445
[quo2.components.loaders.skeleton-list.component-spec]
4546
[quo2.components.markdown.text-component-spec]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(ns status-im2.contexts.quo-preview.list-items.saved-address
2+
(:require [quo2.core :as quo]
3+
[reagent.core :as reagent]
4+
[status-im2.contexts.quo-preview.preview :as preview]))
5+
6+
(def descriptor
7+
[(preview/customization-color-option {:key :account-color})
8+
{:key :blur? :type :boolean}
9+
{:key :title :type :text}
10+
(preview/customization-color-option)])
11+
12+
(defn view
13+
[]
14+
(let [state (reagent/atom {:type :default
15+
:customization-color :blue
16+
:account-color :flamingo
17+
:title "Alisher Yakupov"
18+
:address "0x21a...49e"
19+
:on-options-press #(js/alert "Options button pressed!")})]
20+
(fn []
21+
[preview/preview-container
22+
{:state state
23+
:descriptor descriptor
24+
:blur? (:blur? @state)
25+
:show-blur-background? true
26+
:blur-dark-only? true}
27+
[quo/saved-address
28+
(assoc @state
29+
:user-props
30+
{:name (:title @state)
31+
:address (:address @state)
32+
:emoji (:emoji @state)
33+
:customization-color (:account-color @state)})]])))

src/status_im2/contexts/quo_preview/main.cljs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
[status-im2.contexts.quo-preview.list-items.channel :as channel]
7171
[status-im2.contexts.quo-preview.list-items.dapp :as dapp]
7272
[status-im2.contexts.quo-preview.list-items.preview-lists :as preview-lists]
73+
[status-im2.contexts.quo-preview.list-items.saved-address :as saved-address]
7374
[status-im2.contexts.quo-preview.list-items.token-value :as token-value]
7475
[status-im2.contexts.quo-preview.list-items.user-list :as user-list]
7576
[status-im2.contexts.quo-preview.list-items.community-list :as community-list]
@@ -279,6 +280,8 @@
279280
:component dapp/preview}
280281
{:name :preview-lists
281282
:component preview-lists/view}
283+
{:name :saved-address
284+
:component saved-address/view}
282285
{:name :token-value
283286
:component token-value/view}
284287
{:name :user-list

0 commit comments

Comments
 (0)