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: no routes are found in case of valid amount in fiat is entered #20000

Merged
merged 1 commit into from
May 20, 2024

Conversation

briansztamfater
Copy link
Member

@briansztamfater briansztamfater commented May 13, 2024

fixes #18561
fixes #19999

Summary

This PR fixes a bug that makes no routes being fetched when the users switch the input mode to display values in fiat and a valid amount in fiat is entered. Also fixed some minor but noticeable bugs that appeared after fixing the main bug:

  • Visual overflow of the suffix text of the input when swapping mode to fiat and the number is too big. Needed to refactor a bit the views and styles of Token Input component.
  • Don't allow the user to use more decimals than the token supports.
  • Fiat character symbol was not showing in the conversion.
  • Fiat character symbol was not used when showing the max amount.
  • Many trailing zeroes issues when leading with large numbers.
  • Routes being fetched when swapping to fiat, and vise versa

Demo

fiatconversiondemo.mp4

Platforms

  • Android
  • iOS

Areas that maybe impacted

Functional
  • wallet / transactions

Steps to test

  • Open Status
  • Login
  • Go to wallet
  • Select an account
  • Tap on Send button
  • Select an asset where the user has funds on
  • Tap on switch button on the input to display values in fiat
  • Enter a valid amount in fiat
  • Wait for routes to be loaded
  • Verify correct behavior of input and routes loading

status: ready

@status-im-auto
Copy link
Member

status-im-auto commented May 13, 2024

Jenkins Builds

