Skip to content

Commit 32f6167

Browse files
authored
Merge branch 'develop' into 19188
2 parents 16fff8b + 463e8a5 commit 32f6167

File tree

11 files changed

+157
-97
lines changed

11 files changed

+157
-97
lines changed

src/quo/components/wallet/summary_info/view.cljs

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@
3030
(defn networks
3131
[values theme]
3232
(let [{:keys [ethereum optimism arbitrum]} values
33-
show-optimism? (and optimism (pos? (:amount optimism)))
34-
show-arbitrum? (and arbitrum (pos? (:amount arbitrum)))]
33+
show-optimism? (and optimism
34+
(or (pos? (:amount optimism))
35+
(= (:amount optimism) "<0.01")))
36+
show-arbitrum? (and arbitrum
37+
(or (pos? (:amount arbitrum))
38+
(= (:amount arbitrum) "<0.01")))]
3539
[rn/view
3640
{:style style/networks-container
3741
:accessibility-label :networks}

src/status_im/constants.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@
478478

479479
(def ^:const bridge-name-transfer "Transfer")
480480
(def ^:const bridge-name-erc-721-transfer "ERC721Transfer")
481+
(def ^:const bridge-name-hop "Hop")
481482

482483
(def ^:const alert-banner-height 40)
483484

src/status_im/contexts/wallet/account/bridge_to/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
:fiat-value fiat-formatted
3232
:on-press #(rf/dispatch [:wallet/select-bridge-network
3333
{:network-chain-id chain-id
34-
:stack-id :wallet-bridge}])}])))
34+
:stack-id :screen/wallet.bridge-to}])}])))
3535

3636
(defn- view-internal
3737
[]

src/status_im/contexts/wallet/account/view.cljs

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
[status-im.contexts.wallet.account.tabs.view :as tabs]
88
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
99
[status-im.contexts.wallet.common.temp :as temp]
10-
[status-im.feature-flags :as ff]
1110
[utils.i18n :as i18n]
1211
[utils.re-frame :as rf]))
1312

@@ -55,8 +54,7 @@
5554
:receive-action #(rf/dispatch [:open-modal :screen/wallet.share-address {:status :receive}])
5655
:buy-action #(rf/dispatch [:show-bottom-sheet
5756
{:content buy-drawer}])
58-
:bridge-action #(ff/alert ::ff/wallet.bridge-token
59-
(fn [] (rf/dispatch [:wallet/start-bridge])))}])
57+
:bridge-action #(rf/dispatch [:wallet/start-bridge])}])
6058
[quo/tabs
6159
{:style style/tabs
6260
:size 32

src/status_im/contexts/wallet/events.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244

245245
(rf/reg-event-fx :wallet/start-bridge
246246
(fn [{:keys [db]}]
247-
{:db (assoc-in db [:wallet :ui :send :type] :bridge)
247+
{:db (assoc-in db [:wallet :ui :send :tx-type] :bridge)
248248
:fx [[:dispatch [:open-modal :screen/wallet.bridge]]]}))
249249

250250
(rf/reg-event-fx :wallet/select-bridge-network

src/status_im/contexts/wallet/send/events.cljs

+129-78
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,24 @@
9090

9191
(rf/reg-event-fx :wallet/clean-selected-token
9292
(fn [{:keys [db]}]
93-
{:db (assoc-in db [:wallet :ui :send :token] nil)}))
93+
{:db (update-in db [:wallet :ui :send] dissoc :token :tx-type)}))
9494

9595
(rf/reg-event-fx :wallet/clean-selected-collectible
9696
(fn [{:keys [db]}]
97-
(let [type (get-in db [:wallet :ui :send :type])]
97+
(let [transaction-type (get-in db [:wallet :ui :send :tx-type])]
9898
{:db (update-in db
9999
[:wallet :ui :send]
100100
dissoc
101101
:collectible
102102
:amount
103-
(when (= type :collecible) :type))})))
103+
(when (= transaction-type :collecible) :tx-type))})))
104104

