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 for "no routes found" on transaction confirmation page #19789

Merged
merged 3 commits into from
Apr 25, 2024
Merged
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
31 changes: 15 additions & 16 deletions src/status_im/contexts/wallet/send/input_amount/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@

route (rf/sub [:wallet/wallet-send-route])
to-address (rf/sub [:wallet/wallet-send-to-address])
nav-current-screen-id (rf/sub [:view-id])

on-confirm (or default-on-confirm handle-on-confirm)
crypto-decimals (or default-crypto-decimals
Expand All @@ -115,20 +114,19 @@
token
token-balance))
fiat-limit (.toFixed (* token-balance conversion-rate) 2)
current-limit #(if @crypto-currency? crypto-limit fiat-limit)
routes-can-be-fetched? (and (= nav-current-screen-id current-screen-id)
(not
(or (empty? (controlled-input/input-value input-state))
(<= (controlled-input/numeric-value input-state) 0)
(> (controlled-input/numeric-value input-state)
(current-limit)))))
current-limit (if @crypto-currency? crypto-limit fiat-limit)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Current limit is no longer a function because it don't need to be

valid-input? (not (or (string/blank? (controlled-input/input-value
input-state))
(<= (controlled-input/numeric-value input-state) 0)
(> (controlled-input/numeric-value input-state)
current-limit)))
current-currency (if @crypto-currency? token-symbol fiat-currency)
input-num-value (controlled-input/numeric-value input-state)
confirm-disabled? (or (nil? route)
(empty? route)
(empty? (controlled-input/input-value input-state))
(string/blank? (controlled-input/input-value input-state))
(<= input-num-value 0)
(> input-num-value (current-limit)))
(> input-num-value current-limit))
amount-text (str (controlled-input/input-value input-state)
" "
token-symbol)
Expand Down Expand Up @@ -167,8 +165,8 @@
#(.remove app-keyboard-listener))))
(rn/use-effect
(fn []
(set-input-state #(controlled-input/set-upper-limit % (current-limit))))
[@crypto-currency?])
(set-input-state #(controlled-input/set-upper-limit % current-limit)))
[current-limit])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now limit updated correctly.

[rn/view
{:style style/screen
:accessibility-label (str "container"
Expand All @@ -185,16 +183,17 @@
:error? (controlled-input/input-error input-state)
:networks (seq token-networks)
:title (i18n/label :t/send-limit
{:limit (make-limit-label (current-limit) current-currency)})
{:limit (make-limit-label current-limit current-currency)})
:conversion conversion-rate
:show-keyboard? false
:value (controlled-input/input-value input-state)
:on-swap #(reset! crypto-currency? %)
:on-token-press show-select-asset-sheet}]
[routes/view
{:token token
:input-value (controlled-input/input-value input-state)
:routes-can-be-fetched? routes-can-be-fetched?}]
{:token token
:input-value (controlled-input/input-value input-state)
:valid-input? valid-input?
:current-screen-id current-screen-id}]
(when (or loading-routes? (seq route))
[estimated-fees
{:loading-suggested-routes? loading-routes?
Expand Down
22 changes: 12 additions & 10 deletions src/status_im/contexts/wallet/send/routes/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,20 @@
:on-press-to-network on-press-to-network}]))

(defn fetch-routes
[amount routes-can-be-fetched? bounce-duration-ms]
(if routes-can-be-fetched?
[amount valid-input? bounce-duration-ms]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function was the cause of the problem. It was getting too generic condition routes-can-be-fetched? that was made from two logical conditions - if the valid is input and if we are still on the routes screen.
And when user navigated to confirmation page that condition became false which lead to clearing suggested routes.

Now in this function we rely only on input validity. And when the screen is wrong we dont't even call it.

(if valid-input?
(debounce/debounce-and-dispatch
[:wallet/get-suggested-routes {:amount amount}]
bounce-duration-ms)
(rf/dispatch [:wallet/clean-suggested-routes])))

(defn view
[{:keys [token theme input-value routes-can-be-fetched?
on-press-to-network]}]
[{:keys [token theme input-value valid-input?
on-press-to-network current-screen-id]}]

(let [token-symbol (:symbol token)
nav-current-screen-id (rf/sub [:view-id])
active-screen? (= nav-current-screen-id current-screen-id)
loading-suggested-routes? (rf/sub
[:wallet/wallet-send-loading-suggested-routes?])
from-values-by-chain (rf/sub
Expand Down Expand Up @@ -241,12 +243,12 @@
(not-empty routes))]

(rn/use-effect
#(when (> (count affordable-networks) 0)
(fetch-routes input-value routes-can-be-fetched? 2000))
[input-value routes-can-be-fetched?])
#(when (and active-screen? (> (count affordable-networks) 0))
(fetch-routes input-value valid-input? 2000))
[input-value valid-input?])
Copy link
Member

@briansztamfater briansztamfater Apr 24, 2024

Choose a reason for hiding this comment

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

Do we actually need to react to valid-input?? I think passing only input-value would be okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, theoretically we can remove it because we know that input validity depends only on input value. But that is kind of knowledge that we have outside of the component. If for some reason the validity rule will change, not having valid-input? as a dependency can cause an error

(rn/use-effect
#(when (> (count affordable-networks) 0)
(fetch-routes input-value routes-can-be-fetched? 0))
#(when (and active-screen? (> (count affordable-networks) 0))
(fetch-routes input-value valid-input? 0))
[disabled-from-chain-ids])
(if show-routes?
(let [initial-network-links-count (count network-links)
Expand Down Expand Up @@ -275,7 +277,7 @@
{:from-values-by-chain from-values-by-chain
:to-values-by-chain to-values-by-chain
:theme theme
:fetch-routes #(fetch-routes % routes-can-be-fetched? 2000)
:fetch-routes #(fetch-routes % valid-input? 2000)
:on-press-from-network (fn [chain-id _]
(let [disabled-chain-ids (if (contains? (set
disabled-from-chain-ids)
Expand Down