|
1 | 1 | (ns quo.components.wallet.token-input.view
|
2 | 2 | (:require
|
3 | 3 | [clojure.string :as string]
|
4 |
| - [oops.core :as oops] |
5 | 4 | [quo.components.buttons.button.view :as button]
|
6 | 5 | [quo.components.dividers.divider-line.view :as divider-line]
|
7 | 6 | [quo.components.markdown.text :as text]
|
8 |
| - [quo.components.tags.network-tags.view :as network-tag] |
9 | 7 | [quo.components.utilities.token.view :as token]
|
10 | 8 | [quo.components.wallet.token-input.schema :as component-schema]
|
11 | 9 | [quo.components.wallet.token-input.style :as style]
|
12 | 10 | [quo.theme :as quo.theme]
|
13 | 11 | [react-native.core :as rn]
|
14 | 12 | [schema.core :as schema]))
|
15 | 13 |
|
16 |
| -(defn- data-info |
17 |
| - [{:keys [theme networks title converted-value error?]}] |
18 |
| - [rn/view {:style style/data-container} |
19 |
| - [network-tag/view |
20 |
| - {:networks networks |
21 |
| - :title title |
22 |
| - :status (when error? :error)}] |
23 |
| - [text/text |
24 |
| - {:size :paragraph-2 |
25 |
| - :weight :medium |
26 |
| - :style (style/fiat-amount theme)} |
27 |
| - converted-value]]) |
28 |
| - |
29 | 14 | (defn- token-name-text
|
30 | 15 | [theme text]
|
31 | 16 | [text/text
|
|
35 | 20 | (string/upper-case (or (clj->js text) ""))])
|
36 | 21 |
|
37 | 22 | (defn input-section
|
38 |
| - [{:keys [on-change-text value value-internal set-value-internal on-selection-change |
39 |
| - on-token-press]}] |
40 |
| - (let [input-ref (atom nil) |
41 |
| - set-ref #(reset! input-ref %) |
42 |
| - focus-input #(when-let [ref ^js @input-ref] |
43 |
| - (.focus ref)) |
44 |
| - controlled-input? (some? value) |
45 |
| - handle-on-change-text (fn [v] |
46 |
| - (when-not controlled-input? |
47 |
| - (set-value-internal v)) |
48 |
| - (when on-change-text |
49 |
| - (on-change-text v))) |
50 |
| - handle-selection-change (fn [^js e] |
51 |
| - (when on-selection-change |
52 |
| - (-> e |
53 |
| - (oops/oget "nativeEvent.selection") |
54 |
| - (js->clj :keywordize-keys true) |
55 |
| - (on-selection-change))))] |
56 |
| - (fn [{:keys [token customization-color show-keyboard? crypto? currency value error? selection |
57 |
| - handle-on-swap allow-selection?] |
58 |
| - :or {show-keyboard? true |
59 |
| - allow-selection? true}}] |
60 |
| - (let [theme (quo.theme/use-theme) |
61 |
| - window-width (:width (rn/get-window))] |
62 |
| - [rn/pressable |
63 |
| - {:style {:width "100%" |
64 |
| - :flex-direction :row} |
65 |
| - :on-press on-token-press} |
66 |
| - [token/view |
67 |
| - {:token token |
68 |
| - :size :size-32}] |
69 |
| - [rn/view {:style (style/input-container window-width)} |
70 |
| - [rn/pressable |
71 |
| - {:style style/text-input-container |
72 |
| - :on-press focus-input} |
73 |
| - [rn/text-input |
74 |
| - (cond-> {:style (style/text-input theme error?) |
75 |
| - :placeholder-text-color (style/placeholder-text theme) |
76 |
| - :auto-focus true |
77 |
| - :ref set-ref |
78 |
| - :placeholder "0" |
79 |
| - :keyboard-type :numeric |
80 |
| - :on-change-text handle-on-change-text |
81 |
| - :selection-color customization-color |
82 |
| - :show-soft-input-on-focus show-keyboard? |
83 |
| - :on-selection-change handle-selection-change |
84 |
| - :selection (clj->js selection) |
85 |
| - :editable allow-selection?} |
86 |
| - controlled-input? (assoc :value value) |
87 |
| - (not controlled-input?) (assoc :default-value value-internal))] |
88 |
| - [token-name-text theme (if crypto? token currency)]]] |
89 |
| - [button/button |
90 |
| - {:icon true |
91 |
| - :icon-only? true |
92 |
| - :size 32 |
93 |
| - :on-press handle-on-swap |
94 |
| - :type :outline |
95 |
| - :accessibility-label :reorder} |
96 |
| - :i/reorder]])))) |
| 23 | + [{:keys [token-symbol on-token-press value error? on-swap currency-symbol]}] |
| 24 | + (let [theme (quo.theme/use-theme) |
| 25 | + window-width (:width (rn/get-window))] |
| 26 | + [rn/pressable |
| 27 | + {:style {:width "100%" |
| 28 | + :flex-direction :row} |
| 29 | + :on-press on-token-press} |
| 30 | + [token/view |
| 31 | + {:token token-symbol |
| 32 | + :size :size-32}] |
| 33 | + [rn/view {:style (style/input-container window-width)} |
| 34 | + [rn/text-input |
| 35 | + {:style (style/text-input theme error?) |
| 36 | + :placeholder-text-color (style/placeholder-text theme) |
| 37 | + :placeholder "0" |
| 38 | + :keyboard-type :numeric |
| 39 | + :editable false |
| 40 | + :value value}] |
| 41 | + [token-name-text theme currency-symbol]] |
| 42 | + [button/button |
| 43 | + {:icon true |
| 44 | + :icon-only? true |
| 45 | + :size 32 |
| 46 | + :on-press #(when on-swap (on-swap)) |
| 47 | + :type :outline |
| 48 | + :accessibility-label :reorder} |
| 49 | + :i/reorder]])) |
97 | 50 |
|
98 | 51 | (defn- view-internal
|
99 |
| - [{:keys [container-style on-swap crypto?] :as props}] |
100 |
| - (let [theme (quo.theme/use-theme) |
101 |
| - width (:width (rn/get-window)) |
102 |
| - [value-internal set-value-internal] (rn/use-state nil) |
103 |
| - handle-on-swap (rn/use-callback |
104 |
| - (fn [] |
105 |
| - (when on-swap (on-swap (not crypto?)))) |
106 |
| - [on-swap])] |
| 52 | + [{:keys [token-symbol |
| 53 | + value |
| 54 | + on-token-press |
| 55 | + error? |
| 56 | + container-style |
| 57 | + on-swap |
| 58 | + converted-value |
| 59 | + hint-component |
| 60 | + currency-symbol]}] |
| 61 | + (let [theme (quo.theme/use-theme) |
| 62 | + width (:width (rn/get-window))] |
107 | 63 | [rn/view {:style (merge (style/main-container width) container-style)}
|
108 | 64 | [rn/view {:style style/amount-container}
|
109 | 65 | [input-section
|
110 |
| - (assoc props |
111 |
| - :value-internal value-internal |
112 |
| - :theme theme |
113 |
| - :set-value-internal set-value-internal |
114 |
| - :handle-on-swap handle-on-swap |
115 |
| - :crypto? crypto?)]] |
| 66 | + {:theme theme |
| 67 | + :token-symbol token-symbol |
| 68 | + :on-token-press on-token-press |
| 69 | + :value value |
| 70 | + :error? error? |
| 71 | + :on-swap on-swap |
| 72 | + :currency-symbol currency-symbol}]] |
116 | 73 | [divider-line/view {:container-style (style/divider theme)}]
|
117 |
| - [data-info (assoc props :theme theme)]])) |
| 74 | + [rn/view {:style style/data-container} |
| 75 | + hint-component |
| 76 | + [text/text |
| 77 | + {:size :paragraph-2 |
| 78 | + :weight :medium |
| 79 | + :style (style/converted-amount theme)} |
| 80 | + converted-value]]])) |
118 | 81 |
|
119 | 82 | (def view (schema/instrument #'view-internal component-schema/?schema))
|
0 commit comments