Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet)_: Send flow from saved address and QR scanner #21899

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand All @@ -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]
Expand All @@ -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
Expand Down
41 changes: 40 additions & 1 deletion src/status_im/contexts/wallet/send/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,44 @@
(fn [{:keys [db]}]
{:db (update-in db [:wallet :ui :send] dissoc :amount)}))

(rf/reg-event-fx
:wallet/open-send-flow
(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-> db
(not multiple-accounts?)
(assoc-in [:wallet :current-viewing-account-address] default-account-address)

:always
(update-in
[:wallet :ui :send]
assoc
: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/init-send-flow-for-address
(fn [_ [args]]
{:fx [[:dispatch [:wallet/clean-send-data]]
[:dispatch [:wallet/open-send-flow args]]]}))
Comment on lines +151 to +155
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We clean the send data before user goes into the flow. This ensure no data from any other flows is left and also to prevent any bugs.


(rf/reg-event-fx
:wallet/select-send-address
(fn [{:keys [db]} [{:keys [address recipient stack-id start-flow?]}]]
Expand Down Expand Up @@ -688,6 +726,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
Expand Down Expand Up @@ -720,7 +759,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
Expand Down
43 changes: 25 additions & 18 deletions src/status_im/contexts/wallet/send/from/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,78 @@
[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]
[utils.money :as money]
[utils.re-frame :as rf]))

(defn- on-account-press
[address network-details collectible-tx?]
[address network-details no-tx-type? collectible-tx?]
(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 no-tx-type? collectible-tx?))}]))

(defn- on-close
[]
(rf/dispatch [:wallet/clean-selected-collectible {:ignore-entry-point? true}])
(rf/dispatch [:wallet/clean-current-viewing-account]))

(defn- render-fn
[item _ _ {:keys [network-details collectible-tx? collectible]}]
[item _ _ {:keys [no-tx-type? 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
no-tx-type? 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 no-tx-type? collectible-tx?)
:state (if (or has-balance? no-tx-type?) :default :disabled)
:token-props (when-not no-tx-type?
{:symbol asset-symbol
:value asset-value})
:account-props item}]))

(defn view
[]
(let [collectible-tx? (rf/sub [:wallet/send-tx-type-collectible?])
(let [no-tx-type? (nil? (rf/sub [:wallet/wallet-send-tx-type]))
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 no-tx-type? 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}]}
Comment on lines +64 to +69
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need account switcher on the from page

[quo/page-top
{:title (i18n/label :t/from-label)
:title-accessibility-label :title-label}]
[rn/flat-list
{:style style/accounts-list
:content-container-style style/accounts-list-container
:data accounts
:render-data {:network-details network-details
:render-data {:no-tx-type? no-tx-type?
:network-details network-details
:collectible-tx? collectible-tx?
:collectible collectible}
:render-fn render-fn
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/navigation/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,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
Expand Down