Click to see older builds (52)
Commit #️⃣ Finished (UTC) Duration Platform Result
b6ca301 #1 2024-05-13 15:52:20 ~2 min tests 📄log
2e74d98 #2 2024-05-13 15:54:55 ~2 min tests 📄log
✔️ 2e74d98 #2 2024-05-13 15:59:34 ~6 min android 🤖apk 📲
✔️ 2e74d98 #2 2024-05-13 16:00:07 ~7 min android-e2e 🤖apk 📲
✔️ 2e74d98 #2 2024-05-13 16:02:43 ~10 min ios 📱ipa 📲
1a6106e #3 2024-05-14 09:35:58 ~2 min tests 📄log
✔️ 1a6106e #3 2024-05-14 09:39:45 ~6 min android-e2e 🤖apk 📲
✔️ 1a6106e #3 2024-05-14 09:39:49 ~6 min android 🤖apk 📲
✔️ 1a6106e #3 2024-05-14 09:42:29 ~8 min ios 📱ipa 📲
f6f077c #4 2024-05-14 09:46:08 ~2 min tests 📄log
✔️ f6f077c #4 2024-05-14 09:49:26 ~5 min android-e2e 🤖apk 📲
✔️ f6f077c #4 2024-05-14 09:49:38 ~6 min android 🤖apk 📲
✔️ f6f077c #4 2024-05-14 09:52:18 ~8 min ios 📱ipa 📲
0bf1584 #5 2024-05-14 15:39:12 ~2 min tests 📄log
efcff9c #6 2024-05-14 15:42:43 ~2 min tests 📄log
✔️ efcff9c #6 2024-05-14 15:47:53 ~8 min android 🤖apk 📲
✔️ efcff9c #6 2024-05-14 15:47:55 ~8 min android-e2e 🤖apk 📲
✔️ efcff9c #6 2024-05-14 15:48:07 ~8 min ios 📱ipa 📲
✔️ 1d77b60 #7 2024-05-15 10:41:55 ~6 min android-e2e 🤖apk 📲
✔️ 1d77b60 #7 2024-05-15 10:41:57 ~6 min android 🤖apk 📲
✔️ 1d77b60 #7 2024-05-15 10:43:52 ~8 min ios 📱ipa 📲
✔️ 1d77b60 #8 2024-05-15 12:56:16 ~4 min tests 📄log
d7a73bd #9 2024-05-16 10:06:20 ~30 sec tests 📄log
✔️ d7a73bd #8 2024-05-16 10:12:43 ~6 min android-e2e 🤖apk 📲
✔️ d7a73bd #8 2024-05-16 10:12:47 ~6 min android 🤖apk 📲
✔️ d7a73bd #8 2024-05-16 10:14:23 ~8 min ios 📱ipa 📲
1b0a237 #10 2024-05-16 10:17:13 ~2 min tests 📄log
dc873bf #11 2024-05-16 10:22:06 ~30 sec tests 📄log
✔️ dc873bf #10 2024-05-16 10:27:27 ~5 min android 🤖apk 📲
✔️ dc873bf #10 2024-05-16 10:27:50 ~6 min android-e2e 🤖apk 📲
✔️ dc873bf #10 2024-05-16 10:31:08 ~9 min ios 📱ipa 📲
dc873bf #12 2024-05-16 10:48:10 ~30 sec tests 📄log
1acd275 #13 2024-05-16 14:03:44 ~1 min tests 📄log
bf1d1b9 #14 2024-05-16 14:06:37 ~2 min tests 📄log
✔️ bf1d1b9 #12 2024-05-16 14:10:04 ~6 min android 🤖apk 📲
✔️ bf1d1b9 #12 2024-05-16 14:10:51 ~6 min android-e2e 🤖apk 📲
✔️ bf1d1b9 #12 2024-05-16 14:13:03 ~8 min ios 📱ipa 📲
✔️ 08f7100 #15 2024-05-16 14:26:22 ~5 min tests 📄log
✔️ 08f7100 #13 2024-05-16 14:26:55 ~6 min android-e2e 🤖apk 📲
✔️ 08f7100 #13 2024-05-16 14:27:33 ~6 min android 🤖apk 📲
✔️ b994b96 #16 2024-05-16 14:34:29 ~4 min tests 📄log
✔️ b994b96 #14 2024-05-16 14:37:33 ~7 min android 🤖apk 📲
✔️ b994b96 #14 2024-05-16 14:37:44 ~7 min android-e2e 🤖apk 📲
✔️ b994b96 #14 2024-05-16 14:41:21 ~11 min ios 📱ipa 📲
✔️ 0a70a8f #17 2024-05-17 13:57:20 ~4 min tests 📄log
✔️ 0a70a8f #15 2024-05-17 13:59:20 ~6 min android 🤖apk 📲
✔️ 0a70a8f #15 2024-05-17 14:00:14 ~6 min android-e2e 🤖apk 📲
✔️ 0a70a8f #15 2024-05-17 14:04:43 ~11 min ios 📱ipa 📲
✔️ 882f7b7 #18 2024-05-20 08:34:45 ~4 min tests 📄log
✔️ 882f7b7 #16 2024-05-20 08:36:46 ~6 min android-e2e 🤖apk 📲
✔️ 882f7b7 #16 2024-05-20 08:37:38 ~6 min android 🤖apk 📲
✔️ 882f7b7 #16 2024-05-20 08:40:29 ~9 min ios 📱ipa 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ cbbb9e9 #19 2024-05-20 11:29:30 ~4 min tests 📄log
✔️ cbbb9e9 #17 2024-05-20 11:31:16 ~6 min android 🤖apk 📲
✔️ cbbb9e9 #17 2024-05-20 11:32:12 ~6 min android-e2e 🤖apk 📲
✔️ cbbb9e9 #17 2024-05-20 11:33:40 ~8 min ios 📱ipa 📲
✔️ 60151b5 #20 2024-05-20 13:00:42 ~4 min tests 📄log
✔️ 60151b5 #18 2024-05-20 13:02:34 ~5 min android-e2e 🤖apk 📲
✔️ 60151b5 #18 2024-05-20 13:02:51 ~6 min android 🤖apk 📲
✔️ 60151b5 #18 2024-05-20 13:05:35 ~8 min ios 📱ipa 📲

@briansztamfater briansztamfater force-pushed the fix/routes-fetch-fiat branch 2 times, most recently from 1a6106e to f6f077c Compare May 14, 2024 09:43
@briansztamfater briansztamfater changed the title [WIP] fix: no routes are found in case of valid amount in fiat is entered fix: no routes are found in case of valid amount in fiat is entered May 14, 2024
@briansztamfater briansztamfater marked this pull request as ready for review May 14, 2024 15:39
@@ -12,30 +12,22 @@
{:padding-horizontal 20
Copy link
Member

Choose a reason for hiding this comment

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

I am curious what are the styling changes for as I don't see ui-related problem in the issue description

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, the main issue doesn't specify UI bugs, but after fixing the main issue, some other issues started to be more noticeable. For instance:

  • Visual overflow of the suffix text of the input when swapping mode to fiat and the number is too big. Needed to refactor a bit the views and styles of Token Input component.
  • Don't allow the user to use more decimals than the token supports.
  • Fiat character symbol was not showing in the conversion.
  • Fiat character symbol was not used when showing the max amount.
  • Many trailing zeroes issues when leading with large numbers.
  • Routes being fetched when swapping to fiat, and vise versa

Added this in the description, will add some comments also to specify those changes.

@OmarBasem
Copy link
Member

Hey @briansztamfater, can you please review your code a little bit to explain are the other bugs being fixed?

Also would be good if you can add a video to PR description.

@J-Son89
Copy link
Member

J-Son89 commented May 15, 2024

🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 20000 pr's 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉

@@ -29,3 +30,13 @@
if `num` exceeds a given bound, then returns the bound exceeded."
[number lower-bound upper-bound]
(max lower-bound (min number upper-bound)))

