Skip to content

Commit 94723fb

Browse files
feat: approve token transactions on swap
Signed-off-by: Brian Sztamfater <[email protected]>
1 parent ad1fa0b commit 94723fb

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

src/status_im/constants.cljs

+3-1
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,13 @@
591591
(def ^:const default-slippage 0.5)
592592
(def ^:const max-recommended-slippage 5)
593593
(def ^:const max-slippage-decimal-places 2)
594-
(def ^:const swap-default-provider
594+
(def ^:const swap-provider-paraswap
595595
{:name :paraswap
596596
:full-name "Paraswap"
597597
:color :blue
598598
:contract-address "0xdef171fe48cf0115b1d80b88dc8eab59176fee57"
599599
:terms-and-conditions-url "https://files.paraswap.io/tos_v4.pdf"})
600+
(def ^:const swap-providers
601+
{:paraswap swap-provider-paraswap})
600602

601603
(def ^:const token-for-fees-symbol "ETH")

src/status_im/contexts/wallet/swap/set_spending_cap/view.cljs

+27-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
(ns status-im.contexts.wallet.swap.set-spending-cap.view
22
(:require
3+
[native-module.core :as native-module]
34
[quo.core :as quo]
45
[quo.foundations.resources :as resources]
56
[quo.theme :as quo.theme]
67
[react-native.core :as rn]
78
[status-im.common.events-helper :as events-helper]
89
[status-im.common.floating-button-page.view :as floating-button-page]
910
[status-im.common.standard-authentication.core :as standard-auth]
11+
[status-im.constants :as constants]
1012
[status-im.contexts.wallet.common.utils.external-links :as external-links]
1113
[status-im.contexts.wallet.swap.set-spending-cap.style :as style]
1214
[utils.address :as address-utils]
15+
[utils.hex :as hex]
1316
[utils.i18n :as i18n]
17+
[utils.number :as number]
1418
[utils.re-frame :as rf]))
1519

1620
(defn- swap-title
@@ -171,8 +175,9 @@
171175
:size :small}]]])
172176

173177
(defn footer
174-
[{:keys [estimated-time-min native-currency-symbol network theme account-color loading-fees?]}]
175-
(let [fee-formatted (rf/sub [:wallet/wallet-send-fee-fiat-formatted native-currency-symbol])
178+
[{:keys [estimated-time-min network theme account-color loading-fees?]}]
179+
(let [fee-formatted (rf/sub [:wallet/wallet-swap-proposal-fee-fiat-formatted
180+
constants/token-for-fees-symbol])
176181
on-auth-success (rn/use-callback #(js/alert "Not implemented yet"))]
177182
[rn/view {:style {:margin-bottom -10}}
178183
[transaction-details
@@ -194,16 +199,25 @@
194199
[]
195200
(let [theme (quo.theme/use-theme)
196201
swap-transaction-data (rf/sub [:wallet/swap])
197-
{:keys [asset-to-pay network pay-amount
198-
providers swap-proposal
202+
{:keys [asset-to-pay network
203+
swap-proposal
199204
loading-fees?]} swap-transaction-data
205+
amount-in (rf/sub [:wallet/swap-proposal-amount-in])
206+
pay-token-decimals (:decimals asset-to-pay)
207+
pay-token-address (get-in asset-to-pay
208+
[:balances-per-chain
209+
(:chain-id network) :address])
210+
pay-amount (when amount-in
211+
(number/convert-to-whole-number
212+
(native-module/hex-to-number
213+
(hex/normalize-hex
214+
amount-in))
215+
pay-token-decimals))
200216
estimated-time-min (:estimated-time swap-proposal)
201217
pay-token-symbol (:symbol asset-to-pay)
202-
pay-token-address (:address asset-to-pay)
203-
native-currency-symbol (get-in swap-proposal [:from :native-currency-symbol])
204218
account (rf/sub [:wallet/current-viewing-account])
205219
account-color (:color account)
206-
provider (first providers)]
220+
provider (rf/sub [:wallet/swap-proposal-provider])]
207221
[rn/view {:style style/container}
208222
[floating-button-page/view
209223
{:footer-container-padding 0
@@ -214,13 +228,12 @@
214228
:background :blur
215229
:accessibility-label :top-bar}]
216230
:footer [footer
217-
{:estimated-time-min estimated-time-min
218-
:native-currency-symbol native-currency-symbol
219-
:network network
220-
:account-color account-color
221-
:provider provider
222-
:loading-fees? loading-fees?
223-
:theme theme}]
231+
{:estimated-time-min estimated-time-min
232+
:network network
233+
:account-color account-color
234+
:provider provider
235+
:loading-fees? loading-fees?
236+
:theme theme}]
224237
:gradient-cover? true
225238
:customization-color account-color}
226239
[:<>

src/status_im/contexts/wallet/swap/setup_swap/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
:on-max-press #(set-pay-input-state pay-token-balance-selected-chain)
263263
:input-focused? pay-input-focused?
264264
:on-token-press #(js/alert "Token Pressed")
265-
:on-approve-press #(js/alert "Approve Pressed")
265+
:on-approve-press #(rf/dispatch [:open-modal :screen/wallet.swap-set-spending-cap])
266266
:on-input-focus #(set-pay-input-focused? true)}]
267267
[swap-order-button {:on-press #(js/alert "Swap Order Pressed")}]
268268
[receive-token-input

src/status_im/subs/wallet/swap.cljs

+13
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@
9595
:<- [:wallet/swap-proposal]
9696
:-> :amount-out)
9797

98+
(rf/reg-sub
99+
:wallet/swap-proposal-amount-in
100+
:<- [:wallet/swap-proposal]
101+
:-> :amount-in)
102+
103+
(rf/reg-sub
104+
:wallet/swap-proposal-provider
105+
:<- [:wallet/swap-proposal]
106+
(fn [swap-proposal]
107+
(let [bridge-name (:bridge-name swap-proposal)
108+
provider-key (keyword (string/lower-case bridge-name))]
109+
(get constants/swap-providers provider-key))))
110+
98111
(rf/reg-sub
99112
:wallet/swap-proposal-approval-required
100113
:<- [:wallet/swap-proposal]

0 commit comments

Comments
 (0)