105105
(rf/reg-event-fx :wallet/send-select-collectible
106106
(fn [{:keys [db]} [{:keys [collectible stack-id]}]]
107107
{:db (-> db
108108
(update-in [:wallet :ui :send] dissoc :token)
109109
(assoc-in [:wallet :ui :send :collectible] collectible)
110-
(assoc-in [:wallet :ui :send :type] :collectible)
110+
(assoc-in [:wallet :ui :send :tx-type] :collectible)
111111
(assoc-in [:wallet :ui :send :amount] 1))
112112
:fx [[:dispatch [:wallet/get-suggested-routes {:amount 1}]]
113113
[:navigate-to-within-stack [:screen/wallet.transaction-confirmation stack-id]]]}))
@@ -121,7 +121,7 @@
121121
(fn [{:keys [db now]} [{:keys [amount]}]]
122122
(let [wallet-address (get-in db [:wallet :current-viewing-account-address])
123123
token (get-in db [:wallet :ui :send :token])
124-
transaction-type (get-in db [:wallet :ui :send :type])
124+
transaction-type (get-in db [:wallet :ui :send :tx-type])
125125
collectible (get-in db [:wallet :ui :send :collectible])
126126
to-address (get-in db [:wallet :ui :send :to-address])
127127
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
@@ -191,47 +191,81 @@
191191
(fn [_]
192192
{:fx [[:dispatch [:dismiss-modal :screen/wallet.transaction-progress]]]}))
193193

194-
(defn- transaction-bridge
195-
[{:keys [from-address from-chain-id to-address token-id token-address route data eth-transfer?]}]
196-
(let [{:keys [bridge-name amount-out gas-amount
197-
gas-fees]} route
198-
eip-1559-enabled? (:eip-1559-enabled gas-fees)
194+
(defn- transaction-data
195+
[{:keys [from-address to-address token-address route data eth-transfer?]}]
196+
(let [{:keys [amount-in gas-amount gas-fees]} route
197+
eip-1559-enabled? (:eip-1559-enabled gas-fees)
199198
{:keys [gas-price max-fee-per-gas-medium
200-
max-priority-fee-per-gas]} gas-fees
201-
transfer-tx (cond-> {:From from-address
202-
:To (or token-address to-address)
203-
:Gas (money/to-hex gas-amount)
204-
:Value (when eth-transfer? amount-out)
205-
:Nonce nil
206-
:Input ""
207-
:Data (or data "0x")}
208-
eip-1559-enabled? (assoc :TxType "0x02"
209-
:MaxFeePerGas
210-
(money/to-hex
211-
(money/->wei
212-
:gwei
213-
max-fee-per-gas-medium))
214-
:MaxPriorityFeePerGas
215-
(money/to-hex
216-
(money/->wei
217-
:gwei
218-
max-priority-fee-per-gas)))
219-
(not eip-1559-enabled?) (assoc :TxType "0x00"
220-
:GasPrice (money/to-hex
221-
(money/->wei
222-
:gwei
223-
gas-price))))]
224-
[(cond-> {:BridgeName bridge-name
225-
:ChainID from-chain-id}
199+
max-priority-fee-per-gas]} gas-fees]
200+
(cond-> {:From from-address
201+
:To (or token-address to-address)
202+
:Gas (money/to-hex gas-amount)
203+
:Value (when eth-transfer? amount-in)
204+
:Nonce nil
205+
:Input ""
206+
:Data (or data "0x")}
207+
eip-1559-enabled? (assoc
208+
:TxType "0x02"
209+
:MaxFeePerGas
210+
(money/to-hex
211+
(money/->wei
212+
:gwei
213+
max-fee-per-gas-medium))
214+
:MaxPriorityFeePerGas
215+
(money/to-hex
216+
(money/->wei
217+
:gwei
218+
max-priority-fee-per-gas)))
219+
(not eip-1559-enabled?) (assoc :TxType "0x00"
220+
:GasPrice
221+
(money/to-hex
222+
(money/->wei
223+
:gwei
224+
gas-price))))))
226225

227-
(= bridge-name constants/bridge-name-erc-721-transfer)
228-
(assoc :ERC721TransferTx
229-
(assoc transfer-tx
230-
:Recipient to-address
231-
:TokenID token-id))
226+
(defn- transaction-path
227+
[{:keys [from-address to-address token-id token-address route data eth-transfer?]}]
228+
(let [{:keys [bridge-name amount-in bonder-fees from
229+
to]} route
230+
tx-data (transaction-data {:from-address from-address
231+
:to-address to-address
232+
:token-address token-address
233+
:route route
234+
:data data
235+
:eth-transfer? eth-transfer?})
236+
to-chain-id (:chain-id to)
237+
from-chain-id (:chain-id from)]
238+
(cond-> {:BridgeName bridge-name
239+
:ChainID from-chain-id}
232240

233-
(= bridge-name constants/bridge-name-transfer)
234-
(assoc :TransferTx transfer-tx))]))
241+
(= bridge-name constants/bridge-name-erc-721-transfer)
242+
(assoc :ERC721TransferTx
243+
(assoc tx-data
244+
:Recipient to-address
245+
:TokenID token-id
246+
:ChainID to-chain-id))
247+
248+
(= bridge-name constants/bridge-name-transfer)
249+
(assoc :TransferTx tx-data)
250+
251+
(= bridge-name constants/bridge-name-hop)
252+
(assoc :HopTx
253+
(assoc tx-data
254+
:ChainID to-chain-id
255+
:Symbol token-id
256+
:Recipient to-address
257+
:Amount amount-in
258+
:BonderFee bonder-fees))
259+
260+
(not (or (= bridge-name constants/bridge-name-erc-721-transfer)
261+
(= bridge-name constants/bridge-name-transfer)
262+
(= bridge-name constants/bridge-name-hop)))
263+
(assoc :CbridgeTx
264+
(assoc tx-data
265+
:ChainID to-chain-id
266+
:Symbol token-id
267+
:Recipient to-address
268+
:Amount amount-in)))))
235269

