fix(wallet)_: General send flow for saved address and scanned address (#21899)

This commit:

- fixes send flow from saved addresses
- adds back send flow from general QR scanner

Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
Mohamed Javid 2025-01-14 17:57:21 +05:30 committed by GitHub
parent 457ed15e0b
commit 2d8ba41d89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 103 additions and 53 deletions

View File

@ -13,19 +13,15 @@
[{:keys [name full-address chain-short-names address customization-color] :as opts}]
(let [open-send-flow (rn/use-callback
(fn []
(rf/dispatch [:hide-bottom-sheet])
(rf/dispatch [:pop-to-root :shell-stack])
(js/setTimeout #(rf/dispatch [:wallet/select-send-address
{:address full-address
:recipient
{:label name
:customization-color
customization-color
:recipient-type :saved-address}
:stack-id :wallet-select-address
:start-flow? true}])
400))
[full-address])
(rf/dispatch [:wallet/init-send-flow-for-address
{:address full-address
:recipient
{:label name
:customization-color
customization-color
:recipient-type :saved-address}
:stack-id :screen/settings.saved-addresses}]))
[full-address name customization-color])
open-eth-chain-explorer (rn/use-callback
#(rf/dispatch [:wallet/navigate-to-chain-explorer
{:address address

View File

@ -2,6 +2,8 @@
(:require
[quo.core :as quo]
[react-native.clipboard :as clipboard]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.common.utils.networks :as network-utils]
[status-im.feature-flags :as ff]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
@ -13,16 +15,15 @@
{:type :positive
:text (i18n/label :t/address-copied)}]))
#_(defn- send-to-address
[address]
(let [[_ split-address] (network-utils/split-network-full-address address)]
(rf/dispatch
[:wallet/select-send-address
{:address address
:recipient {:recipient-type :address
:label (utils/get-shortened-address split-address)}
:stack-id :wallet-select-address
:start-flow? true}])))
(defn- send-to-address
[address]
(let [[_ split-address] (network-utils/split-network-full-address address)]
(rf/dispatch
[:wallet/init-send-flow-for-address
{:address address
:recipient {:recipient-type :address
:label (utils/get-shortened-address split-address)}
:stack-id :wallet-select-address}])))
(defn view
[address]
@ -33,13 +34,10 @@
:accessibility-label :send-asset
:label (i18n/label :t/copy-address)
:on-press #(copy-address address)}
;; Originally, the flow went to the send flow, but it has been removed to avoid bugs,
;; please check https://github.com/status-im/status-mobile/issues/20972 for more context
;; The previous code has been commented out to be reintroduced in the future easily.
#_{:icon :i/send
:accessibility-label :send-asset
:label (i18n/label :t/send-to-this-address)
:on-press #(send-to-address address)}
{:icon :i/send
:accessibility-label :send-asset
:label (i18n/label :t/send-to-this-address)
:on-press #(send-to-address address)}
(when (ff/enabled? :ff/wallet.saved-addresses)
{:icon :i/save
:accessibility-label :save-address

View File

@ -116,6 +116,39 @@
(fn [{:keys [db]}]
{:db (update-in db [:wallet :ui :send] dissoc :amount)}))
(rf/reg-event-fx
:wallet/init-send-flow-for-address
(fn [{:keys [db]} [{:keys [recipient address stack-id]}]]
(let [[_ address-without-prefix] (utils/split-prefix-and-address address)
wallet-accounts (vals (get-in db [:wallet :accounts]))
default-account-address (some #(when (:default-account? %) (:address %))
wallet-accounts)
multiple-accounts? (-> (filter :operable? wallet-accounts)
count
(> 1))]
{:db (cond-> (update-in db [:wallet :ui] dissoc :send)
(not multiple-accounts?)
(assoc-in [:wallet :current-viewing-account-address] default-account-address)
:always
(update-in
[:wallet :ui :send]
assoc
:general-flow? true
:recipient (or recipient address)
:to-address address-without-prefix))
:fx [[:dispatch [:hide-bottom-sheet]]
[:dispatch [:shell/change-tab :wallet-stack]]
[:dispatch [:pop-to-root :shell-stack]]
[:dispatch-later
[{:ms 600
:dispatch (if multiple-accounts?
[:open-modal :screen/wallet.select-from]
[:wallet/wizard-navigate-forward
{:current-screen stack-id
:start-flow? true
:flow-id :wallet-send-flow}])}]]]})))
(rf/reg-event-fx
:wallet/select-send-address
(fn [{:keys [db]} [{:keys [address recipient stack-id start-flow?]}]]
@ -185,7 +218,7 @@
{:db (cond-> db
network (update-in [:wallet :ui :send]
#(-> %
(dissoc :collectible :tx-type)
(dissoc :collectible)
(assoc :network network)))
token-symbol (assoc-in [:wallet :ui :send :token-symbol] token-symbol)
token-data (update-in [:wallet :ui :send]
@ -198,7 +231,8 @@
:token-display-name (:symbol token-data)
:token-symbol (:symbol token-data)))
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)
:always (assoc-in [:wallet :ui :send :tx-type] :tx/send))
: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.
@ -254,7 +288,12 @@
(rf/reg-event-fx :wallet/clean-selected-token
(fn [{:keys [db]}]
{:db (update-in db [:wallet :ui :send] dissoc :token :token-display-name :tx-type)}))
{:db (update-in db
[:wallet :ui :send]
dissoc
:token
:token-symbol :token-display-name
:tx-type :network)}))
(rf/reg-event-fx :wallet/clean-selected-collectible
(fn [{:keys [db]} [{:keys [ignore-entry-point?]}]]
@ -688,6 +727,7 @@
(fn [{db :db} [{:keys [address stack-id network-details network start-flow?] :as params}]]
(let [{:keys [token-symbol
tx-type]} (-> db :wallet :ui :send)
no-tx-type? (nil? tx-type)
collectible-tx? (send-utils/tx-type-collectible? tx-type)
token (when token-symbol
;; When this flow has started in the wallet home page, we
@ -720,7 +760,7 @@
network (assoc-in [:wallet :ui :send :network] network)
token-symbol (assoc-in [:wallet :ui :send :token] token)
bridge-tx? (assoc-in [:wallet :ui :send :to-address] address))
:fx (if (or (some? network) collectible-tx?)
:fx (if (or no-tx-type? (some? network) collectible-tx?)
[[:dispatch [:wallet/switch-current-viewing-account address]]
[:dispatch
[:wallet/wizard-navigate-forward

View File

@ -4,9 +4,9 @@
[quo.core :as quo]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[status-im.common.events-helper :as events-helper]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.contexts.wallet.collectible.utils :as collectible-utils]
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
[status-im.contexts.wallet.send.from.style :as style]
[status-im.setup.hot-reload :as hot-reload]
[utils.i18n :as i18n]
@ -14,12 +14,15 @@
[utils.re-frame :as rf]))
(defn- on-account-press
[address network-details collectible-tx?]
[address network-details general-flow? collectible-tx?]
(when general-flow?
(rf/dispatch [:wallet/clean-selected-token])
(rf/dispatch [:wallet/clean-selected-collectible]))
(rf/dispatch [:wallet/select-from-account
{:address address
:network-details network-details
:stack-id :screen/wallet.select-from
:start-flow? (not collectible-tx?)}]))
:start-flow? (not (or general-flow? collectible-tx?))}]))
(defn- on-close
[]
@ -27,40 +30,46 @@
(rf/dispatch [:wallet/clean-current-viewing-account]))
(defn- render-fn
[item _ _ {:keys [network-details collectible-tx? collectible]}]
[item _ _ {:keys [general-flow? network-details collectible-tx? collectible]}]
(let [account-address (:address item)
balance (if collectible-tx?
(collectible-utils/collectible-balance collectible account-address)
(string/replace-first (:asset-pay-balance item) "<" ""))
balance (cond
general-flow? 0
collectible-tx? (collectible-utils/collectible-balance collectible
account-address)
:else (string/replace-first (:asset-pay-balance item) "<" ""))
has-balance? (money/above-zero? balance)
asset-symbol (if collectible-tx? "" (:asset-pay-symbol item))
asset-value (if collectible-tx? (str balance) (:asset-pay-balance item))]
[quo/account-item
{:type (if has-balance? :tag :default)
:on-press #(on-account-press account-address network-details collectible-tx?)
:state (if has-balance? :default :disabled)
:token-props {:symbol asset-symbol
:value asset-value}
:on-press #(on-account-press account-address network-details general-flow? collectible-tx?)
:state (if (or has-balance? general-flow?) :default :disabled)
:token-props (when-not general-flow?
{:symbol asset-symbol
:value asset-value})
:account-props item}]))
(defn view
[]
(let [collectible-tx? (rf/sub [:wallet/send-tx-type-collectible?])
(let [general-flow? (rf/sub [:wallet/send-general-flow?])
collectible-tx? (rf/sub [:wallet/send-tx-type-collectible?])
token-symbol (rf/sub [:wallet/send-token-symbol])
token (rf/sub [:wallet/token-by-symbol-from-first-available-account-with-balance
token-symbol])
collectible (rf/sub [:wallet/wallet-send-collectible])
accounts (if collectible-tx?
accounts (if (or general-flow? collectible-tx?)
(rf/sub [:wallet/operable-accounts])
(rf/sub [:wallet/accounts-with-balances token]))
network-details (rf/sub [:wallet/network-details])]
(hot-reload/use-safe-unmount on-close)
[floating-button-page/view
{:footer-container-padding 0
:header [account-switcher/view
{:on-press #(rf/dispatch [:navigate-back])
:margin-top (safe-area/get-top)
:switcher-type :select-account}]}
:header [quo/page-nav
{:type :no-title
:icon-name :i/close
:on-press events-helper/navigate-back
:margin-top (safe-area/get-top)
:background :blur}]}
[quo/page-top
{:title (i18n/label :t/from-label)
:title-accessibility-label :title-label}]
@ -68,7 +77,8 @@
{:style style/accounts-list
:content-container-style style/accounts-list-container
:data accounts
:render-data {:network-details network-details
:render-data {:general-flow? general-flow?
:network-details network-details
:collectible-tx? collectible-tx?
:collectible collectible}
:render-fn render-fn

View File

@ -607,7 +607,8 @@
{:name :screen/wallet.select-asset
:metrics {:track? true
:alias-id :wallet-send.select-asset}
:options {:insets {:top? true}}
:options {:modalPresentationStyle :overCurrentContext
:insets {:top? true}}
:component wallet-select-asset/view}
{:name :screen/wallet.send-input-amount

View File

@ -246,6 +246,11 @@
(fn [tx-type]
(send-utils/tx-type-collectible? tx-type)))
(rf/reg-sub
:wallet/send-general-flow?
:<- [:wallet/wallet-send]
:-> :general-flow?)
(rf/reg-sub
:wallet/keypairs
:<- [:wallet]