Compare commits

...
Author SHA1 Message Date
Ajay Sivan c939412b8e lint-fix 2024-07-24 15:51:45 +05:30
Ajay Sivan 3cbc7c1730 Style fixes 2024-07-24 15:51:45 +05:30
Ajay Sivan a4db8d6995 Network selection fix 2024-07-24 15:51:44 +05:30
Ajay Sivan 6417221c6d Split events 2024-07-24 15:51:44 +05:30
Ajay Sivan fcdfc890e8 Remove outdated test 2024-07-24 15:51:44 +05:30
Ajay Sivan bda7d1c58d Fix single network flow 2024-07-24 15:51:44 +05:30
Ajay Sivan bf1b039df5 Logic cleanup 2024-07-24 15:51:43 +05:30
Ajay Sivan b55e4208e5 Launch Swap Flows 2024-07-24 15:51:43 +05:30
7 changed files with 54 additions and 21 deletions
@@ -1,6 +1,5 @@
(ns status-im.contexts.wallet.common.token-value.view
(:require [quo.core :as quo]
[status-im.common.not-implemented :as not-implemented]
[status-im.contexts.wallet.sheets.buy-token.view :as buy-token]
[status-im.feature-flags :as ff]
[utils.i18n :as i18n]
@@ -44,11 +43,18 @@
(rf/dispatch [:wallet/bridge-select-token bridge-params]))})
(defn- action-swap
[]
{:icon :i/swap
:accessibility-label :swap
:label (i18n/label :t/swap)
:on-press #(not-implemented/alert)})
[token-symbol]
(let [current-viewing-account-address (rf/sub [:wallet/current-viewing-account-address])
account-address (or current-viewing-account-address
(:address (first (rf/sub [:wallet/operable-accounts]))))
token (rf/sub [:wallet/token-with-networks token-symbol
account-address])]
{:icon :i/swap
:accessibility-label :swap
:label (i18n/label :t/swap)
:on-press (fn []
(rf/dispatch [:hide-bottom-sheet])
(rf/dispatch [:wallet.swap/start-with-token token]))}))
(defn- action-manage-tokens
[watch-only?]
@@ -90,7 +96,7 @@
(when (seq token-owners)
(action-send send-or-bridge-params entry-point))
(action-receive selected-account?)
(when (ff/enabled? ::ff/wallet.swap) (action-swap))
(when (ff/enabled? ::ff/wallet.swap) (action-swap token-symbol))
(when (seq (seq token-owners))
(action-bridge send-or-bridge-params))]))]]))
+17 -2
View File
@@ -1,18 +1,33 @@
(ns status-im.contexts.wallet.swap.events
(:require [re-frame.core :as rf]
[status-im.constants :as constants]
[status-im.contexts.communities.utils :as utils]
[status-im.contexts.wallet.sheets.network-selection.view :as network-selection]
[utils.number]))
(rf/reg-event-fx :wallet.swap/start
(fn [{:keys [_db]}]
(fn [{:keys [_]}]
{:fx [[:dispatch [:open-modal :screen/wallet.swap-select-asset-to-pay]]]}))
(rf/reg-event-fx :wallet.swap/start-with-token
(fn [{:keys [db]} [token]]
(let [current-address (get-in db [:wallet :current-viewing-account-address])
address (:address (first (utils/sorted-operable-non-watch-only-accounts db)))
token-networks (:networks token)]
{:fx [(when-not current-address
[:dispatch
[:wallet/switch-current-viewing-account address]])
[:dispatch
[:wallet.swap/select-asset-to-pay
{:token token
:network (when (= count token-networks)
(first token-networks))}]]]})))
(rf/reg-event-fx :wallet.swap/select-asset-to-pay
(fn [{:keys [db]} [{:keys [token network]}]]
{:db (-> db
(assoc-in [:wallet :ui :swap :asset-to-pay] token)
(assoc-in [:wallet :ui :swap :network] network))
(cond-> network (assoc-in [:wallet :ui :swap :network] network)))
:fx (if network
[[:dispatch [:navigate-to :screen/wallet.swap-propasal]]
[:dispatch [:wallet.swap/set-default-slippage]]]
@@ -1,4 +1,6 @@
(ns status-im.contexts.wallet.swap.swap-proposal.style)
(def container
{:flex 1})
{:flex 1
:padding 16
:gap 16})
@@ -9,6 +9,10 @@
[]
(let [max-slippage (rf/sub [:wallet/swap-max-slippage])]
[rn/view {:style style/container}
[quo/button
{:on-press #(rf/dispatch [:navigate-back])
:type :grey}
"Back"]
[quo/button
{:on-press #(rf/dispatch [:show-bottom-sheet
{:content slippage-settings/view}])}
+5 -3
View File
@@ -21,9 +21,11 @@
(rf/reg-sub
:wallet/swap-asset-to-pay-networks
:<- [:wallet/swap-asset-to-pay]
(fn [token]
(let [{token-networks :networks} token
(fn []
[(rf/subscribe [:wallet/swap-asset-to-pay])
(rf/subscribe [:wallet/current-viewing-account-tokens-filtered])])
(fn [[asset-to-pay tokens]]
(let [{token-networks :networks} (some #(when (= (:symbol %) (:symbol asset-to-pay)) %) tokens)
grouped-networks (group-by :layer
token-networks)
mainnet-network (first (get grouped-networks constants/layer-1-network))
-8
View File
@@ -90,14 +90,6 @@
swap-data)
(is (match? "SNT" (rf/sub [sub-name])))))
(h/deftest-sub :wallet/swap-asset-to-pay-networks
[sub-name]
(testing "Return the available networks for the swap asset-to-pay"
(swap! rf-db/app-db assoc-in
[:wallet :ui :swap]
swap-data)
(is (match? networks (rf/sub [sub-name])))))
(h/deftest-sub :wallet/swap-asset-to-pay-network-balance
[sub-name]
(testing "Return swap asset-to-pay"
+12
View File
@@ -426,6 +426,18 @@
sorted-tokens))
sorted-tokens))))
(rf/reg-sub
:wallet/token-with-networks
:<- [:wallet/accounts]
:<- [:wallet/network-details]
(fn [[accounts networks] [_ token-symbol account-address]]
(let [account (utils/get-account-by-address accounts account-address)
token (some #(when (= token-symbol (:symbol %)) %)
(:tokens account))]
(assoc token
:networks
(network-utils/network-list token networks)))))
(rf/reg-sub
:wallet/token-by-symbol
:<- [:wallet/current-viewing-account]