236270
(defn- multi-transaction-command
237271
[{:keys [from-address to-address from-asset to-asset amount-out transfer-type]
@@ -245,41 +279,54 @@
245279

246280
(rf/reg-event-fx :wallet/send-transaction
247281
(fn [{:keys [db]} [sha3-pwd]]
248-
(let [route (first (get-in db [:wallet :ui :send :route]))
249-
from-address (get-in db [:wallet :current-viewing-account-address])
250-
token (get-in db [:wallet :ui :send :token])
251-
collectible (get-in db [:wallet :ui :send :collectible])
252-
from-chain-id (get-in route [:from :chain-id])
253-
token-id (if token
254-
(:symbol token)
255-
(get-in collectible [:id :token-id]))
282+
(let [routes (get-in db [:wallet :ui :send :route])
283+
first-route (first routes)
284+
from-address (get-in db [:wallet :current-viewing-account-address])
285+
transaction-type (get-in db [:wallet :ui :send :tx-type])
286+
transaction-type-param (case transaction-type
287+
:collectible constants/send-type-erc-721-transfer
288+
:bridge constants/send-type-bridge
289+
constants/send-type-transfer)
290+
token (get-in db [:wallet :ui :send :token])
291+
collectible (get-in db [:wallet :ui :send :collectible])
292+
first-route-from-chain-id (get-in first-route [:from :chain-id])
293+
token-id (if token
294+
(:symbol token)
295+
(get-in collectible [:id :token-id]))
256296
erc20-transfer? (and token (not= token-id "ETH"))
257-
eth-transfer? (and token (not erc20-transfer?))
258-
token-address (cond collectible
259-
(get-in collectible
260-
[:id :contract-id :address])
261-
erc20-transfer?
262-
(get-in token [:balances-per-chain from-chain-id :address]))
263-
to-address (get-in db [:wallet :ui :send :to-address])
264-
data (when erc20-transfer?
265-
(native-module/encode-transfer (address/normalized-hex to-address)
266-
(:amount-out route)))
267-
request-params [(multi-transaction-command
268-
{:from-address from-address
269-
:to-address to-address
270-
:from-asset token-id
271-
:to-asset token-id
272-
:amount-out (if eth-transfer? (:amount-out route) "0x0")})
273-
(transaction-bridge {:to-address to-address
274-
:from-address from-address
275-
:route route
276-
:from-chain-id from-chain-id
277-
:token-address token-address
278-
:token-id (when collectible
279-
(money/to-hex (js/parseInt token-id)))
280-
:data data
281-
:eth-transfer? eth-transfer?})
282-
sha3-pwd]]
297+
eth-transfer? (and token (not erc20-transfer?))
298+
token-address (cond collectible
299+
(get-in collectible
300+
[:id :contract-id :address])
301+
erc20-transfer?
302+
(get-in token [:balances-per-chain first-route-from-chain-id :address]))
303+
to-address (get-in db [:wallet :ui :send :to-address])
304+
transaction-paths (mapv (fn [route]
305+
(let [data (when erc20-transfer?
306+
(native-module/encode-transfer
307+
(address/normalized-hex to-address)
308+
(:amount-in route)))]
309+
(transaction-path {:to-address to-address
310+
:from-address from-address
311+
:route route
312+
:token-address token-address
313+
:token-id (if collectible
314+
(money/to-hex (js/parseInt
315+
token-id))
316+
token-id)
317+
:data data
318+
:eth-transfer? eth-transfer?})))
319+
routes)
320+
request-params
321+
[(multi-transaction-command
322+
{:from-address from-address
323+
:to-address to-address
324+
:from-asset token-id
325+
:to-asset token-id
326+
:amount-out (if eth-transfer? (:amount-out first-route) "0x0")
327+
:transfer-type transaction-type-param})
328+
transaction-paths
329+
sha3-pwd]]
283330
{:json-rpc/call [{:method "wallet_createMultiTransaction"
284331
:params request-params
285332
:on-success (fn [result]
@@ -293,4 +340,8 @@
293340
(log/error "failed to send transaction"
294341
{:event :wallet/send-transaction
295342
:error error
296-
:params request-params}))}]})))
343+
:params request-params})
344+
(rf/dispatch [:toasts/upsert
345+
{:id :send-transaction-error
346+
:type :negative
347+
:text (:message error)}]))}]})))

