Skip to content

Commit 0552713

Browse files
authored
Add quo2 dApp component (status-im#17074)
1 parent 3223c71 commit 0552713

File tree

10 files changed

+168
-3
lines changed

10 files changed

+168
-3
lines changed
4.23 KB
Loading
7.35 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(ns quo2.components.list-items.dapp.component-spec
2+
(:require [quo2.components.list-items.dapp.view :as dapp]
3+
[test-helpers.component :as h]))
4+
5+
(def props
6+
{:dapp {:avatar nil
7+
:name "Coingecko"
8+
:value "coingecko.com"}
9+
:state :default
10+
:action :icon
11+
:blur? false
12+
:customization-color :blue})
13+
14+
(h/describe
15+
"dApp component test"
16+
(h/test "default render"
17+
(h/render [dapp/view props])
18+
(h/is-truthy (h/get-by-text (:name (:dapp props))))
19+
(h/is-truthy (h/get-by-text (:value (:dapp props)))))
20+
(h/test "on-press event"
21+
(let [mock-fn (h/mock-fn)]
22+
(h/render [dapp/view (assoc props :on-press-icon mock-fn)])
23+
(h/fire-event :press (h/get-by-test-id "dapp-component-icon"))
24+
(h/was-called mock-fn))))
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
(ns quo2.components.list-items.dapp.style
2+
(:require [quo2.foundations.colors :as colors]))
3+
4+
(defn get-background-color
5+
[{:keys [pressed? state blur? customization-color theme]}]
6+
(cond
7+
(and pressed? (= theme :dark) blur?) colors/white-opa-5
8+
9+
pressed? (colors/theme-colors
10+
(colors/custom-color customization-color 50 5)
11+
(colors/custom-color customization-color 60 5)
12+
theme)
13+
14+
(and (= state :active) (= theme :dark) blur?) colors/white-opa-10
15+
16+
(= state :active) (colors/theme-colors
17+
(colors/custom-color customization-color 50 10)
18+
(colors/custom-color customization-color 60 10)
19+
theme)
20+
21+
:else :transparent))
22+
23+
(defn container
24+
[props]
25+
{:flex 1
26+
:padding-horizontal 12
27+
:padding-vertical 8
28+
:border-radius 12
29+
:background-color (get-background-color props)
30+
:flex-direction :row
31+
:justify-content :space-between
32+
:align-items :center})
33+
34+
(def container-info
35+
{:flex-direction :row
36+
:align-items :center})
37+
38+
(def user-info
39+
{:margin-left 8})
40+
41+
(defn style-text-name
42+
[theme]
43+
{:color (colors/theme-colors colors/neutral-100 colors/white theme)})
44+
45+
(defn style-text-value
46+
[theme]
47+
{:color (colors/theme-colors colors/neutral-50 colors/white theme)})
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
(ns quo2.components.list-items.dapp.view
2+
(:require [quo2.components.icon :as icons]
3+
[quo2.components.markdown.text :as text]
4+
[quo2.foundations.colors :as colors]
5+
[react-native.core :as rn]
6+
[react-native.fast-image :as fast-image]
7+
[quo2.components.list-items.dapp.style :as style]
8+
[quo2.theme :as quo.theme]
9+
[reagent.core :as reagent]))
10+
11+
(defn- view-internal
12+
[]
13+
(let [pressed? (reagent/atom false)]
14+
(fn [{:keys [dapp action on-press on-press-icon theme] :as props}]
15+
[rn/pressable
16+
{:style (style/container (assoc props :pressed? @pressed?))
17+
:on-press on-press
18+
:on-press-in #(reset! pressed? true)
19+
:on-press-out #(reset! pressed? false)}
20+
[rn/view {:style style/container-info}
21+
[fast-image/fast-image
22+
{:source (:avatar dapp)
23+
:style {:width 32 :height 32}}]
24+
[rn/view {:style style/user-info}
25+
[text/text
26+
{:weight :semi-bold
27+
:size :paragraph-1
28+
:style (style/style-text-name theme)}
29+
(:name dapp)]
30+
[text/text
31+
{:weight :regular
32+
:size :paragraph-2
33+
:style (style/style-text-value theme)}
34+
(:value dapp)]]]
35+
(when (= action :icon)
36+
[rn/pressable
37+
{:on-press on-press-icon
38+
:testID "dapp-component-icon"}
39+
[icons/icon :i/options
40+
{:color (colors/theme-colors
41+
colors/neutral-50
42+
colors/neutral-40
43+
theme)
44+
:accessibility-label :icon}]])])))
45+
46+
(def view
47+
(quo.theme/with-theme view-internal))

src/quo2/core.cljs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
quo2.components.list-items.account-list-card.view
6363
quo2.components.list-items.channel
6464
quo2.components.list-items.community.view
65+
quo2.components.list-items.dapp.view
6566
quo2.components.list-items.menu-item
6667
quo2.components.list-items.preview-list
6768
quo2.components.list-items.token-value.view
@@ -110,8 +111,8 @@
110111
quo2.components.tags.tags
111112
quo2.components.tags.token-tag
112113
quo2.components.text-combinations.title.view
113-
quo2.components.wallet.account-overview.view
114114
quo2.components.wallet.account-card.view
115+
quo2.components.wallet.account-overview.view
115116
quo2.components.wallet.keypair.view
116117
quo2.components.wallet.network-amount.view
117118
quo2.components.wallet.network-bridge.view
@@ -235,6 +236,7 @@
235236
;;;; List items
236237
(def account-list-card quo2.components.list-items.account-list-card.view/view)
237238
(def channel-list-item quo2.components.list-items.channel/list-item)
239+
(def dapp quo2.components.list-items.dapp.view/view)
238240
(def menu-item quo2.components.list-items.menu-item/menu-item)
239241
(def preview-list quo2.components.list-items.preview-list/preview-list)
240242
(def user-list quo2.components.list-items.user-list/user-list)

src/quo2/core_spec.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
[quo2.components.links.url-preview-list.component-spec]
3737
[quo2.components.links.url-preview.component-spec]
3838
[quo2.components.list-items.community.component-spec]
39+
[quo2.components.list-items.dapp.component-spec]
3940
[quo2.components.list-items.token-value.component-spec]
4041
[quo2.components.markdown.text-component-spec]
4142
[quo2.components.markdown.list.component-spec]
@@ -55,8 +56,8 @@
5556
[quo2.components.settings.category.component-spec]
5657
[quo2.components.share.share-qr-code.component-spec]
5758
[quo2.components.tags.status-tags-component-spec]
58-
[quo2.components.wallet.account-overview.component-spec]
5959
[quo2.components.wallet.account-card.component-spec]
60+
[quo2.components.wallet.account-overview.component-spec]
6061
[quo2.components.wallet.keypair.component-spec]
6162
[quo2.components.wallet.network-amount.component-spec]
6263
[quo2.components.wallet.network-bridge.component-spec]

src/status_im2/common/resources.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
(def mock-images
5353
{:diamond (js/require "../resources/images/mock2/diamond.png")
5454
:coinbase (js/require "../resources/images/mock2/coinbase.png")
55+
:coin-gecko (js/require "../resources/images/mock2/coin-gecko.png")
5556
:collectible (js/require "../resources/images/mock2/collectible.png")
5657
:contact (js/require "../resources/images/mock2/contact.png")
5758
:community-banner (js/require "../resources/images/mock2/community-banner.png")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(ns status-im2.contexts.quo-preview.list-items.dapp
2+
(:require [quo2.core :as quo]
3+
[react-native.core :as rn]
4+
[reagent.core :as reagent]
5+
[status-im2.common.resources :as resources]
6+
[status-im2.contexts.quo-preview.preview :as preview]))
7+
8+
(def descriptor
9+
[{:key :state
10+
:type :select
11+
:options [{:key :default
12+
:value "Default"}
13+
{:key :active
14+
:value "Active"}]}
15+
{:key :action
16+
:type :select
17+
:options [{:key :none
18+
:value "None"}
19+
{:key :icon
20+
:value "Icon"}]}
21+
{:key :blur?
22+
:type :boolean}])
23+
24+
(defn preview
25+
[]
26+
(let [state (reagent/atom {:dapp {:avatar (resources/get-mock-image :coin-gecko)
27+
:name "Coingecko"
28+
:value "coingecko.com"}
29+
:state :default
30+
:action :icon
31+
:blur? false
32+
:customization-color :blue
33+
:on-press-icon (fn [] (js/alert "Button pressed"))})]
34+
(fn []
35+
[preview/preview-container {:state state :descriptor descriptor}
36+
[rn/view
37+
{:padding-vertical 60
38+
:flex-direction :row
39+
:justify-content :center}
40+
[quo/dapp @state]]])))

src/status_im2/contexts/quo_preview/main.cljs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
[status-im2.contexts.quo-preview.links.link-preview :as link-preview]
6363
[status-im2.contexts.quo-preview.list-items.account-list-card :as account-list-card]
6464
[status-im2.contexts.quo-preview.list-items.channel :as channel]
65+
[status-im2.contexts.quo-preview.list-items.dapp :as dapp]
6566
[status-im2.contexts.quo-preview.list-items.preview-lists :as preview-lists]
6667
[status-im2.contexts.quo-preview.list-items.user-list :as user-list]
6768
[status-im2.contexts.quo-preview.list-items.community-list :as community-list]
@@ -111,8 +112,8 @@
111112
[status-im2.contexts.quo-preview.loaders.skeleton :as skeleton]
112113
[status-im2.contexts.quo-preview.community.channel-actions :as channel-actions]
113114
[status-im2.contexts.quo-preview.gradient.gradient-cover :as gradient-cover]
114-
[status-im2.contexts.quo-preview.wallet.account-overview :as account-overview]
115115
[status-im2.contexts.quo-preview.wallet.account-card :as account-card]
116+
[status-im2.contexts.quo-preview.wallet.account-overview :as account-overview]
116117
[status-im2.contexts.quo-preview.wallet.keypair :as keypair]
117118
[status-im2.contexts.quo-preview.wallet.network-amount :as network-amount]
118119
[status-im2.contexts.quo-preview.wallet.network-bridge :as network-bridge]
@@ -248,6 +249,8 @@
248249
{:name :community-list
249250
:options {:insets {:top? true}}
250251
:component community-list/view}
252+
{:name :dapp
253+
:component dapp/preview}
251254
{:name :preview-lists
252255
:component preview-lists/preview-preview-lists}
253256
{:name :user-list

0 commit comments

Comments
 (0)