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)_: token supported networks #21451

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

smohamedjavid
Copy link
Member

@smohamedjavid smohamedjavid commented Oct 17, 2024

fixes #20988

Summary

This PR fixes the networks/chains supported by the token based on the token list fetched from status-go instead of relying on the balance-per-chain map as status-go returns balance for chains only if there is a positive balance.

Platforms

  • Android
  • iOS

Areas that may be impacted

Functional

  • wallet/transactions

Steps to test

Prerequisites: A wallet account with a token balance on one network
  • Open Status
  • Navigate to Wallet > Account > Bridge
  • Verify the supported networks by each token is displayed below each token
  • Upon selecting a token, verify the token supported networks are selectable even if there is no balance on that network/chain
  • Navigate to Wallet > Account > Send
  • Verify the tokens are displayed correctly with networks supported by the token
  • Navigate to the routes generation page and verify Not available text is not shown on the receiver side
  • Verify the transaction can be performed

status: ready

@smohamedjavid smohamedjavid self-assigned this Oct 17, 2024
@status-im-auto
Copy link
Member

status-im-auto commented Oct 17, 2024

Jenkins Builds

Click to see older builds (8)
Commit #️⃣ Finished (UTC) Duration Platform Result
015a233 #1 2024-10-17 12:13:53 ~3 min tests 📄log
✔️ 015a233 #1 2024-10-17 12:19:15 ~8 min android-e2e 🤖apk 📲
✔️ 015a233 #1 2024-10-17 12:19:48 ~9 min android 🤖apk 📲
✔️ 015a233 #1 2024-10-17 12:19:53 ~9 min ios 📱ipa 📲
✔️ f59d0c0 #2 2024-10-17 15:19:18 ~4 min tests 📄log
✔️ f59d0c0 #2 2024-10-17 15:23:15 ~8 min android-e2e 🤖apk 📲
✔️ f59d0c0 #2 2024-10-17 15:23:26 ~8 min ios 📱ipa 📲
✔️ f59d0c0 #2 2024-10-17 15:23:40 ~9 min android 🤖apk 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
f7dc535 #3 2024-10-18 18:50:23 ~3 min tests 📄log
✔️ f7dc535 #3 2024-10-18 18:54:20 ~7 min android 🤖apk 📲
✔️ f7dc535 #3 2024-10-18 18:55:15 ~8 min android-e2e 🤖apk 📲
✔️ f7dc535 #3 2024-10-18 18:56:27 ~9 min ios 📱ipa 📲
✔️ 86c4705 #4 2024-10-18 19:21:12 ~5 min tests 📄log
✔️ 86c4705 #4 2024-10-18 19:24:57 ~8 min ios 📱ipa 📲
✔️ 86c4705 #4 2024-10-18 19:25:00 ~9 min android-e2e 🤖apk 📲
✔️ 86c4705 #4 2024-10-18 19:26:50 ~10 min android 🤖apk 📲

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.

Hi @smohamedjavid thanks for you PR!

I added some minor comments related to the code.

Comment on lines 527 to 529
{:chain-id chain-id
:raw-balance (money/->bignumber 0)
:balance "0"})))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: since this map is constant, I'd create it outside of this reduce, in a let.

Comment on lines 65 to 71
[chain-ids networks]
(into #{}
(mapv (fn [chain-id]
(first (filter #(or (= (:chain-id %) chain-id)
(= (:related-chain-id %) chain-id))
networks)))
(keys balances-per-chain))))
chain-ids)))
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this code already existed, but there's a big room for improvement, for example: first + filter -> some and using the transducer syntax for into or just use (set) instead of (into #{})

@@ -390,18 +390,21 @@
receiver-networks disabled-from-chain-ids
from-locked-amounts bridge-to-chain-id]
:or {token updated-token}} (get-in db [:wallet :ui :send])
bridge-tx? (= tx-type :tx/bridge)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines 62 to 63
(let [networks (-> (get-in wallet [:networks (if test-networks-enabled? :test :prod)])
(network-utils/sorted-networks-with-details))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We are using -> for only one step:

(-> (get-in wallet [])
    (do-something)

Better to extract wallet, since threading macros of only one step do not have a big benefit:

(-> wallet
    (get-in [])
    (do-something)

(filter (fn [{:keys [networks]}]
(pos? (count networks))))
(remove #(when hide-token-fn (hide-token-fn constants/swap-tokens-my %))))
tokens (->>
Copy link
Contributor

Choose a reason for hiding this comment

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

the usual Clojure code style for ->> is putting the threaded var next to ->>:

;; Do:
(->> a
     (f)
     (g))
;; Don't:
(->> 
  a
  (f)
  (g))

Comment on lines 476 to 478
(filter (fn [{:keys [networks]}]
(pos? (count networks))))
(remove #(when hide-token-fn (hide-token-fn constants/swap-tokens-my %))))
Copy link
Contributor

Choose a reason for hiding this comment

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

We can save another iteration by joining this filter + remove into a single one. (actually we can even join the previous map by using keep, but it's highly probable that the readability will be worse).

Copy link
Member

@clauxx clauxx left a comment

Choose a reason for hiding this comment

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

hey @smohamedjavid, I noticed this PR adds changes in similar places as this one, just as an FYI.

Also, wondering if it's possible to isolate the changes in one place only, for instance: when we get the token data from status-go, can we update balances-per-chain to include the missing chains? I may be missing context here though, just wondering if the other changes are necessary.

@smohamedjavid
Copy link
Member Author

hey @smohamedjavid, I noticed this PR adds changes in similar places as this one, just as an FYI.

@clauxx - thanks for the heads up 👍 I guess I missed the context. I was under the impression that we need to display the supported networks below each token as we used to display (depending on the balance-per-chain key). I guess I will change it. Please merge your PR and I will make changes on top of it.

Also, wondering if it's possible to isolate the changes in one place only, for instance: when we get the token data from status-go, can we update balances-per-chain to include the missing chains? I may be missing context here though, just wondering if the other changes are necessary.

That was my first thought too. I was under the impression that the status-go returns the balance even if it's zero in supported chains for all tokens, but it's different for non-default tokens (ETH SNT STT DAI are default tokens). I was inclined to status-go, but I don't want to introduce any bugs close to release.

I will quickly add the missing chain while we save it to the app-db. I need to ensure the token list (as we depend on it for supported chains for each token) is fetched before we fetch the tokens for each account so that we can add any missing chains in balance-per-chain. I will make a quick update.

@@ -494,10 +494,12 @@
(sort-by (juxt :symbol priority) tokens)))

(defn tokens-with-balance
[tokens networks chain-ids]
[tokens networks token-supported-chains chain-ids]
Copy link
Contributor

@vkjr vkjr Oct 18, 2024

Choose a reason for hiding this comment

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

When I read name token-supported-chains my brain splits it like "[token-supported] [chains]" which is quite confusing because I can't figure out what are chains that are supported by tokens :)
I'd suggest to rename all similar variables, keywords and functions (17 entries) to make them easier to understand:
'token-supported-chains' -> 'chains-supported-by-token'
'token-supported-chains-by-symbol' -> 'supported-chains-by-token-symbol'
Wdyt?

@smohamedjavid smohamedjavid reopened this Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: CONTRIBUTOR
Development

Successfully merging this pull request may close these issues.

Bridging of assets is blocked unless user has a positive balance of this asset ("Network is not available")
5 participants