src/status_im/contexts/wallet/send/input_amount/view.cljs

+2-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
conversion-rate (-> token :market-values-per-currency :usd :price)
207207
loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
208208
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
209+
best-routes (when suggested-routes (or (:best suggested-routes) []))
209210
route (rf/sub [:wallet/wallet-send-route])
210211
to-address (rf/sub [:wallet/wallet-send-to-address])
211212
on-confirm (or default-on-confirm handle-on-confirm)
@@ -280,7 +281,7 @@
280281
:limit-crypto crypto-limit})}]
281282
[routes/view
282283
{:amount amount-text
283-
:routes suggested-routes
284+
:routes best-routes
284285
:token token
285286
:input-value @input-value
286287
:fetch-routes #(fetch-routes % (current-limit))}]

src/status_im/contexts/wallet/send/routes/view.cljs

+3-4
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@
122122
(let [selected-networks (rf/sub [:wallet/wallet-send-selected-networks])
123123
loading-networks (find-affordable-networks token input-value selected-networks)
124124
loading-suggested-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
125-
best-routes (:best routes)
126-
data (if loading-suggested-routes? loading-networks best-routes)]
127-
(if (or (and (not-empty loading-networks) loading-suggested-routes?) (not-empty best-routes))
125+
data (if loading-suggested-routes? loading-networks routes)]
126+
(if (or (and (not-empty loading-networks) loading-suggested-routes?) (not-empty routes))
128127
[rn/flat-list
129128
{:data (if (and (< (count data) 3) (pos? (count data)))
130129
(concat data [{:status :add}])
@@ -154,7 +153,7 @@
154153
(utils/id->network (get-in item
155154
[:to :chain-id])))}])}]
156155
[rn/view {:style style/empty-container}
157-
(when (and (not (nil? best-routes)) (not loading-suggested-routes?))
156+
(when (and (not (nil? routes)) (not loading-suggested-routes?))
158157
[quo/text (i18n/label :t/no-routes-found)])])))
159158

160159
(def view (quo.theme/with-theme view-internal))

0 commit comments

Comments
 (0)