-
Notifications
You must be signed in to change notification settings - Fork 984
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
Swap flows (launch from home / launch from account) #21269
Open
alwx
wants to merge
2
commits into
feature/20332-20333
Choose a base branch
from
feature/swap-flows
base: feature/20332-20333
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+121
−72
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,63 @@ | ||
(ns status-im.contexts.wallet.swap.utils | ||
(:require | ||
[status-im.contexts.wallet.common.utils :as utils] | ||
[status-im.contexts.wallet.common.utils.networks :as network-utils])) | ||
[status-im.contexts.wallet.common.utils :as utils] | ||
[status-im.contexts.wallet.common.utils.networks :as network-utils])) | ||
|
||
(defn select-asset-to-receive | ||
[wallet profile asset-to-pay] | ||
(let [wallet-address (get-in wallet [:current-viewing-account-address]) | ||
account (-> wallet | ||
:accounts | ||
vals | ||
(utils/get-account-by-address wallet-address)) | ||
test-networks-enabled? (get profile :test-networks-enabled?) | ||
networks (-> (get-in wallet | ||
[:wallet :networks (if test-networks-enabled? :test :prod)]) | ||
(network-utils/sorted-networks-with-details))] | ||
(defn- first-operable-account | ||
[accounts] | ||
(->> accounts | ||
vals | ||
(remove :watch-only?) | ||
(filter :operable?) | ||
(sort-by :position) | ||
first)) | ||
|
||
(defn wallet-account | ||
"Picks the account that's gonna be used for the swap operation. | ||
It's gonna be either the preselected account defined by | ||
`[:wallet :current-viewing-account-address]` in `db` | ||
or the first operable account." | ||
[wallet] | ||
(if-let [wallet-address (get wallet :current-viewing-account-address)] | ||
(-> wallet | ||
:accounts | ||
vals | ||
(utils/get-account-by-address wallet-address)) | ||
(-> wallet :accounts first-operable-account))) | ||
|
||
(defn select-asset-to-pay-by-symbol | ||
"Selects an asset to pay by token symbol. | ||
It's used for cases when only token symbol is available and the information | ||
about token needs to be extracted from the database. | ||
That happens when token is being selected on the home screen and | ||
it basically indicates that no account pre-selection was made." | ||
[{:keys [wallet account test-networks-enabled? token-symbol]}] | ||
(let [networks (-> (get-in wallet [:networks (if test-networks-enabled? :test :prod)]) | ||
(network-utils/sorted-networks-with-details)) | ||
token (->> account | ||
:tokens | ||
(filter #(= token-symbol (:symbol %))) | ||
first)] | ||
(assoc token :networks (network-utils/network-list token networks)))) | ||
|
||
(defn select-default-asset-to-receive | ||
"Selects an asset to receive if it was not provided explicitly. | ||
The principle of how the asset is being selected is simple: we get the | ||
whole list, remove the currently selected `asset-to-pay` from it, and choose | ||
the first one of what's left." | ||
[{:keys [wallet account test-networks-enabled? asset-to-pay]}] | ||
(let [networks (-> (get-in wallet [:networks (if test-networks-enabled? :test :prod)]) | ||
(network-utils/sorted-networks-with-details))] | ||
(->> (utils/tokens-with-balance (:tokens account) networks nil) | ||
(remove #(= (:symbol %) (:symbol asset-to-pay))) | ||
first))) | ||
|
||
(defn select-network | ||
"Chooses the network. | ||
Usually user needs to do the selection first and if the selection was done | ||
then the list of networks for the defined token will always contain | ||
one entry. Otherwise `nil` will be returned from here which will serve | ||
as an indicator that the network selector needs to be displayed." | ||
[{:keys [networks]}] | ||
(when (= (count networks) 1) | ||
(first networks))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing these changes may affect bridge and send flows navigation. Are you sure we want to remove them?
We should ask @status-im/mobile-qa team to verify we are not introducing regressions with these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not getting removed here, it's simply a small restructuring because some of the code is redundant.