feat(wallet): Fix bugs in the bridge flow and add missing entry points (#20197)

* Fix "Bridge to" screen not showing

* Fix "Unkown flow" alert in bridge flow

* Fix warnings in transaction confirmation page

* Fix missing images and strings while bridging in transaction confirmation page

* Fix stale data shown for an instant in the suggested routes component

* Add support for bridge flow started in the wallet home screen

* Fix fetch-activities event
This commit is contained in:
Ulises Manuel 2024-06-13 10:32:34 -06:00 committed by GitHub
parent 26c4a736ad
commit 435bf3dbd5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 158 additions and 106 deletions

View File

@ -25,15 +25,17 @@
(defn view
[]
(let [selected-tab (or (rf/sub [:wallet/account-tab]) first-tab-id)
{:keys [name color formatted-balance watch-only?
address]} (rf/sub [:wallet/current-viewing-account])
{:keys [name color formatted-balance
watch-only?]} (rf/sub [:wallet/current-viewing-account])
customization-color (rf/sub [:profile/customization-color])]
(rn/use-unmount #(rf/dispatch [:wallet/clean-send-data]))
(rn/use-mount
#(rf/dispatch [:wallet/fetch-activities-for-current-account address]))
#(rf/dispatch [:wallet/fetch-activities-for-current-account]))
[rn/view {:style {:flex 1}}
[account-switcher/view
{:type :wallet-networks
:on-press #(rf/dispatch [:wallet/close-account-page])}]
:on-press (fn []
(rf/dispatch [:wallet/close-account-page]))}]
[quo/account-overview
{:container-style style/account-overview
:current-value formatted-balance

View File

@ -51,6 +51,9 @@
account-token (when account-token (assoc account-token :networks (:networks token)))
bridge-to-title (i18n/label :t/bridge-to
{:name (string/upper-case (str token-symbol))})]
(rn/use-unmount #(rf/dispatch [:wallet/clean-bridge-to-selection]))
[rn/view
[account-switcher/view
{:on-press #(rf/dispatch [:navigate-back])

View File

@ -1,7 +1,9 @@
(ns status-im.contexts.wallet.bridge.flow-config)
(def steps
[{:screen-id :screen/wallet.bridge-select-asset
[{:screen-id :screen/wallet.select-from
:skip-step? (fn [db] (some? (get-in db [:wallet :current-viewing-account-address])))}
{: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])))}

View File

@ -8,11 +8,16 @@
(defn view
[]
(rn/use-unmount #(rf/dispatch [:wallet/clean-routes-calculation]))
[rn/view {:style style/bridge-send-wrapper}
[input-amount/view
{:current-screen-id :screen/wallet.bridge-input-amount
:button-one-label (i18n/label :t/review-bridge)
:button-one-props {:icon-left :i/bridge}
:on-confirm (fn [amount]
(rf/dispatch [:wallet/set-token-amount-to-bridge
{:amount amount
:stack-id :screen/wallet.bridge-input-amount}]))
:on-navigate-back (fn []
(rf/dispatch [:wallet/clean-disabled-from-networks])
(rf/dispatch [:wallet/clean-send-amount])

View File

@ -15,7 +15,9 @@
(fn []
[rn/view {:style {:flex 1}}
[account-switcher/view
{:on-press #(rf/dispatch [:navigate-back])
{:on-press (fn []
(rf/dispatch [:navigate-back])
(rf/dispatch [:wallet/clean-selected-token]))
:accessibility-label :top-bar
:switcher-type :select-account}]
[quo/page-top {:title (i18n/label :t/bridge)}]

View File

@ -35,13 +35,13 @@
#(rf/dispatch [:open-modal :screen/share-shell {:initial-tab :wallet}]))})
(defn- action-bridge
[token-data]
[bridge-params]
{:icon :i/bridge
:accessibility-label :bridge
:label (i18n/label :t/bridge)
:on-press (fn []
(rf/dispatch [:hide-bottom-sheet])
(rf/dispatch [:wallet/bridge-select-token {:token token-data}]))})
(rf/dispatch [:wallet/bridge-select-token bridge-params]))})
(defn- action-swap
[]
@ -68,9 +68,10 @@
(defn token-value-drawer
[token watch-only?]
(let [token-symbol (:token token)
token-data (first (rf/sub [:wallet/current-viewing-account-tokens-filtered token-symbol]))
token-data (first (rf/sub [:wallet/current-viewing-account-tokens-filtered
token-symbol]))
selected-account? (rf/sub [:wallet/current-viewing-account-address])
send-params (if selected-account?
send-or-bridge-params (if selected-account?
{:token token-data
:stack-id :screen/wallet.accounts
:start-flow? true}
@ -83,10 +84,10 @@
(when (ff/enabled? ::ff/wallet.assets-modal-hide)
(action-hide))]
(not watch-only?) (concat [(action-buy)
(action-send send-params)
(action-send send-or-bridge-params)
(action-receive selected-account?)
(when (ff/enabled? ::ff/wallet.swap) (action-swap))
(action-bridge token-data)]))]]))
(action-bridge send-or-bridge-params)]))]]))
(defn view
[item _ _ {:keys [watch-only?]}]

View File

@ -42,7 +42,7 @@
(fn [{:keys [db]} [address]]
{:db (assoc-in db [:wallet :current-viewing-account-address] address)
:fx [[:dispatch [:navigate-to-within-stack [:screen/wallet.accounts :shell-stack] address]]
[:dispatch [:wallet/fetch-activities]]]}))
[:dispatch [:wallet/fetch-activities-for-current-account]]]}))
(rf/reg-event-fx :wallet/navigate-to-new-account
(fn [{:keys [db]} [address]]
@ -259,12 +259,14 @@
(rf/reg-event-fx :wallet/get-keypairs get-keypairs)
(rf/reg-event-fx :wallet/bridge-select-token
(fn [{:keys [db]} [{:keys [token stack-id]}]]
(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)
(assoc-in [:wallet :ui :send :tx-type] :tx/bridge))
(fn [{:keys [db]} [{:keys [token token-symbol stack-id]}]]
(let [missing-recipient? (-> db :wallet :ui :send :to-address nil?)
to-address (-> db :wallet :current-viewing-account-address)]
{:db (cond-> db
:always (assoc-in [:wallet :ui :send :tx-type] :tx/bridge)
token (assoc-in [:wallet :ui :send :token] token)
token-symbol (assoc-in [:wallet :ui :send :token-symbol] token-symbol)
missing-recipient? (assoc-in [:wallet :ui :send :to-address] to-address))
:fx [[:dispatch
[:wallet/wizard-navigate-forward
{:current-screen stack-id

View File

@ -197,8 +197,8 @@
(let [{token-networks :networks} token
receiver-networks (get-in db [:wallet :ui :send :receiver-networks])
token-networks-ids (mapv #(:chain-id %) token-networks)
token-not-supported-in-receiver-networks? (not (some (set receiver-networks)
token-networks-ids))]
token-not-supported-in-receiver-networks? (not-any? (set receiver-networks)
token-networks-ids)]
{:db (cond-> db
:always (update-in [:wallet :ui :send] dissoc :collectible)
:always (assoc-in [:wallet :ui :send :token-display-name]
@ -305,6 +305,29 @@
:start-flow? start-flow?
:flow-id :wallet-send-flow}]]]}))
(rf/reg-event-fx
:wallet/set-token-amount-to-bridge
(fn [{:keys [db]} [{:keys [amount stack-id start-flow?]}]]
{:db (assoc-in db [:wallet :ui :send :amount] amount)
:fx [[:dispatch
[:wallet/wizard-navigate-forward
{:current-screen stack-id
:start-flow? start-flow?
:flow-id :wallet-bridge-flow}]]]}))
(rf/reg-event-fx
:wallet/clean-bridge-to-selection
(fn [{:keys [db]}]
{:db (update-in db [:wallet :ui :send] dissoc :bridge-to-chain-id)}))
(rf/reg-event-fx
:wallet/clean-routes-calculation
(fn [{:keys [db]}]
(let [keys-to-remove [:to-values-by-chain :network-links :sender-network-values :route
:receiver-network-values :suggested-routes :from-values-by-chain
:loading-suggested-routes? :suggested-routes-call-timestamp]]
{:db (update-in db [:wallet :ui :send] #(apply dissoc % keys-to-remove))})))
(rf/reg-event-fx :wallet/disable-from-networks
(fn [{:keys [db]} [chain-ids]]
{:db (assoc-in db [:wallet :ui :send :disabled-from-chain-ids] chain-ids)}))
@ -463,7 +486,7 @@
(fn [{:keys [db]}]
(let [address (get-in db [:wallet :current-viewing-account-address])]
{:fx [[:dispatch [:wallet/navigate-to-account-within-stack address]]
[:dispatch [:wallet/fetch-activities]]
[:dispatch [:wallet/fetch-activities-for-current-account]]
[:dispatch [:wallet/select-account-tab :activity]]
[:dispatch-later
[{:ms 20
@ -632,7 +655,8 @@
(rf/reg-event-fx
:wallet/select-from-account
(fn [{db :db} [{:keys [address stack-id network-details start-flow?]}]]
(let [token-symbol (-> db :wallet :ui :send :token-symbol)
(let [{:keys [token-symbol
tx-type]} (-> db :wallet :ui :send)
token (when token-symbol
;; When this flow has started in the wallet home page, we know the
;; token or collectible to send, but we don't know from which
@ -640,15 +664,17 @@
(let [token (utils/get-token-from-account db token-symbol address)]
(assoc token
:networks (network-utils/network-list token network-details)
:total-balance (utils/calculate-total-token-balance token))))]
{:db (if token-symbol
(-> db
(assoc-in [:wallet :ui :send :token] token)
(update-in [:wallet :ui :send] dissoc :token-symbol))
db)
:total-balance (utils/calculate-total-token-balance token))))
bridge-tx? (= tx-type :tx/bridge)
flow-id (if bridge-tx?
:wallet-bridge-flow
:wallet-send-flow)]
{:db (cond-> db
token-symbol (assoc-in [:wallet :ui :send :token] token)
bridge-tx? (assoc-in [:wallet :ui :send :to-address] address))
:fx [[:dispatch [:wallet/switch-current-viewing-account address]]
[:dispatch
[:wallet/wizard-navigate-forward
{:current-screen stack-id
:start-flow? start-flow?
:flow-id :wallet-send-flow}]]]})))
:flow-id flow-id}]]]})))

View File

@ -19,6 +19,7 @@
(defn- on-close
[]
(rf/dispatch [:wallet/clean-current-viewing-account])
(rf/dispatch [:wallet/clean-send-data])
(rf/dispatch [:navigate-back]))
(defn- render-fn

View File

@ -394,7 +394,7 @@
sending-to-unpreferred-networks?
#(show-unpreferred-networks-alert on-confirm)
:else
on-confirm)}
#(on-confirm amount))}
(when should-try-again?
{:type :grey}))}]
[quo/numbered-keyboard

View File

@ -15,8 +15,8 @@
[utils.security.core :as security]))
(defn- transaction-title
[{:keys [token-display-name amount account to-address route to-network image-url transaction-type
collectible?]}]
[{:keys [token-display-name amount account to-address route to-network image-url
transaction-type collectible?]}]
(let [to-network-name (:network-name to-network)
to-network-color (if (= to-network-name :mainnet) :ethereum to-network-name)]
[rn/view {:style style/content-container}
@ -30,11 +30,12 @@
(i18n/label :t/bridge)
(i18n/label :t/send))]
[quo/summary-tag
{:token (if collectible? "" token-display-name)
(cond-> {:token (if collectible? "" token-display-name)
:label (str amount " " token-display-name)
:type (if collectible? :collectible :token)
:image-source (if collectible? image-url :eth)}]]
:type (if collectible? :collectible :token)}
collectible? (assoc :image-source image-url))]]
(if (= transaction-type :tx/bridge)
(doall
(map-indexed
(fn [idx path]
(let [from-network (:from path)
@ -46,6 +47,7 @@
network-name-capitalized (when (seq network-name-text)
(string/capitalize network-name-text))
network-color (if (= network-name :mainnet) :ethereum network-name)]
(with-meta
[rn/view
{:style {:flex-direction :row
:margin-top 4}}
@ -73,8 +75,9 @@
{:label network-name-capitalized
:type :network
:image-source (:source network)
:customization-color network-color}]])]))
route)
:customization-color network-color}]])]
{:key (str "transaction-title" idx)})))
route))
[rn/view
{:style {:flex-direction :row
:margin-top 4}}
@ -126,13 +129,16 @@
(defn- user-summary
[{:keys [network-values token-display-name account-props theme label accessibility-label
summary-type]}]
(let [network-values
(reduce-kv
(let [network-values (reduce-kv
(fn [acc chain-id amount]
(let [network-name (network-utils/id->network chain-id)]
(let [network-name (network-utils/id->network chain-id)
network-keyword (if (= network-name :mainnet)
:ethereum
network-name)]
(assoc acc
(if (= network-name :mainnet) :ethereum network-name)
{:amount amount :token-symbol token-display-name})))
network-keyword
{:amount amount
:token-symbol token-display-name})))
{}
network-values)]
[rn/view
@ -209,6 +215,8 @@
(get-in collectible [:preview-url :uri]))
transaction-type (:tx-type send-transaction-data)
estimated-time-min (reduce + (map :estimated-time route))
token-symbol (or token-display-name
(-> send-transaction-data :token :symbol))
first-route (first route)
native-currency-symbol (get-in first-route [:from :native-currency-symbol])
native-token (when native-currency-symbol
@ -265,7 +273,7 @@
:customization-color (:color account)}
[rn/view
[transaction-title
{:token-display-name token-display-name
{:token-display-name token-symbol
:amount amount
:account account
:to-address to-address
@ -275,7 +283,7 @@
:transaction-type transaction-type
:collectible? collectible?}]
[user-summary
{:token-display-name token-display-name
{:token-display-name token-symbol
:summary-type :status-account
:accessibility-label :summary-from-label
:label (i18n/label :t/from-capitalized)
@ -283,7 +291,7 @@
:account-props from-account-props
:theme theme}]
[user-summary
{:token-display-name token-display-name
{:token-display-name token-symbol
:summary-type (if (= transaction-type :tx/bridge)
:status-account
:account)