-
Notifications
You must be signed in to change notification settings - Fork 991
/
Copy pathview.cljs
233 lines (223 loc) · 9.89 KB
/
view.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
(ns status-im.contexts.wallet.swap.swap-confirmation.view
(:require
[quo.core :as quo]
[quo.theme :as quo.theme]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.common.standard-authentication.core :as standard-auth]
[status-im.constants :as constants]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.send.utils :as send-utils]
[status-im.contexts.wallet.swap.swap-confirmation.style :as style]
[utils.address :as address-utils]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn- on-close-action
[]
(rf/dispatch [:navigate-back]))
(defn- swap-title
[]
(let [asset-to-pay (rf/sub [:wallet/swap-asset-to-pay])
asset-to-receive (rf/sub [:wallet/swap-asset-to-receive])
account (rf/sub [:wallet/current-viewing-account])
receive-amount (rf/sub [:wallet/swap-receive-amount])
pay-amount (rf/sub [:wallet/swap-pay-amount])
pay-token-symbol (:symbol asset-to-pay)
receive-token-symbol (:symbol asset-to-receive)]
[rn/view {:style style/content-container}
[rn/view {:style {:flex-direction :row}}
[quo/text
{:size :heading-1
:weight :semi-bold
:style style/title-container
:accessibility-label :title-label}
(i18n/label :t/swap)]
[quo/summary-tag
{:token pay-token-symbol
:label (str pay-amount " " pay-token-symbol)
:type :token}]]
[rn/view {:style style/title-line-with-margin-top}
[quo/text
{:size :heading-1
:weight :semi-bold
:style style/title-container
:accessibility-label :title-label}
(i18n/label :t/to)]
[quo/summary-tag
{:token receive-token-symbol
:label (str receive-amount " " receive-token-symbol)
:type :token}]]
[rn/view {:style style/title-line-with-margin-top}
[quo/text
{:size :heading-1
:weight :semi-bold
:style style/title-container
:accessibility-label :send-label}
(i18n/label :t/in)]
[quo/summary-tag
{:label (:name account)
:type :account
:emoji (:emoji account)
:customization-color (:color account)}]]]))
(defn- summary-section
[{:keys [theme label title-accessibility-label amount token-symbol token-address network]}]
(let [network-values {(if (= network :mainnet) :ethereum network)
{:amount amount :token-symbol token-symbol}}]
[rn/view {:style style/summary-section-container}
[quo/text
{:size :paragraph-2
:weight :medium
:style (style/section-label theme)
:accessibility-label title-accessibility-label}
label]
[quo/summary-info
{:type :token
:networks? true
:values (send-utils/network-values-for-ui network-values)
:token-props {:token token-symbol
:label (str amount " " token-symbol)
:address (when token-address
(address-utils/get-shortened-compressed-key token-address))
:size 32}}]]))
(defn- pay-section
[]
(let [theme (quo.theme/use-theme)
asset-to-pay (rf/sub [:wallet/swap-asset-to-pay])
network (rf/sub [:wallet/swap-network])
pay-amount (rf/sub [:wallet/swap-pay-amount-raw])
network-chain-id (:chain-id network)
network-name (:network-name network)
pay-token-symbol (:symbol asset-to-pay)
pay-token-address (get-in asset-to-pay [:balances-per-chain network-chain-id :address])]
[summary-section
{:title-accessibility-label :summary-section-pay
:label (i18n/label :t/pay)
:token-symbol pay-token-symbol
:amount pay-amount
:token-address (when-not (address-utils/zero-address? pay-token-address)
pay-token-address)
:network network-name
:theme theme}]))
(defn- receive-section
[]
(let [theme (quo.theme/use-theme)
asset-to-receive (rf/sub [:wallet/swap-asset-to-receive])
network (rf/sub [:wallet/swap-network])
receive-amount (rf/sub [:wallet/swap-receive-amount-raw])
network-chain-id (:chain-id network)
network-name (:network-name network)
receive-token-symbol (:symbol asset-to-receive)
receive-token-address (get-in asset-to-receive [:balances-per-chain network-chain-id :address])]
[summary-section
{:title-accessibility-label :summary-section-receive
:label (i18n/label :t/receive)
:token-symbol receive-token-symbol
:amount receive-amount
:token-address (when-not (address-utils/zero-address? receive-token-address)
receive-token-address)
:network network-name
:theme theme}]))
(defn- data-item
[{:keys [title subtitle loading?]}]
[quo/data-item
{:container-style style/detail-item
:blur? false
:card? false
:status (if loading? :loading :default)
:size :small
:title title
:subtitle subtitle}])
(defn- transaction-details
[]
(let [max-fees (rf/sub [:wallet/wallet-swap-proposal-fee-fiat
constants/token-for-fees-symbol])
currency-symbol (rf/sub [:profile/currency-symbol])
max-fees-formatted (utils/fiat-formatted-for-ui
currency-symbol
max-fees)
estimated-time (rf/sub [:wallet/swap-proposal-estimated-time])
loading-swap-proposal? (rf/sub [:wallet/swap-loading-swap-proposal?])
max-slippage (rf/sub [:wallet/swap-max-slippage])]
[rn/view {:style style/details-container}
[:<>
(when estimated-time
[data-item
{:title (i18n/label :t/est-time)
:subtitle (i18n/label :t/time-in-mins {:minutes (str estimated-time)})
:loading? loading-swap-proposal?}])
[data-item
{:title (i18n/label :t/max-fees)
:subtitle (if max-fees-formatted max-fees-formatted (i18n/label :t/unknown))
:loading? loading-swap-proposal?}]
[data-item
{:title (i18n/label :t/max-slippage)
:subtitle (str max-slippage "%")}]]]))
(defn- slide-button
[]
(let [loading-swap-proposal? (rf/sub [:wallet/swap-loading-swap-proposal?])
transaction-for-signing (rf/sub [:wallet/swap-transaction-for-signing])
swap-proposal (rf/sub [:wallet/swap-proposal-without-fees])
account (rf/sub [:wallet/current-viewing-account])
account-color (:color account)
sign-on-keycard? (get-in transaction-for-signing
[:signingDetails :signOnKeycard])]
[standard-auth/slide-button
{:size :size-48
:track-text (i18n/label :t/slide-to-swap)
:container-style {:z-index 2}
:customization-color account-color
:disabled? (or loading-swap-proposal?
(not swap-proposal)
(not transaction-for-signing))
:auth-button-label (i18n/label :t/confirm)
:on-complete (when sign-on-keycard?
#(rf/dispatch
[:wallet/prepare-signatures-for-transactions
:swap
""]))
:on-auth-success (fn [data]
(rf/dispatch [:wallet/stop-get-swap-proposal])
(rf/dispatch [:wallet/prepare-signatures-for-transactions :swap data]))}]))
(defn footer
[]
(let [provider (rf/sub [:wallet/swap-proposal-provider])
theme (quo.theme/use-theme)
on-press (rn/use-callback #(when provider
(rf/dispatch [:open-modal :screen/pdf-viewer
{:uri (:terms-and-conditions-url provider)}]))
[provider])]
[:<>
[transaction-details]
[slide-button]
[rn/view {:style style/providers-container}
[quo/text
{:size :paragraph-2
:style (style/swaps-powered-by theme)}
(i18n/label :t/swaps-powered-by
{:provider (if provider (:full-name provider) (i18n/label :t/unknown))})]
[quo/text
{:size :paragraph-2
:style (style/terms-and-conditions theme)
:on-press on-press}
(i18n/label :t/terms-and-conditions)]]]))
(defn view
[]
(let [account (rf/sub [:wallet/current-viewing-account])
account-color (:color account)]
[rn/view {:style {:flex 1}}
[floating-button-page/view
{:footer-container-padding 0
:header [quo/page-nav
{:icon-name :i/arrow-left
:on-press on-close-action
:margin-top (safe-area/get-top)
:background :blur
:accessibility-label :top-bar}]
:footer [footer]
:gradient-cover? true
:customization-color account-color}
[rn/view
[swap-title]
[pay-section]
[receive-section]]]]))