From 604eaccbbf6aea06ade280b7a5862a5519486dcf Mon Sep 17 00:00:00 2001 From: Omar Basem Date: Wed, 8 May 2024 16:31:38 +0400 Subject: [PATCH] feat: Start bridge from asset drawer (#19860) feat: Start bridge from asset drawer (#19860) --- .../contexts/wallet/account/view.cljs | 15 ++++++++----- .../contexts/wallet/bridge/flow_config.cljs | 11 ++++++++++ .../wallet/common/token_value/view.cljs | 8 ++++--- .../contexts/wallet/common/wizard.cljs | 22 ------------------- .../contexts/wallet/common/wizard/events.cljs | 6 +++-- src/status_im/contexts/wallet/events.cljs | 14 +++++++++--- .../contexts/wallet/send/events.cljs | 10 ++++----- src/status_im/navigation/screens.cljs | 3 ++- 8 files changed, 47 insertions(+), 42 deletions(-) create mode 100644 src/status_im/contexts/wallet/bridge/flow_config.cljs delete mode 100644 src/status_im/contexts/wallet/common/wizard.cljs diff --git a/src/status_im/contexts/wallet/account/view.cljs b/src/status_im/contexts/wallet/account/view.cljs index f1c732b403..521b365f51 100644 --- a/src/status_im/contexts/wallet/account/view.cljs +++ b/src/status_im/contexts/wallet/account/view.cljs @@ -33,12 +33,11 @@ {:type :wallet-networks :on-press #(rf/dispatch [:wallet/close-account-page])}] [quo/account-overview - {:container-style style/account-overview - :current-value formatted-balance + {:current-value formatted-balance :account-name name :account (if watch-only? :watched-address :default) :customization-color color}] - (when (ff/enabled? ::ff/wallet.graph) [quo/wallet-graph {:time-frame :empty}]) + [quo/wallet-graph {:time-frame :empty}] (when (not watch-only?) [quo/wallet-ctas {:container-style style/cta-buttons @@ -46,14 +45,18 @@ (rf/dispatch [:wallet/clean-send-data]) (rf/dispatch [:wallet/wizard-navigate-forward {:start-flow? true - :flow-id :wallet-flow}])) + :flow-id :wallet-send-flow}])) :receive-action #(rf/dispatch [:open-modal :screen/wallet.share-address {:status :receive}]) :buy-action #(rf/dispatch [:show-bottom-sheet {:content buy-token/view}]) + :bridge-action (fn [] + (rf/dispatch [:wallet/clean-send-data]) + (rf/dispatch [:wallet/wizard-navigate-forward + {:start-flow? true + :flow-id :wallet-bridge-flow}])) :swap-action (when (ff/enabled? ::ff/wallet.swap) - #(rf/dispatch [:wallet/start-swap])) - :bridge-action #(rf/dispatch [:wallet/start-bridge])}]) + #(rf/dispatch [:wallet/start-swap]))}]) [quo/tabs {:style style/tabs :size 32 diff --git a/src/status_im/contexts/wallet/bridge/flow_config.cljs b/src/status_im/contexts/wallet/bridge/flow_config.cljs new file mode 100644 index 0000000000..d662674dfd --- /dev/null +++ b/src/status_im/contexts/wallet/bridge/flow_config.cljs @@ -0,0 +1,11 @@ +(ns status-im.contexts.wallet.bridge.flow-config) + +(def steps + [{:screen-id :screen/wallet.bridge-select-asset + :skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :token])))} + {:screen-id :screen/wallet.bridge-to + :skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :bridge-to-chain-id])))} + {:screen-id :screen/wallet.bridge-input-amount + :skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :amount])))} + {:screen-id :screen/wallet.transaction-confirmation} + {:screen-id :screen/wallet.transaction-progress}]) diff --git a/src/status_im/contexts/wallet/common/token_value/view.cljs b/src/status_im/contexts/wallet/common/token_value/view.cljs index 2779836a66..e93ac0cedd 100644 --- a/src/status_im/contexts/wallet/common/token_value/view.cljs +++ b/src/status_im/contexts/wallet/common/token_value/view.cljs @@ -34,11 +34,13 @@ :on-press #(rf/dispatch [:open-modal :screen/wallet.share-address {:status :receive}])}) (defn- action-bridge - [] + [token-data] {:icon :i/bridge :accessibility-label :bridge :label (i18n/label :t/bridge) - :on-press #(js/alert "to be implemented")}) + :on-press (fn [] + (rf/dispatch [:hide-bottom-sheet]) + (rf/dispatch [:wallet/bridge-select-token {:token token-data}]))}) (defn- action-manage-tokens [watch-only?] @@ -66,7 +68,7 @@ (not watch-only?) (concat [(action-buy) (action-send token-data) (action-receive) - (action-bridge)]))]])) + (action-bridge token-data)]))]])) (defn view [item _ _ {:keys [watch-only?]}] diff --git a/src/status_im/contexts/wallet/common/wizard.cljs b/src/status_im/contexts/wallet/common/wizard.cljs deleted file mode 100644 index 3ef8c2b27d..0000000000 --- a/src/status_im/contexts/wallet/common/wizard.cljs +++ /dev/null @@ -1,22 +0,0 @@ -(ns status-im.contexts.wallet.common.wizard - (:require [status-im.contexts.wallet.send.flow-config :as wallet-flow] - [utils.re-frame :as rf])) - -(defn- wizard-find-next-screen - [db flow-id current-screen] - (let [flow-config (case flow-id - :wallet-flow wallet-flow/steps - nil)] - (first (filter (fn [{:keys [skip-step? screen-id]}] - (and (not= screen-id current-screen) - (not (and (fn? skip-step?) (skip-step? db))))) - flow-config)))) - -(rf/reg-event-fx - :wallet/wizard-navigate-forward - (fn [{:keys [db]} [{:keys [current-screen flow-id start-flow?]}]] - (let [next-screen (wizard-find-next-screen db flow-id current-screen)] - {:fx [[:dispatch - (if start-flow? - [:open-modal (:screen-id next-screen)] - [:navigate-to-within-stack [(:screen-id next-screen) current-screen]])]]}))) diff --git a/src/status_im/contexts/wallet/common/wizard/events.cljs b/src/status_im/contexts/wallet/common/wizard/events.cljs index 92948592e3..a6312f80e5 100644 --- a/src/status_im/contexts/wallet/common/wizard/events.cljs +++ b/src/status_im/contexts/wallet/common/wizard/events.cljs @@ -1,11 +1,13 @@ (ns status-im.contexts.wallet.common.wizard.events - (:require [status-im.contexts.wallet.send.flow-config :as wallet-flow] + (:require [status-im.contexts.wallet.bridge.flow-config :as wallet-bridge-flow] + [status-im.contexts.wallet.send.flow-config :as wallet-send-flow] [utils.re-frame :as rf])) (defn- wizard-find-next-screen [db flow-id current-screen] (let [flow-config (case flow-id - :wallet-flow wallet-flow/steps + :wallet-send-flow wallet-send-flow/steps + :wallet-bridge-flow wallet-bridge-flow/steps nil)] (first (filter (fn [{:keys [skip-step? screen-id]}] (and (not= screen-id current-screen) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 680e717133..3ee4328c9c 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -247,8 +247,13 @@ (let [to-address (get-in db [:wallet :current-viewing-account-address])] {:db (-> db (assoc-in [:wallet :ui :send :token] token) - (assoc-in [:wallet :ui :send :to-address] to-address)) - :fx [[:dispatch [:navigate-to-within-stack [:screen/wallet.bridge-to stack-id]]]]}))) + (assoc-in [:wallet :ui :send :to-address] to-address) + (assoc-in [:wallet :ui :send :tx-type] :bridge)) + :fx [[:dispatch + [:wallet/wizard-navigate-forward + {:current-screen stack-id + :start-flow? true + :flow-id :wallet-bridge-flow}]]]}))) (rf/reg-event-fx :wallet/start-bridge (fn [{:keys [db]}] @@ -258,7 +263,10 @@ (rf/reg-event-fx :wallet/select-bridge-network (fn [{:keys [db]} [{:keys [network-chain-id stack-id]}]] {:db (assoc-in db [:wallet :ui :send :bridge-to-chain-id] network-chain-id) - :fx [[:dispatch [:navigate-to-within-stack [:screen/wallet.bridge-input-amount stack-id]]]]})) + :fx [[:dispatch + [:wallet/wizard-navigate-forward + {:current-screen stack-id + :flow-id :wallet-bridge-flow}]]]})) (rf/reg-event-fx :wallet/get-ethereum-chains diff --git a/src/status_im/contexts/wallet/send/events.cljs b/src/status_im/contexts/wallet/send/events.cljs index 96d5a3b3c6..643e323564 100644 --- a/src/status_im/contexts/wallet/send/events.cljs +++ b/src/status_im/contexts/wallet/send/events.cljs @@ -146,7 +146,7 @@ [:wallet/wizard-navigate-forward {:current-screen stack-id :start-flow? start-flow? - :flow-id :wallet-flow}]]]}))) + :flow-id :wallet-send-flow}]]]}))) (rf/reg-event-fx :wallet/update-receiver-networks @@ -174,7 +174,7 @@ [:wallet/wizard-navigate-forward {:current-screen stack-id :start-flow? start-flow? - :flow-id :wallet-flow}]]]})) + :flow-id :wallet-send-flow}]]]})) (rf/reg-event-fx :wallet/edit-token-to-send @@ -236,7 +236,7 @@ [:wallet/wizard-navigate-forward {:current-screen stack-id :start-flow? start-flow? - :flow-id :wallet-flow}]]]})) + :flow-id :wallet-send-flow}]]]})) (rf/reg-event-fx :wallet/disable-from-networks (fn [{:keys [db]} [chain-ids]] @@ -339,7 +339,7 @@ :fx [[:dispatch [:wallet/wizard-navigate-forward {:current-screen :screen/wallet.transaction-confirmation - :flow-id :wallet-flow}]]]}))) + :flow-id :wallet-send-flow}]]]}))) (rf/reg-event-fx :wallet/close-transaction-progress-page (fn [_] @@ -509,4 +509,4 @@ [:wallet/wizard-navigate-forward {:current-screen stack-id :start-flow? start-flow? - :flow-id :wallet-flow}]]]})) + :flow-id :wallet-send-flow}]]]})) diff --git a/src/status_im/navigation/screens.cljs b/src/status_im/navigation/screens.cljs index 714d53155e..c729dec0bb 100644 --- a/src/status_im/navigation/screens.cljs +++ b/src/status_im/navigation/screens.cljs @@ -392,7 +392,8 @@ :component wallet-bridge-select-asset/view} {:name :screen/wallet.bridge-to - :options {:insets {:top? true}} + :options {:insets {:top? true} + :modalPresentationStyle :overCurrentContext} :component wallet-bridge-to/view} {:name :screen/wallet.bridge-input-amount