(defn remove-trailing-zeroes
Copy link
Member

Choose a reason for hiding this comment

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

probably should add a test to cover this functionality? 🤔

is this really core "numbers" or is it more specific to the wallet also? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, this function was already in a common file for wallet, but moved to a utils as it is a general purpose function and needed to use it un token input component

Copy link
Member

Choose a reason for hiding this comment

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

Good point 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we have a focus on this function, maybe we can simplify the logic a bit?

(let [[integral fractional] (string/split (str num) #"\.")
      fractional-fixed      (some-> fractional
                              (string/replace #"0+$" ""))]
  (if fractional
    (str integral "." fractional-fixed)
    integral))

I think in this implementation is clearer what we do to the number 👀 wdyt?

(when (and active-screen?
(> (count token-available-networks-for-suggested-routes) 0)
(not lock-fetch-routes?))
(fetch-routes value valid-input? 2000)))
Copy link
Member

Choose a reason for hiding this comment

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

btw what is 2000 here? perhaps it's better to put this in a named var, or instead use a map for the arguments so it's obvious of the uses without looking at the function

Copy link
Member Author

Choose a reason for hiding this comment

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

It is an arbitrary time for debouncing-dispatch fetch routes event. Here #19100 we changed it to 2000, I can add it in a named var of course.

Copy link
Member

Choose a reason for hiding this comment

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

I think just a map for params explains it.

(fetch-routes {:value value 
                         :valid-input? valid-input?
                         :debounce-ms 2000})

Copy link
Member

Choose a reason for hiding this comment

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

I think this number 2000 is used in multiple places, we can refactor it to a constants file

@@ -92,36 +84,49 @@
(oops/oget "nativeEvent.selection")
(js->clj :keywordize-keys true)
(on-selection-change))))]
(fn [{:keys [token customization-color show-keyboard? crypto? currency value error? selection]
(fn [{:keys [token customization-color show-keyboard? crypto? currency value error? selection
handle-on-swap]
:or {show-keyboard? true}}]
Copy link
Member

Choose a reason for hiding this comment

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

it can be quite hard to distinguish what changes you have actually made in code blobs like this.
It would be nice if you could leave some comments to help find the changes :)

Copy link
Member Author

Choose a reason for hiding this comment

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

:placeholder-text-color (style/placeholder-text theme)
:auto-focus true
:ref set-ref
:placeholder "0"
Copy link
Member

Choose a reason for hiding this comment

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

is this placeholder correct? Probably should be an i81n label so it can be set.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is fine, the placeholder should be "0" in this case as this is the token amount input

@@ -513,3 +513,7 @@
(def ^:const community-joined-notification-type "communityJoined")

(def ^:const default-telemetry-server-url "https://telemetry.status.im")

(def currency-symbols
Copy link
Member

Choose a reason for hiding this comment

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

hmm, do we not already have currencies already defined somewhere? 🤔
I don't think we need to start adding this list. What exactly did you need it for?
cc @smohamedjavid

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm I found one in quo.foundations.common. Not sure if we should use it from status-im namespace?

Copy link
Member

Choose a reason for hiding this comment

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

This I'm not sure of, but we get the symbol from the sub I think, which comes from Status-Go.
I don't think we should add this map tbh, probably need to nuke the one in quo.foundations.common too

Copy link
Member

Choose a reason for hiding this comment

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

I think they were added temporarily. We need to fetch currencies data from status-go (probably settings team will work on that)

Copy link
Member

Choose a reason for hiding this comment

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

@briansztamfater @J-Son89

We use the existing list from legacy.status-im.utils.currency ns for currency list display and selection. But, it's needs to be fetched from status-go as @OmarBasem mentioned, to serve as a single point of truth for both Mobile and Desktop.

I believe those APIs are wallet_getCachedCurrencyFormats and wallet_fetchAllCurrencyFormats.

(probably settings team will work on that)

Not sure about that. 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up using :profile/currency-symbol and :profile/currency subs. No need for those maps from what I've seen, so I also removed quo.foundations.common file which only has that definition and was only used on Token Input.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you @briansztamfater

:right 0})
(defn input-container
[window-width]
{:width (- window-width 120)
Copy link
Member

Choose a reason for hiding this comment

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

what is 120 related to?

Copy link
Member Author

Choose a reason for hiding this comment

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

Token icon width + swap button width + spacing.

I will add a comment to make it more clear.

Copy link
Member

Choose a reason for hiding this comment

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

You can also just put 120 in a named def

Copy link
Member

Choose a reason for hiding this comment

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

What if we change the token icon width, the styling here will probably break. I think we need to have those 3 styles defined (and be used in the relevant components), and then the sum defined.

Or maybe there could be another approach without using that number here

Copy link
Member Author

Choose a reason for hiding this comment

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

There was a bug that makes a visual overflow of the suffix text of the input when swapping mode to fiat and the number is too big. So I refactored a bit this component to fix those issues.

(str (number/remove-trailing-zeroes
(.toFixed (/ num-value conversion) (or crypto-decimals 2)))
Copy link
Member Author

Choose a reason for hiding this comment

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

Numbers can be of 0.000100000, so need to remove trailing zeroes

Copy link
Member

Choose a reason for hiding this comment

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

a test maybe?

Copy link
Member

Choose a reason for hiding this comment

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

Would be good to add a test for the remove-trailing-zeroes util

Comment on lines +122 to +121
[button/button
{:icon true
:icon-only? true
:size 32
:on-press handle-on-swap
:type :outline
:accessibility-label :reorder}
:i/reorder]]))))
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved button to this view, not sure why it was outside of it, but refactored to fix token-label overflowing when the input is too large.

Comment on lines +31 to +35
(defn- make-limit-label-fiat
[amount currency-symbol]
(str currency-symbol amount))
Copy link
Member Author

Choose a reason for hiding this comment

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

Formatting for fiat was incorrect.

Previously it showed like: 100 EUR, now it should show like €100

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that depends on the language/region?

I've seen in some places in Europe they use 100 € and in USA and Mexico we use € 100.

So we might need to move this to translations

:on-swap #(reset! crypto-currency? %)
:value input-amount
:on-swap (fn [swap-to-crypto-currency?]
(set-just-toggled-mode? true)
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, when input value changes and the value is valid, routes are fetched. When swapping, the input value changes, the value is valid because it is still the same value in crypto, but routes should not be fetched.

This flag is used to prevent routes being fetched when swapping.

Comment on lines 157 to 161
amount (if @crypto-currency?
input-amount
(number/remove-trailing-zeroes
(.toFixed (/ input-amount conversion-rate)
crypto-decimals)))
Copy link
Member Author

Choose a reason for hiding this comment

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

Even if we are in "fiat mode", we need to calculate the equivalent in crypto token because it is what we are actually sending / bridging. Fiat values are just for visual representation.

Comment on lines 163 to 164
amount-text (str (.toFixed (js/parseFloat send-amount)
(min token-decimals 6))
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the amount string we show to the user. We cap the decimals to 6 to not overflow.

Comment on lines +219 to +280
(rn/use-effect
#(when input-error (debounce/clear-all))
[input-error])
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit out of scope, we can move it to another PR, but I think it is fine to leave it here as it includes many minor fixes for the input.

Let's say user wants to send SNT, the balance is 10 SNT.
Then the user starts typing "1", causing an event to fetch routes is debounced to dispatch in 2 seconds.
Then the user types another "1", now the input shows "11". But the user has only 10 SNT, so the input enters in an error state.
Because the first event was already in the dispatch queue, routes will be fetched with amount of "1" even if the user continued typing an invalid amount.

So, calling debounce/clear-all fixes that.

(set-input-state #(controlled-input/add-character % c))))
(let [new-text (str input-amount c)
max-decimals (if @crypto-currency? crypto-decimals 2)
regex-pattern (str "^\\d*\\.?\\d{0," max-decimals "}$")
Copy link
Member Author

Choose a reason for hiding this comment

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

When typing, we limit the input to allow decimals up to the decimals amount of the token or 2 if it is a fiat amount.

@briansztamfater
Copy link
Member Author

@J-Son89 @OmarBasem added more context all over the PR, also improved the description describing related issues that were fixed here and added a demo video

Copy link
Member

@J-Son89 J-Son89 left a comment

Choose a reason for hiding this comment

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

looks nice and smooth in the video ✨

Copy link
Member

@OmarBasem OmarBasem left a comment

Choose a reason for hiding this comment

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

@briansztamfater thanks for adding clarifications to your code. Left some comments 👍

:right 0})
(defn input-container
[window-width]
{:width (- window-width 120)
Copy link
Member

Choose a reason for hiding this comment

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

What if we change the token icon width, the styling here will probably break. I think we need to have those 3 styles defined (and be used in the relevant components), and then the sum defined.

Or maybe there could be another approach without using that number here

(str (number/remove-trailing-zeroes
(.toFixed (/ num-value conversion) (or crypto-decimals 2)))
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to add a test for the remove-trailing-zeroes util

Comment on lines +94 to +90
{:style {:width "100%"
:flex-direction :row}
Copy link
Member

Choose a reason for hiding this comment

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

Could be moved to style file

@@ -513,3 +513,7 @@
(def ^:const community-joined-notification-type "communityJoined")

(def ^:const default-telemetry-server-url "https://telemetry.status.im")

(def currency-symbols
Copy link
Member

Choose a reason for hiding this comment

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

I think they were added temporarily. We need to fetch currencies data from status-go (probably settings team will work on that)

Comment on lines 252 to 296
%
(let [value (controlled-input/input-value %)
Copy link
Member

Choose a reason for hiding this comment

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

This close usages of % can be confusing

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, better to give a name to that var.

@briansztamfater I prefer to follow the approach @ilmotta once shared with me: use the shorthand (#()) only when its a simple one liner function, otherwise prefer to use (fn []) because it's clearer what is received or even if it's empty it's clearer than looking for a % in the function.

(set-input-state #(controlled-input/add-character % c))))
(let [new-text (str input-amount c)
max-decimals (if @crypto-currency? crypto-decimals 2)
regex-pattern (str "^\\d*\\.?\\d{0," max-decimals "}$")
Copy link
Member

Choose a reason for hiding this comment

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

Probably better to refactor this regex pattern to constants file

(when (and active-screen?
(> (count token-available-networks-for-suggested-routes) 0)
(not lock-fetch-routes?))
(fetch-routes value valid-input? 2000)))
Copy link
Member

Choose a reason for hiding this comment

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

I think this number 2000 is used in multiple places, we can refactor it to a constants file

sender-network-values)
(not (nil? routes))
(not loading-suggested-routes?))
input-error (controlled-input/input-error input-state)]
Copy link
Member

@OmarBasem OmarBasem May 15, 2024

Choose a reason for hiding this comment

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

I mentioned this recently, but just to draw attention to how it keeps getting longer. We have subs, dispatch events, utils, and defined values mixed together. We need to put some thought into cleaning it up a bit @J-Son89 @ulisesmac

Copy link
Contributor

Choose a reason for hiding this comment

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

@OmarBasem
Sorry, I don't get it, do you mean that we have events, subs, utils and defs defined in the same file?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree there are lots of var definitions in this file, it is getting bigger and it deserves a refactor.
Not sure if we want to refactor now? Maybe it is too risky as it is a complex and core component for wallet, I would vote for refactor once we have a stable version so we can easily revert commits in case we break things while refactoring. But I am also open to listen to other opinions, no strong opinion on this tbh.

Copy link
Contributor

@ulisesmac ulisesmac left a comment

Choose a reason for hiding this comment

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

Hey @briansztamfater thanks for the PR and for addressing the bugs found!

The video and code look really good besides a couple of small comments.
💯
Maybe we want to ask QA to confirm the bugs have been properly solved

Comment on lines 64 to 66
(defn- token-label
[{:keys [theme value text]}]
[rn/view
{:style style/token-label-container
:pointer-events :none}
[rn/text-input
{:max-length 12
:style style/text-input-dimensions
:editable false
:placeholder "0"
:opacity 0
:value value}]
[token-name-text theme text]])
[{:keys [theme text]}]
[token-name-text theme text])
Copy link
Contributor

Choose a reason for hiding this comment

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

This component seems just like a wrapper for token-name-text do we need it? maybe we can use token-name-text directly?

@@ -29,3 +30,13 @@
if `num` exceeds a given bound, then returns the bound exceeded."
[number lower-bound upper-bound]
(max lower-bound (min number upper-bound)))

(defn remove-trailing-zeroes
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we have a focus on this function, maybe we can simplify the logic a bit?

(let [[integral fractional] (string/split (str num) #"\.")
      fractional-fixed      (some-> fractional
                              (string/replace #"0+$" ""))]
  (if fractional
    (str integral "." fractional-fixed)
    integral))

I think in this implementation is clearer what we do to the number 👀 wdyt?

@briansztamfater briansztamfater moved this from REVIEW to E2E Tests in Pipeline for QA May 16, 2024
@status-im-auto
Copy link
Member

87% of end-end tests have passed

Total executed tests: 52
Failed tests: 5
Expected to fail tests: 2
Passed tests: 45
IDs of failed tests: 727230,704615,727229,703391,702807 
IDs of expected to fail tests: 703495,703503 

Failed tests (5)

Click to expand
  • Rerun failed tests

  • Class TestWalletMultipleDevice:

    1. test_wallet_send_asset_from_drawer, id: 727230

    Device 1: Find `Text` by `xpath`: `//android.view.ViewGroup[@content-desc='container']/android.widget.TextView[@text='Ether']/../android.widget.TextView[3]`
    Device 1: `Text` is `0.49046 ETH`

    critical/test_wallet.py:129: in test_wallet_send_asset_from_drawer
        self._check_balances_after_tx(amount_to_send, sender_balance, receiver_balance, eth_amount_sender,
    critical/test_wallet.py:100: in _check_balances_after_tx
        self.errors.verify_no_errors()
    base_test_case.py:190: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Eth amount in the receivers wallet is 0.001 but should be 0.0011
    E    Eth amount in the senders wallet is 0.4905 but should be 0.4904
    



    2. test_wallet_send_eth, id: 727229

    Device 1: Find Text by xpath: //android.view.ViewGroup[@content-desc='container']/android.widget.TextView[@text='Ether']/../android.widget.TextView[3]
    Device 1: Text is 0.49046 ETH

    critical/test_wallet.py:114: in test_wallet_send_eth
        self._check_balances_after_tx(amount_to_send, sender_balance, receiver_balance, eth_amount_sender,
    critical/test_wallet.py:100: in _check_balances_after_tx
        self.errors.verify_no_errors()
    base_test_case.py:190: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Eth amount in the receivers wallet is 0.001 but should be 0.0011
    E    Eth amount in the senders wallet is 0.4905 but should be 0.4904
    



    Class TestCommunityMultipleDeviceMerged:

    1. test_community_edit_delete_message_when_offline, id: 704615

    Device 1: Looking for a message by text: text after edit
    Device 1: Looking for a message by text: message to delete

    critical/chats/test_public_chat_browsing.py:798: in test_community_edit_delete_message_when_offline
        self.errors.verify_no_errors()
    base_test_case.py:190: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Message 'message to delete' was not deleted for the receiver
    



    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_send_image_save_and_share, id: 703391

    Device 2: Find Button by accessibility id: image-0
    Device 2: Click system back button

    critical/chats/test_1_1_public_chats.py:458: in test_1_1_chat_send_image_save_and_share
        self.errors.verify_no_errors()
    base_test_case.py:190: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Message about saving a photo is not shown for sender.
    



    Device sessions

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_join_send_text_messages_push, id: 702807

    Device 2: Find Text by xpath: //*[starts-with(@text,'Hey, admin!')]/ancestor::android.view.ViewGroup[@content-desc='chat-item']//*[@content-desc='message-status']/android.widget.TextView
    Device 2: Text is Sent

    critical/chats/test_group_chat.py:95: in test_group_chat_join_send_text_messages_push
        self.chats[1].chat_element_by_text(message_to_admin).wait_for_status_to_be('Delivered', timeout=120)
    ../views/chat_view.py:225: in wait_for_status_to_be
        raise TimeoutException("Message status was not changed to %s, it's %s" % (expected_status, current_status))
     Message status was not changed to Delivered, it's Sent
    



    Device sessions

    Expected to fail tests (2)

    Click to expand

    Class TestCommunityOneDeviceMerged:

    1. test_community_discovery, id: 703503

    Test is not run, e2e blocker  
    

    [[reason: [NOTRUN] Curated communities not loading, https://github.com//issues/17852]]

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_mute_chat, id: 703495

    # STEP: Change device time so chat will be unmuted by timer
    Device 2: Long press on ChatElement

    critical/chats/test_group_chat.py:464: in test_group_chat_mute_chat
        self.errors.verify_no_errors()
    base_test_case.py:190: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Chat is still muted after timeout 
    

    [[Chat is not unmuted after expected time: https://github.com//issues/19627]]

    Device sessions

    Passed tests (45)

    Click to expand

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_pin_messages, id: 702732
    Device sessions

    2. test_group_chat_send_image_save_and_share, id: 703297
    Device sessions

    3. test_group_chat_reactions, id: 703202
    Device sessions

    4. test_group_chat_offline_pn, id: 702808
    Device sessions

    Class TestActivityCenterContactRequestMultipleDevicePR:

    1. test_add_contact_field_validation, id: 702777
    Device sessions

    2. test_activity_center_contact_request_accept_swipe_mark_all_as_read, id: 702851
    Device sessions

    3. test_activity_center_contact_request_decline, id: 702850
    Device sessions

    Class TestCommunityOneDeviceMerged:

    1. test_restore_multiaccount_with_waku_backup_remove_switch, id: 703133
    Device sessions

    2. test_community_copy_and_paste_message_in_chat_input, id: 702742
    Device sessions

    3. test_community_undo_delete_message, id: 702869
    Device sessions

    4. test_community_navigate_to_channel_when_relaunch, id: 702846
    Device sessions

    5. test_community_mute_community_and_channel, id: 703382
    Device sessions

    Class TestWalletOneDevice:

    1. test_wallet_add_remove_regular_account, id: 727231
    Device sessions

    2. test_wallet_add_remove_watch_only_account, id: 727232
    Device sessions

    Class TestCommunityMultipleDeviceMergedTwo:

    1. test_community_markdown_support, id: 702809
    Device sessions

    2. test_community_hashtag_links_to_community_channels, id: 702948
    Device sessions

    3. test_community_mentions_push_notification, id: 702786
    Device sessions

    4. test_community_leave, id: 702845
    Device sessions

    5. test_community_join_when_node_owner_offline, id: 703629
    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_several_images_send_reply, id: 703194
    Device sessions

    2. test_community_one_image_send_reply, id: 702859
    Device sessions

    3. test_community_emoji_send_copy_paste_reply, id: 702840
    Device sessions

    4. test_community_mark_all_messages_as_read, id: 703086
    Device sessions

    5. test_community_contact_block_unblock_offline, id: 702894
    Device sessions

    6. test_community_message_delete, id: 702839
    Device sessions

    7. test_community_message_send_check_timestamps_sender_username, id: 702838
    Device sessions

    8. test_community_links_with_previews_github_youtube_twitter_gif_send_enable, id: 702844
    Device sessions

    9. test_community_message_edit, id: 702843
    Device sessions

    10. test_community_unread_messages_badge, id: 702841
    Device sessions

    Class TestActivityMultipleDevicePRTwo:

    1. test_activity_center_mentions, id: 702957
    Device sessions

    2. test_activity_center_admin_notification_accept_swipe, id: 702958
    Device sessions

    Class TestActivityMultipleDevicePR:

    1. test_navigation_jump_to, id: 702936
    Device sessions

    2. test_activity_center_reply_read_unread_delete_filter_swipe, id: 702947
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_emoji_send_reply_and_open_link, id: 702782
    Device sessions

    2. test_1_1_chat_text_message_delete_push_disappear, id: 702733
    Device sessions

    3. test_1_1_chat_push_emoji, id: 702813
    Device sessions

    4. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745
    Device sessions

    5. test_1_1_chat_edit_message, id: 702855
    Device sessions

    6. test_1_1_chat_pin_messages, id: 702731
    Device sessions

    7. test_1_1_chat_message_reaction, id: 702730
    Device sessions

    Class TestDeepLinksOneDevice:

    1. test_links_open_universal_links_from_chat, id: 704613
    Device sessions

    2. test_links_deep_links, id: 702775
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUiTwo:

    1. test_1_1_chat_delete_via_long_press_relogin, id: 702784
    Device sessions

    2. test_1_1_chat_is_shown_message_sent_delivered_from_offline, id: 702783
    Device sessions

    3. test_1_1_chat_mute_chat, id: 703496
    Device sessions

    @yevh-berdnyk
    Copy link
    Contributor

    87% of end-end tests have passed

    e2e failures are not related to the PR

    @briansztamfater briansztamfater force-pushed the fix/routes-fetch-fiat branch 2 times, most recently from 08f7100 to b994b96 Compare May 16, 2024 14:29
    Comment on lines 152 to 251
    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)))
    input-num-value (controlled-input/numeric-value input-state)
    input-amount (controlled-input/input-value input-state)
    confirm-disabled? (or (nil? route)
    (empty? route)
    (string/blank? (controlled-input/input-value
    input-state))
    (<= input-num-value 0)
    (> input-num-value current-limit))
    amount (if @crypto-currency?
    input-amount
    (number/remove-trailing-zeroes
    (.toFixed (/ input-amount conversion-rate)
    crypto-decimals)))
    send-amount (rf/sub [:wallet/wallet-send-amount])
    amount-text (str (number/remove-trailing-zeroes
    (.toFixed (js/parseFloat send-amount)
    (min token-decimals 6)))
    " "
    token-symbol)
    first-route (first route)
    native-currency-symbol (when-not confirm-disabled?
    (get-in first-route
    [:from :native-currency-symbol]))
    native-token (when native-currency-symbol
    (rf/sub [:wallet/token-by-symbol
    native-currency-symbol]))
    fee-in-native-token (when-not confirm-disabled?
    (send-utils/calculate-full-route-gas-fee route))
    fee-in-crypto-formatted (when fee-in-native-token
    (utils/get-standard-crypto-format
    native-token
    fee-in-native-token))
    fee-in-fiat (when-not confirm-disabled?
    (utils/calculate-token-fiat-value
    {:currency fiat-currency
    :balance fee-in-native-token
    :token native-token}))
    fee-formatted (when fee-in-fiat
    (utils/get-standard-fiat-format
    fee-in-crypto-formatted
    currency-symbol
    fee-in-fiat))
    show-select-asset-sheet #(rf/dispatch
    [:show-bottom-sheet
    {:content (fn []
    [select-asset-bottom-sheet
    clear-input!])}])
    sender-network-values (rf/sub
    [:wallet/wallet-send-sender-network-values])
    receiver-network-values (rf/sub
    [:wallet/wallet-send-receiver-network-values])
    token-not-supported-in-receiver-networks? (every? #(= (:type %) :not-available)
    (filter #(not= (:type %) :add)
    receiver-network-values))
    suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
    routes (when suggested-routes
    (or (:best suggested-routes) []))
    no-routes-found? (and
    (every-network-value-is-zero?
    sender-network-values)
    (not (nil? routes))
    (not loading-routes?)
    (not token-not-supported-in-receiver-networks?))
    receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
    receiver-preferred-networks (rf/sub
    [:wallet/wallet-send-receiver-preferred-networks])
    receiver-preferred-networks-set (set receiver-preferred-networks)
    sending-to-unpreferred-networks? (not (every? (fn [receiver-selected-network]
    (contains?
    receiver-preferred-networks-set
    receiver-selected-network))
    receiver-networks))]
    suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
    routes (when suggested-routes
    (or (:best suggested-routes) []))
    no-routes-found? (and
    (every-network-value-is-zero?
    sender-network-values)
    (not (nil? routes))
    (not loading-routes?)
    (not token-not-supported-in-receiver-networks?))
    receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
    receiver-preferred-networks (rf/sub
    [:wallet/wallet-send-receiver-preferred-networks])
    receiver-preferred-networks-set (set receiver-preferred-networks)
    sending-to-unpreferred-networks? (not (every? (fn [receiver-selected-network]
    (contains?
    receiver-preferred-networks-set
    receiver-selected-network))
    receiver-networks))
    input-error (controlled-input/input-error input-state)]
    Copy link
    Member

    @OmarBasem OmarBasem May 16, 2024

    Choose a reason for hiding this comment

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

    @OmarBasem
    Sorry, I don't get it, do you mean that we have events, subs, utils and defs defined in the same file?

    @ulisesmac I mean this long list of definitions which is a mix of event, subs, utils, and values, could introduce bugs in the future and could be harder to debug. We need to have more separation of concerns here

    @pavloburykh
    Copy link
    Contributor

    Hey @briansztamfater! Thanks for the PR. I see that you have pushed recently some changes. Is that just rebasing or additional changes?

    @briansztamfater
    Copy link
    Member Author

    Hey @briansztamfater! Thanks for the PR. I see that you have pushed recently some changes. Is that just rebasing or additional changes?

    Hey @pavloburykh, just rebasing, PR can be tested

    @pavloburykh
    Copy link
    Contributor

    @briansztamfater thanks for the fixes. PR is ready for merge.

    @pavloburykh pavloburykh moved this from IN TESTING to MERGE in Pipeline for QA May 20, 2024
    Signed-off-by: Brian Sztamfater <brian@status.im>
    @briansztamfater briansztamfater merged commit d4e7e4c into develop May 20, 2024
    6 checks passed
    Pipeline for QA automation moved this from MERGE to DONE May 20, 2024
    @briansztamfater briansztamfater deleted the fix/routes-fetch-fiat branch May 20, 2024 13:08
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    Status: DONE
    8 participants