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

[FLASK] Fix an issue with installing and updating snaps with 0 permissions #15796

Merged
merged 10 commits into from
Sep 20, 2022

Conversation

FrederikBolding
Copy link
Member

Explanation

Fixes an issue with installing snaps that didn't request any permissions.

Manual Testing Steps

  1. Create a snap that requests 0 permissions
  2. Try to install the snap
  3. See that the install prompt shows correctly
  4. Verify that you can install a snap and reject installation of a snap

@metamaskbot
Copy link
Collaborator

Builds ready [05a0032]
Page Load Metrics (2173 ± 123 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1052445272500240
domContentLoaded174526982157263126
load174526982173255123
domInteractive174526972157263126

highlights:

storybook

@metamaskbot
Copy link
Collaborator

Builds ready [8a6c49e]
Page Load Metrics (2360 ± 99 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1202081592411
domContentLoaded211529972335208100
load21312998236020799
domInteractive211529972335208100

highlights:

storybook

@FrederikBolding FrederikBolding changed the title [FLASK] Fix an issue with installing snaps with 0 permissions [FLASK] Fix an issue with installing and updating snaps with 0 permissions Sep 16, 2022
@FrederikBolding FrederikBolding marked this pull request as ready for review September 16, 2022 08:53
@FrederikBolding FrederikBolding requested a review from a team as a code owner September 16, 2022 08:53
@metamaskbot
Copy link
Collaborator

Builds ready [783a654]
Page Load Metrics (1281 ± 43 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint841399225376181
domContentLoaded1139140012566732
load1139150312819043
domInteractive1139140012566732

highlights:

storybook

Copy link
Contributor

@hmalik88 hmalik88 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -0,0 +1,62 @@
diff --git a/node_modules/@metamask/snap-controllers/dist/snaps/SnapController.js b/node_modules/@metamask/snap-controllers/dist/snaps/SnapController.js
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why we're using a patch instead of latest snap-controllers version?

Copy link
Member Author

Choose a reason for hiding this comment

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

Its this fix applied: MetaMask/snaps#754

Will remove once we cut another release of skunkworks.

const revokedPermissions = request.unusedPermissions ?? {};
const newPermissions = request.newPermissions ?? {};
const hasPermissions =
Object.keys(approvedPermissions).length +
Copy link
Member

Choose a reason for hiding this comment

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

please add parentheses around arithmetic to avoid ambiguity.
(yes I know that + has higher precedence over >, but it makes the intentions clearer)

      (
      Object.keys(approvedPermissions).length +
      Object.keys(revokedPermissions).length +
      Object.keys(newPermissions).length
      ) > 0;

Copy link
Member Author

Choose a reason for hiding this comment

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

Not possible due to linting

rejectSnapInstall={(requestId) => {
rejectPendingApproval(
requestId,
serializeError(ethErrors.provider.userRejectedRequest()),
Copy link
Member

Choose a reason for hiding this comment

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

I feel iffy that we're serialising errors in the UI and using rpc errors in general.

export function getFirstSnapUpdateRequest(state) {
const requests = getSnapUpdateRequests(state);
export function getFirstSnapInstallOrUpdateRequest(state) {
const requests = getSnapInstallOrUpdateRequests(state);
Copy link
Member

Choose a reason for hiding this comment

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

return getSnapInstallOrUpdateRequests(state)?.[0] ?? null

@FrederikBolding FrederikBolding merged commit d054175 into develop Sep 20, 2022
@FrederikBolding FrederikBolding deleted the fb/fix-snap-install branch September 20, 2022 12:46
@FrederikBolding
Copy link
Member Author

@ritave Will improve this in the upcoming skunkworks PR. Merging this as is.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2022
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.

None yet

4 participants