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

Handle watch asset accept and reject using ApprovalController only #18829

Merged
merged 28 commits into from
Jun 5, 2023

Conversation

bergarces
Copy link
Contributor

@bergarces bergarces commented Apr 26, 2023

Explanation

  • Updates assets-controllers TokensController, which makes it so that only acceptance or rejection of the approval are triggered from the FE. It will no longer call TokensController.

Fixes https://github.com/MetaMask/MetaMask-planning/issues/463

Manual Testing Steps

  • Open Test Dapp
  • Access EIP 747 section
  • Try to add a new ERC20 token

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@github-actions
Copy link
Contributor

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.

@metamaskbot
Copy link
Collaborator

Builds ready [f5af643]
Page Load Metrics (1493 ± 37 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint86130107115
domContentLoaded1325158414716531
load1326161114937737
domInteractive1325158414716531
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -88 bytes
  • ui: -195 bytes
  • common: -1267 bytes

@metamaskbot
Copy link
Collaborator

Builds ready [8228ba3]
Page Load Metrics (1624 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint893501285326
domContentLoaded14581820161011555
load14761938162413665
domInteractive14581820161011555
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -304 bytes
  • ui: -195 bytes
  • common: -1739 bytes

res.result = true;
return end();
} catch (error) {
if (error.message === 'User rejected to watch the asset.') {
return end(ethErrors.provider.userRejectedRequest());
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 is no longer needed, since that's the error we are defining in the FE component for rejection.

@metamaskbot
Copy link
Collaborator

Builds ready [4de3dde]
Page Load Metrics (1571 ± 30 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint92133113105
domContentLoaded1446173515566732
load1465173615716330
domInteractive1446173515566732
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -304 bytes
  • ui: -204 bytes
  • common: -1947 bytes

@@ -13,7 +14,10 @@ import { getTokens } from '../../ducks/metamask/metamask';
import ZENDESK_URLS from '../../helpers/constants/zendesk-url';
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
import { getSuggestedAssets } from '../../selectors';
Copy link
Contributor

Choose a reason for hiding this comment

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

Presumably you'll have to repoint this selector since this state will be different as it no longer lives on the TokensController?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, we have a new selector that uses approvals filtered by type. It'll definitely need to be used here.

@metamaskbot
Copy link
Collaborator

Builds ready [7c3dac9]
Page Load Metrics (1575 ± 40 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint95136111115
domContentLoaded1374167315518340
load1449174915758440
domInteractive1374167315518340
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -304 bytes
  • ui: -128 bytes
  • common: -1686 bytes

@codecov
Copy link

codecov bot commented May 23, 2023

Codecov Report

Merging #18829 (ac3b5a6) into develop (1726fb3) will increase coverage by 0.04%.
The diff coverage is 90.00%.

@@             Coverage Diff             @@
##           develop   #18829      +/-   ##
===========================================
+ Coverage    69.94%   69.98%   +0.04%     
===========================================
  Files          959      959              
  Lines        36822    36790      -32     
  Branches      9455     9452       -3     
===========================================
- Hits         25753    25747       -6     
+ Misses       11069    11043      -26     
Impacted Files Coverage Δ
.../lib/rpc-method-middleware/handlers/watch-asset.js 37.50% <0.00%> (+1.14%) ⬆️
app/scripts/metamask-controller.js 68.69% <ø> (ø)
app/scripts/migrations/index.js 100.00% <ø> (ø)
ui/store/actions.ts 42.56% <ø> (+0.52%) ⬆️
...add-suggested-token/confirm-add-suggested-token.js 98.08% <100.00%> (+0.08%) ⬆️
ui/selectors/selectors.js 85.20% <100.00%> (-0.15%) ⬇️

@bergarces bergarces mentioned this pull request May 24, 2023
8 tasks
@bergarces bergarces changed the title Token approval promise refactor full Token approval promise refactor May 24, 2023
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added basic E2E tests for the wallet_watchAsset RPC method.

@bergarces bergarces force-pushed the token-approval-promise-refactor-full branch from 2affd0b to 6c006e6 Compare May 30, 2023 12:02
@bergarces bergarces marked this pull request as draft May 30, 2023 15:40
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes from this patch are already included in the new version.

@@ -504,7 +504,7 @@ export function getCurrentCurrency(state) {
export function getTotalUnapprovedCount(state) {
const { pendingApprovalCount = 0 } = state.metamask;

return pendingApprovalCount + getSuggestedAssetCount(state);
Copy link
Contributor Author

@bergarces bergarces May 30, 2023

Choose a reason for hiding this comment

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

suggested assets already were part of pending approvals from a previous PR, this can be removed.

@bergarces bergarces marked this pull request as ready for review May 31, 2023 10:53
@metamaskbot
Copy link
Collaborator

Builds ready [723a04c]
Page Load Metrics (1734 ± 67 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1011881322311
domContentLoaded15242002171913263
load15252002173413967
domInteractive15242002171813263
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -304 bytes
  • ui: -128 bytes
  • common: -1928 bytes

@metamaskbot
Copy link
Collaborator

Builds ready [d405b0f]
Page Load Metrics (1725 ± 54 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1052851343617
domContentLoaded1533187116929847
load15331902172511354
domInteractive1533187116929847
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -304 bytes
  • ui: -138 bytes
  • common: -1928 bytes

suggestedAssetID: string,
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
return async (dispatch: MetaMaskReduxDispatch) => {
dispatch(showLoadingIndication());
Copy link
Member

Choose a reason for hiding this comment

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

For slower connections, do we lose the loading indicator now?

If so, maybe it's worth looking at a separate ticket to add this into the resolvePendingApproval and rejectPendingApproval actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Up until now, resolving or rejecting an approval would happen very fast.

Now that we have the expectsResult option though, we should probably do what you suggest and add the loading indication for resolving actions.

@@ -289,7 +289,6 @@ function defaultFixture() {
allTokens: {},
detectedTokens: [],
ignoredTokens: [],
suggestedAssets: [],
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 I mentioned on the core PR also, but do we have a policy to remove old unused user data using migrations, or leave it to linger?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to ask in one of the dev channels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out a migration to get rid of the state in existing installations would be desirable in this case.

matthewwalsh0
matthewwalsh0 previously approved these changes Jun 1, 2023
@bergarces bergarces changed the title Token approval promise refactor Handle watch asset accept and reject using ApprovalController only Jun 1, 2023
@bergarces bergarces force-pushed the token-approval-promise-refactor-full branch from bb8d9df to 0fa00cc Compare June 5, 2023 10:23
Copy link
Contributor Author

@bergarces bergarces Jun 5, 2023

Choose a reason for hiding this comment

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

Added migration 087. Based on migration 085, which has a similar use case.

@metamaskbot
Copy link
Collaborator

Builds ready [ac3b5a6]
Page Load Metrics (1659 ± 58 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint101164128189
domContentLoaded1523188816409847
load15241931165912058
domInteractive1523188816409847
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 497 bytes
  • ui: -138 bytes
  • common: -1928 bytes

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Patches to TokensController (at least in terms of taking care of MetaMask/core#1261 and MetaMask/core#1268) look good.

@bergarces bergarces merged commit 5355000 into develop Jun 5, 2023
@bergarces bergarces deleted the token-approval-promise-refactor-full branch June 5, 2023 20:13
@github-actions github-actions bot locked and limited conversation to collaborators Jun 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants