some refactoring based on feedback
Signed-off-by: Brian Sztamfater <brian@status.im>
This commit is contained in:
parent
7a34d1b1d3
commit
3ff460fdc7
|
@ -14,11 +14,12 @@
|
||||||
|
|
||||||
(defn- bridge-token-component
|
(defn- bridge-token-component
|
||||||
[]
|
[]
|
||||||
(fn [{:keys [chain-id network-name]} {:keys [supported-networks] :as token} selected-network]
|
(fn [{:keys [chain-id network-name]} {:keys [supported-networks] :as token}]
|
||||||
(let [network (rf/sub [:wallet/network-details-by-chain-id chain-id])
|
(let [network (rf/sub [:wallet/network-details-by-chain-id chain-id])
|
||||||
currency (rf/sub [:profile/currency])
|
currency (rf/sub [:profile/currency])
|
||||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||||
prices-per-token (rf/sub [:wallet/prices-per-token])
|
prices-per-token (rf/sub [:wallet/prices-per-token])
|
||||||
|
selected-network (rf/sub [:wallet/send-network])
|
||||||
{selected-network-chain-id :chain-id} selected-network
|
{selected-network-chain-id :chain-id} selected-network
|
||||||
balance (utils/calculate-total-token-balance token [chain-id])
|
balance (utils/calculate-total-token-balance token [chain-id])
|
||||||
crypto-value (utils/get-standard-crypto-format token
|
crypto-value (utils/get-standard-crypto-format token
|
||||||
|
@ -51,7 +52,6 @@
|
||||||
(let [network-details (rf/sub [:wallet/network-details])
|
(let [network-details (rf/sub [:wallet/network-details])
|
||||||
account (rf/sub [:wallet/current-viewing-account])
|
account (rf/sub [:wallet/current-viewing-account])
|
||||||
token (rf/sub [:wallet/wallet-send-token])
|
token (rf/sub [:wallet/wallet-send-token])
|
||||||
selected-network (rf/sub [:wallet/send-network])
|
|
||||||
token-symbol (:symbol token)
|
token-symbol (:symbol token)
|
||||||
tokens (:tokens account)
|
tokens (:tokens account)
|
||||||
mainnet (first network-details)
|
mainnet (first network-details)
|
||||||
|
@ -73,11 +73,11 @@
|
||||||
:switcher-type :select-account}]
|
:switcher-type :select-account}]
|
||||||
[quo/page-top {:title bridge-to-title}]
|
[quo/page-top {:title bridge-to-title}]
|
||||||
[rn/view style/content-container
|
[rn/view style/content-container
|
||||||
[bridge-token-component (assoc mainnet :network-name :t/mainnet) account-token selected-network]]
|
[bridge-token-component (assoc mainnet :network-name :t/mainnet) account-token]]
|
||||||
|
|
||||||
[quo/divider-label (i18n/label :t/layer-2)]
|
[quo/divider-label (i18n/label :t/layer-2)]
|
||||||
[rn/flat-list
|
[rn/flat-list
|
||||||
{:data layer-2-networks
|
{:data layer-2-networks
|
||||||
:render-fn (fn [network]
|
:render-fn (fn [network]
|
||||||
[bridge-token-component network account-token selected-network])
|
[bridge-token-component network account-token])
|
||||||
:content-container-style style/content-container}]]))
|
:content-container-style style/content-container}]]))
|
||||||
|
|
|
@ -391,27 +391,37 @@
|
||||||
token-symbol (assoc-in [:wallet :ui :send :token-symbol] token-symbol)
|
token-symbol (assoc-in [:wallet :ui :send :token-symbol] token-symbol)
|
||||||
network (assoc-in [:wallet :ui :send :network] network)
|
network (assoc-in [:wallet :ui :send :network] network)
|
||||||
missing-recipient? (assoc-in [:wallet :ui :send :to-address] to-address))
|
missing-recipient? (assoc-in [:wallet :ui :send :to-address] to-address))
|
||||||
:fx (if (and (not unique-owner) multi-account-balance? root-screen?)
|
:fx (cond
|
||||||
|
;; If the token has a balance in more than one account and this was dispatched from the
|
||||||
|
;; general wallet screen, open the account selection screen.
|
||||||
|
(and (not unique-owner) multi-account-balance? root-screen?)
|
||||||
[[:dispatch [:open-modal :screen/wallet.select-from]]]
|
[[:dispatch [:open-modal :screen/wallet.select-from]]]
|
||||||
(if (some? network)
|
|
||||||
[[:dispatch
|
;; If the token has a balance in only one account (or this was dispatched from the
|
||||||
[:wallet/wizard-navigate-forward
|
;; account screen) and the network is already set, navigate forward in the bridge flow.
|
||||||
{:current-screen stack-id
|
(some? network)
|
||||||
:start-flow? start-flow?
|
[[:dispatch
|
||||||
:flow-id :wallet-bridge-flow}]]]
|
[:wallet/wizard-navigate-forward
|
||||||
[[:dispatch [:wallet/switch-current-viewing-account to-address]]
|
{:current-screen stack-id
|
||||||
[:dispatch
|
:start-flow? start-flow?
|
||||||
[:show-bottom-sheet
|
:flow-id :wallet-bridge-flow}]]]
|
||||||
{:content (fn []
|
|
||||||
[network-selection/view
|
;; If we know which account to bridge the token from but the network is not set yet,
|
||||||
{:title (i18n/label :t/select-network-to-bridge-from)
|
;; show the network selection drawer.
|
||||||
:token-symbol (or token-symbol (:symbol token))
|
:else
|
||||||
:source :bridge
|
[[:dispatch [:wallet/switch-current-viewing-account to-address]]
|
||||||
:on-select-network (fn [network]
|
[:dispatch
|
||||||
(rf/dispatch [:hide-bottom-sheet])
|
[:show-bottom-sheet
|
||||||
(rf/dispatch
|
{:content (fn []
|
||||||
[:wallet/bridge-select-token
|
[network-selection/view
|
||||||
(assoc params :network network)]))}])}]]]))})))
|
{:title (i18n/label :t/select-network-to-bridge-from)
|
||||||
|
:token-symbol (or token-symbol (:symbol token))
|
||||||
|
:source :bridge
|
||||||
|
:on-select-network (fn [network]
|
||||||
|
(rf/dispatch [:hide-bottom-sheet])
|
||||||
|
(rf/dispatch
|
||||||
|
[:wallet/bridge-select-token
|
||||||
|
(assoc params :network network)]))}])}]]])})))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/start-bridge
|
(rf/reg-event-fx :wallet/start-bridge
|
||||||
(fn [{:keys [db]}]
|
(fn [{:keys [db]}]
|
||||||
|
|
|
@ -169,10 +169,7 @@
|
||||||
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||||
network-details (-> (get-in db
|
network-details (-> (get-in db
|
||||||
[:wallet :networks (if test-networks-enabled? :test :prod)])
|
[:wallet :networks (if test-networks-enabled? :test :prod)])
|
||||||
(network-utils/sorted-networks-with-details))
|
(network-utils/sorted-networks-with-details))]
|
||||||
next-screen (:screen-id (wizard-utils/wizard-find-next-screen db
|
|
||||||
:wallet-send-flow
|
|
||||||
stack-id))]
|
|
||||||
(when (or token-data token-symbol)
|
(when (or token-data token-symbol)
|
||||||
{:db (cond-> db
|
{:db (cond-> db
|
||||||
network (update-in [:wallet :ui :send]
|
network (update-in [:wallet :ui :send]
|
||||||
|
@ -191,31 +188,41 @@
|
||||||
:token-symbol (:symbol token-data)))
|
:token-symbol (:symbol token-data)))
|
||||||
unique-owner (assoc-in [:wallet :current-viewing-account-address] unique-owner)
|
unique-owner (assoc-in [:wallet :current-viewing-account-address] unique-owner)
|
||||||
entry-point (assoc-in [:wallet :ui :send :entry-point] entry-point))
|
entry-point (assoc-in [:wallet :ui :send :entry-point] entry-point))
|
||||||
:fx (if (and (not unique-owner) multi-account-balance? root-screen?)
|
:fx (cond
|
||||||
|
;; If the token has a balance in more than one account and this was dispatched from
|
||||||
|
;; the general wallet screen, open the account selection screen.
|
||||||
|
(and (not unique-owner) multi-account-balance? root-screen?)
|
||||||
[[:dispatch [:open-modal :screen/wallet.select-from]]]
|
[[:dispatch [:open-modal :screen/wallet.select-from]]]
|
||||||
(if (or (= next-screen :screen/wallet.select-from) (some? network))
|
|
||||||
[[:dispatch [:wallet/stop-and-clean-suggested-routes]]
|
;; If the token has a balance in only one account (or this was dispatched from the
|
||||||
[:dispatch
|
;; account screen) and the network is already set, stop and clean suggested routes,
|
||||||
;; ^:flush-dom allows us to make sure the re-frame DB state is always synced
|
;; then navigate forward in the send flow.
|
||||||
;; before the navigation occurs, so the new screen is always rendered with
|
(some? network)
|
||||||
;; the DB state set by this event. By adding the metadata we are omitting
|
[[:dispatch [:wallet/stop-and-clean-suggested-routes]]
|
||||||
;; a 1-frame blink when the screen is mounted.
|
[:dispatch
|
||||||
^:flush-dom
|
;; ^:flush-dom allows us to make sure the re-frame DB state is always synced
|
||||||
[:wallet/wizard-navigate-forward
|
;; before the navigation occurs, so the new screen is always rendered with
|
||||||
{:current-screen stack-id
|
;; the DB state set by this event. By adding the metadata we are omitting
|
||||||
:start-flow? start-flow?
|
;; a 1-frame blink when the screen is mounted.
|
||||||
:flow-id :wallet-send-flow}]]]
|
^:flush-dom
|
||||||
[[:dispatch
|
[:wallet/wizard-navigate-forward
|
||||||
[:show-bottom-sheet
|
{:current-screen stack-id
|
||||||
{:content (fn []
|
:start-flow? start-flow?
|
||||||
[network-selection/view
|
:flow-id :wallet-send-flow}]]]
|
||||||
{:token-symbol (or token-symbol (:symbol token-data))
|
|
||||||
:source :send
|
;; If we don't know the network but need to set it, show the network selection drawer.
|
||||||
:on-select-network (fn [network]
|
:else
|
||||||
(rf/dispatch [:hide-bottom-sheet])
|
[[:dispatch
|
||||||
(rf/dispatch
|
[:show-bottom-sheet
|
||||||
[:wallet/set-token-to-send
|
{:content (fn []
|
||||||
(assoc params :network network)]))}])}]]]))}))))
|
[network-selection/view
|
||||||
|
{:token-symbol (or token-symbol (:symbol token-data))
|
||||||
|
:source :send
|
||||||
|
:on-select-network (fn [network]
|
||||||
|
(rf/dispatch [:hide-bottom-sheet])
|
||||||
|
(rf/dispatch
|
||||||
|
[:wallet/set-token-to-send
|
||||||
|
(assoc params :network network)]))}])}]]])}))))
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:wallet/edit-token-to-send
|
:wallet/edit-token-to-send
|
||||||
|
@ -273,7 +280,7 @@
|
||||||
|
|
||||||
collectible
|
collectible
|
||||||
(str (:name collection-data) " #" collectible-id))
|
(str (:name collection-data) " #" collectible-id))
|
||||||
owner-address (-> collectible :ownership first :address)
|
owner-address (-> db :wallet :current-viewing-account-address)
|
||||||
collectible-tx (-> db
|
collectible-tx (-> db
|
||||||
(update-in [:wallet :ui :send] dissoc :token)
|
(update-in [:wallet :ui :send] dissoc :token)
|
||||||
(assoc-in [:wallet :ui :send :collectible] collectible)
|
(assoc-in [:wallet :ui :send :collectible] collectible)
|
||||||
|
|
Loading…
Reference in New Issue