Skip to content

Commit feb8753

Browse files
authored
[#19401] Wallet share QR code - multiple fixes (#19425)
* Fix key extractions in re-frame/reg-sub * Add `:width` to share-qr-code By adding this prop, `on-layout` can be skipped and the component can be properly rendered faster. * Use `share-qr-code`'s `:width` prop in share profile shell * Fix share qr code for wallet addresses * Fix the height of the component being cropped. * Fix the bottom dots not being accurately highlighted. * Fix the blink when the component is mounted
1 parent 8b0681c commit feb8753

File tree

5 files changed

+66
-62
lines changed

5 files changed

+66
-62
lines changed

src/quo/components/share/share_qr_code/view.cljs

+5-5
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,21 @@
188188
nil))]]])
189189

190190
(defn- view-internal
191-
[props]
192-
(let [[component-width
191+
[{provided-width :width :as props}]
192+
(let [[calculated-width
193193
set-component-width] (rn/use-state nil)
194194
on-layout (rn/use-callback #(set-component-width
195195
(oops/oget % "nativeEvent.layout.width")))
196196
props (-> props
197-
(assoc :component-width component-width)
197+
(assoc :component-width (or provided-width calculated-width))
198198
(clojure.set/rename-keys {:type :share-qr-type}))]
199199
[quo.theme/provider {:theme :dark}
200200
[rn/view
201201
{:accessibility-label :share-qr-code
202202
:style style/outer-container
203-
:on-layout on-layout}
203+
:on-layout (when-not provided-width on-layout)}
204204
[rn/view {:style {:background-color style/overlay-color}}
205-
(when component-width
205+
(when (:component-width props)
206206
[share-qr-code props])]]]))
207207

208208
(def view (schema/instrument #'view-internal component-schema/?schema))

src/status_im/contexts/shell/share/profile/view.cljs

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616
[]
1717
(let [{:keys [emoji-hash
1818
universal-profile-url]
19-
:as profile} (rf/sub [:profile/profile-with-image])
20-
customization-color (rf/sub [:profile/customization-color])
21-
abbreviated-url (address/get-abbreviated-profile-url
22-
universal-profile-url)
23-
emoji-hash-string (string/join emoji-hash)]
19+
:as profile} (rf/sub [:profile/profile-with-image])
20+
{window-width :width} (rn/get-window)
21+
customization-color (rf/sub [:profile/customization-color])
22+
abbreviated-url (address/get-abbreviated-profile-url
23+
universal-profile-url)
24+
emoji-hash-string (string/join emoji-hash)]
2425
[rn/scroll-view
2526
{:content-container-style {:padding-bottom 16}}
2627
[rn/view {:style style/qr-code-container}
2728
[qr-codes/share-qr-code
2829
{:type :profile
30+
:width (- window-width (* style/screen-padding 2))
2931
:qr-data universal-profile-url
3032
:qr-data-label-shown abbreviated-url
3133
:on-share-press #(list-selection/open-share {:message universal-profile-url})

src/status_im/contexts/shell/share/style.cljs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
(def screen-padding 20)
77

8-
98
(def header-row
109
{:flex-direction :row
1110
:justify-content :space-between
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns status-im.contexts.shell.share.wallet.view
22
(:require
3+
[oops.core :as oops]
34
[quo.core :as quo]
45
[react-native.core :as rn]
56
[react-native.platform :as platform]
@@ -11,6 +12,7 @@
1112
[status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences]
1213
[utils.i18n :as i18n]
1314
[utils.image-server :as image-server]
15+
[utils.number]
1416
[utils.re-frame :as rf]))
1517

1618
(def qr-size 500)
@@ -44,14 +46,14 @@
4446
(rf/dispatch [:hide-bottom-sheet])
4547
(reset! selected-networks (map #(get utils/id->network %)
4648
chain-ids)))}])}]))
47-
(defn- wallet-qr-code-item-internal
48-
[props]
49-
(let [{:keys [account width index]} props
50-
selected-networks (reagent/atom [:ethereum :optimism :arbitrum])
51-
wallet-type (reagent/atom :legacy)
52-
on-settings-press #(open-preferences selected-networks)
53-
on-legacy-press #(reset! wallet-type :legacy)
54-
on-multichain-press #(reset! wallet-type :multichain)]
49+
(defn- wallet-qr-code-item
50+
[{:keys [account index]}]
51+
(let [{window-width :width} (rn/get-window)
52+
selected-networks (reagent/atom [:ethereum :optimism :arbitrum])
53+
wallet-type (reagent/atom :legacy)
54+
on-settings-press #(open-preferences selected-networks)
55+
on-legacy-press #(reset! wallet-type :legacy)
56+
on-multichain-press #(reset! wallet-type :multichain)]
5557
(fn []
5658
(let [share-title (str (:name account) " " (i18n/label :t/address))
5759
qr-url (utils/get-wallet-qr {:wallet-type @wallet-type
@@ -62,10 +64,11 @@
6264
:port (rf/sub [:mediaserver/port])
6365
:qr-size qr-size
6466
:error-level :highest})]
65-
[rn/view {:style {:height qr-size :width width :margin-left (if (zero? index) 0 -30)}}
67+
[rn/view {:style {:width window-width :margin-left (if (zero? index) 0 -30)}}
6668
[rn/view {:style style/qr-code-container}
6769
[quo/share-qr-code
6870
{:type :wallet
71+
:width (- window-width (* style/screen-padding 2))
6972
:address @wallet-type
7073
:qr-image-uri qr-media-server-uri
7174
:qr-data qr-url
@@ -79,54 +82,54 @@
7982
:on-legacy-press on-legacy-press
8083
:on-settings-press on-settings-press}]]]))))
8184

82-
(def wallet-qr-code-item (memoize wallet-qr-code-item-internal))
83-
8485
(defn- indicator
8586
[active?]
86-
[rn/view
87-
{:style (wallet-style/indicator-wrapper-style active?)}])
87+
[rn/view {:style (wallet-style/indicator-wrapper-style active?)}])
8888

8989
(defn- indicator-list
90-
[indicator-count current-index]
91-
[rn/view
92-
{:style wallet-style/indicator-list-style}
93-
(for [i (range indicator-count)]
94-
(let [current-index (cond (<= current-index 0) 0
95-
(>= current-index (dec indicator-count)) (dec indicator-count)
96-
:else current-index)]
97-
^{:key i} [indicator (= current-index i)]))])
90+
[num-indicators current-index]
91+
[rn/view {:style wallet-style/indicator-list-style}
92+
(for [i (range num-indicators)]
93+
^{:key i} [indicator (= current-index i)])])
9894

9995
(defn render-item
10096
[item]
101-
(let [width (rf/sub [:dimensions/window-width])]
102-
[wallet-qr-code-item
103-
{:account item
104-
:index (:position item)
105-
:width width}]))
97+
[wallet-qr-code-item
98+
{:account item
99+
:index (:position item)}])
100+
101+
(defn- qr-code-visualized-index
102+
[offset qr-code-size num-qr-codes]
103+
(-> (+ (/ offset qr-code-size) 0.5)
104+
(int)
105+
(utils.number/value-in-range 0 (dec num-qr-codes))))
106106

107107
(defn wallet-tab
108108
[]
109-
(let [accounts (rf/sub [:wallet/accounts])
110-
width (rf/sub [:dimensions/window-width])
111-
current-index (reagent/atom 0)]
109+
(let [current-index (reagent/atom 0)
110+
{window-width :width} (rn/get-window)
111+
qr-code-size (- window-width 30)]
112112
(fn []
113-
[rn/view
114-
[rn/flat-list
115-
{:horizontal true
116-
:deceleration-rate 0.9
117-
:snap-to-alignment :start
118-
:snap-to-interval (- width 30)
119-
:disable-interval-momentum true
120-
:scroll-event-throttle 64
121-
:data accounts
122-
:directional-lock-enabled true
123-
:shows-horizontal-scroll-indicator false
124-
:on-scroll (fn [e]
125-
(reset! current-index (js/Math.ceil
126-
(/ e.nativeEvent.contentOffset.x
127-
width))))
128-
:render-fn render-item}]
129-
(when (> (count accounts) 1)
130-
[rn/view
131-
{:style {:margin-top 20}}
132-
(indicator-list (count accounts) @current-index)])])))
113+
(let [accounts (rf/sub [:wallet/accounts])
114+
num-accounts (count accounts)
115+
on-scroll (rn/use-callback
116+
(fn [e]
117+
(let [offset-x (oops/oget e "nativeEvent.contentOffset.x")
118+
index (qr-code-visualized-index offset-x qr-code-size num-accounts)]
119+
(reset! current-index index))))]
120+
[rn/view
121+
[rn/flat-list
122+
{:horizontal true
123+
:deceleration-rate 0.9
124+
:snap-to-alignment :start
125+
:snap-to-interval qr-code-size
126+
:disable-interval-momentum true
127+
:scroll-event-throttle 64
128+
:data accounts
129+
:directional-lock-enabled true
130+
:shows-horizontal-scroll-indicator false
131+
:on-scroll on-scroll
132+
:render-fn render-item}]
133+
(when (> num-accounts 1)
134+
[rn/view {:style {:margin-top 20}}
135+
[indicator-list num-accounts @current-index]])]))))

src/status_im/subs/general.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@
120120
(re-frame/reg-sub
121121
:dimensions/window-width
122122
:<- [:dimensions/window]
123-
:width)
123+
:-> :width)
124124

125125
(re-frame/reg-sub
126126
:dimensions/window-height
127127
:<- [:dimensions/window]
128-
:height)
128+
:-> :height)
129129

130130
(re-frame/reg-sub
131131
:dimensions/small-screen?

0 commit comments

Comments
 (0)