Fix 10517 - Prevent tokens without addresses from being added to token list#10593
Fix 10517 - Prevent tokens without addresses from being added to token list#10593darkwing merged 2 commits intoMetaMask:developfrom
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
255bb08 to
4a36fd0
Compare
ui/app/ducks/swaps/swaps.js
Outdated
There was a problem hiding this comment.
This is necessary because the next two lines would allow const selectedToToken = {} to add a token, which we definitely don't want.
There was a problem hiding this comment.
This looks like a fine change to protect against errors. However, we should never be in a situation where there is no toTokenAddress. If so, requesting quotes should fail.
In the issue description, it was described how editing the code so that toTokenAddress is undefined results in the described bug, which occurs after confirming the swap. So it sounds like requesting quotes succeeded (otherwise there wouldn't be a quote to submit on the view quote screen).
So that leads me to believe that there is some other value that is being used for the token address in the request for quote. Or swapsTokens contains a token that has an undefined address.
const destinationTokenInfo =
swapsTokens?.find(({ address }) => address === toTokenAddress) ||
selectedToToken;
It would be good if we could verify exactly how the request for quotes succeeds when const selectedToToken = {} and what the address is in that case.
There was a problem hiding this comment.
We could remove the {} fallback from selectedFromToken and selectedToToken that existed from the initial swaps merge, and remove the toTokenAddress and fromTokenAddress checks in this PR.
If we should never get there without these properties, we should probably throw an error here, right?
There was a problem hiding this comment.
If we should never get there without these properties, we should probably throw an error here, right?
Right, but what I want to know is how was it possible to request quotes without these properties? Requesting quotes when from or two are empty strings or undefined would return 0 quotes.
There was a problem hiding this comment.
I think this can be addressed in another PR, as the change to actions.js handles the objectives of this PR.
7695da0 to
8e7acad
Compare
|
@danjm Since you have the most knowledge about the swaps codebase, could you take a look at this? |
|
To fully address #10593, should a change also be made on the 'Add Token' screen so that typing a single character does not result in an error state when there is a flawed token in the users data? |
Doesn't this PR prevent this circumstance? I don't quite understand what situation you're referring to. |
Right, but suppose such a token does somehow get added. The add token screen shouldn't error during typing right? I mean, add token functionality should continue to work regardless of what the data is like for already added tokens. |
I don't think we should expect UI to be tolerant of invalid state, no. Handling that everywhere would add a huge amount of complexity to our UI, and might obscure what the real expectations of the component are. |
30ec483 to
6a0cf31
Compare
app/scripts/migrations/054.js
Outdated
There was a problem hiding this comment.
This if is required because neither PreferencesController.tokens or PreferencesController. hiddenTokens exists in the migration data to this point.
There was a problem hiding this comment.
What do you mean by "neither PreferencesController.tokens or PreferencesController. hiddenTokens exists in the migration data to this point"? If they don't exist, is this forEach necessary? Will the code inside the if block ever run?
Perhaps you meant that it is possible for PreferencesController.tokens or PreferencesController.hiddenTokens to not exist at this point.
app/scripts/migrations/054.js
Outdated
There was a problem hiding this comment.
This if is required because neither PreferencesController. accountHiddenTokens or PreferencesController. accountTokens exists in the migration data to this point.
app/scripts/migrations/054.js
Outdated
There was a problem hiding this comment.
assetImages isn't in our migration data to this point.
|
@danjm One thing I notice is:
We should probably default to ETH, since that's what the home screen does. Maybe we do this in a separate PR? |
brad-decker
left a comment
There was a problem hiding this comment.
LGTM, though would like @danjm to revisit his comment and subsequent changes before merge.
danjm
left a comment
There was a problem hiding this comment.
I left a couple comments on the migration that should be addressed
054834f to
6084b75
Compare
brad-decker
left a comment
There was a problem hiding this comment.
changes LGTM @danjm can you give this another pass, please 🙏🏻
|
@darkwing you'll need to move your migration test into the migrations folder alongside 054.js, and then apply your changes to |
608bb0e to
3804b91
Compare
|
Rebased per @brad-decker's directives. I also removed a test that I had added, as since .... ... makes |
c6bf32e to
7ed2444
Compare
|
@Gudahtt @danjm @brad-decker Since this is my first migration, I'd love a deep dive on it, especially test data approval. |
brad-decker
left a comment
There was a problem hiding this comment.
I walked through and ran this test a few times, I only have one minor NIT. I think this is a fine migration and test/data set.
|
Good idea Brad, updated! I also added |
18c4538 to
66ca5ea
Compare
66ca5ea to
89c1e0d
Compare
|
In the interest of keeping migrations as tight as possible, I've removed checks on |
Fixes: #10517
Explanation:
ToDo:
addTokento prevent this from happening againui/app/ducks/swaps/swaps.jsto see if this is truly the place it's happening, and ifselectedFromTokenandselectedToTokenare the true culprits.