-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mobile snaps] Update snaps packages to version 2.0.2 (#7609)
## **Description** Update snaps controller to version 2.0.2. This also involved updating some of the peer dependancies such as `@metamask/slip44`, `@metamask/snaps-utils"`, `@metamask/rpc-methods`. Updated the snaps permissions titles to include the newer permissions. The list of permissions can be found [here](https://www.notion.so/bac3299d2c5241c599d2e5e7986e72f7?v=ef742a61bd844435b7171bd2e90b447e). This changed how snap are installed now... Before: - installing a snap would be would trigger a `wallet_installSnap` approval. From this point we would parse the approval request data to show the requested permissions. We would then handle the install state internally. Now: - Installing a a snap triggers a `wallet_requestPermissions` approval type. For this we show the `InstallSnapConnectionRequest`. Approving this triggers a second approval request of type `wallet_installSnap`. This is where we show the requested permissions inside the `InstallSnapPermissionsRequest`. Once approved we show a success/error screen Since the install logic relies so heavily on the the `useApprovalRequest` response, I moved all of the install logic from `app/components/UI/...` into `app/components/Approvals/InstallSnapApproval` ## **Related issues** Progresses: MetaMask/accounts-planning#116 Fixes: MetaMask/accounts-planning#115 Fixes: MetaMask/accounts-planning#114 ## **Manual testing steps** 1. build branch 2. run `yarn setup` 3. navigate to browser tab 4. go to http://metamask.github.io/snaps/test-snaps/1.1.0 5. install BIP-32 snap 6. go through approval flow 7. the snap should be installed 8. navigate to settings/snaps 9. the snap should be available in settings 10. you should be able to preview all of the snaps permissions in the snap settings ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> https://github.com/MetaMask/metamask-mobile/assets/22918444/317d7eca-c0b4-44d1-a60f-e6f1352331c3 ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've clearly explained what problem this PR is solving and how it is solved. - [ ] I've linked related issues - [ ] I've included manual testing steps - [ ] I've included screenshots/recordings if applicable - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). - [ ] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Frederik Bolding <[email protected]>
- Loading branch information
1 parent
2e82b71
commit 49cc2ec
Showing
45 changed files
with
885 additions
and
1,143 deletions.
There are no files selected for viewing
114 changes: 98 additions & 16 deletions
114
app/components/Approvals/InstallSnapApproval/InstallSnapApproval.tsx
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,31 +1,113 @@ | ||
import React, { useState } from 'react'; | ||
import { InstallSnapApprovalFlow } from '../../UI/InstallSnapApprovalFlow'; | ||
import React, { useEffect, useState } from 'react'; | ||
import ApprovalModal from '../ApprovalModal'; | ||
import useApprovalRequest from '../../hooks/useApprovalRequest'; | ||
import { ApprovalTypes } from '../../../core/RPCMethods/RPCMethodMiddleware'; | ||
import Logger from '../../../util/Logger'; | ||
import { SNAP_INSTALL_FLOW } from '../../../constants/test-ids'; | ||
import { SnapInstallState } from './InstallSnapApproval.types'; | ||
import { | ||
InstallSnapConnectionRequest, | ||
InstallSnapError, | ||
InstallSnapPermissionsRequest, | ||
InstallSnapSuccess, | ||
} from './components'; | ||
|
||
const InstallSnapApproval = () => { | ||
const [installState, setInstallState] = useState< | ||
SnapInstallState | undefined | ||
>(undefined); | ||
const [isFinished, setIsFinished] = useState<boolean>(false); | ||
const [installError, setInstallError] = useState<Error | undefined>( | ||
undefined, | ||
); | ||
const { approvalRequest, onConfirm, onReject } = useApprovalRequest(); | ||
|
||
useEffect(() => { | ||
if (approvalRequest) { | ||
if (approvalRequest.type === ApprovalTypes.REQUEST_PERMISSIONS) { | ||
setInstallState(SnapInstallState.Confirm); | ||
} else if ( | ||
approvalRequest.type === ApprovalTypes.INSTALL_SNAP && | ||
approvalRequest.requestState.permissions | ||
) { | ||
setInstallState(SnapInstallState.AcceptPermissions); | ||
} | ||
} else { | ||
setInstallState(undefined); | ||
} | ||
}, [approvalRequest]); | ||
|
||
const onInstallSnapFinished = () => { | ||
setIsFinished(true); | ||
}; | ||
|
||
const isModalVisible = | ||
approvalRequest?.type === ApprovalTypes.INSTALL_SNAP || | ||
(!isFinished && approvalRequest); | ||
|
||
return ( | ||
<ApprovalModal isVisible={isModalVisible} onCancel={onReject}> | ||
<InstallSnapApprovalFlow | ||
onCancel={onReject} | ||
onConfirm={onConfirm} | ||
onFinish={onInstallSnapFinished} | ||
requestData={approvalRequest} | ||
/> | ||
const onPermissionsConfirm = async () => { | ||
try { | ||
await onConfirm(undefined, { | ||
...approvalRequest.requestData, | ||
permissions: approvalRequest.requestState.permissions, | ||
}); | ||
setInstallState(SnapInstallState.SnapInstalled); | ||
} catch (error) { | ||
Logger.error( | ||
error as Error, | ||
`${SNAP_INSTALL_FLOW} Failed to install snap`, | ||
); | ||
setInstallError(error as Error); | ||
setInstallState(SnapInstallState.SnapInstallError); | ||
} | ||
}; | ||
|
||
if (!approvalRequest) return null; | ||
|
||
const renderModalContent = () => { | ||
switch (installState) { | ||
case SnapInstallState.Confirm: | ||
return ( | ||
<InstallSnapConnectionRequest | ||
approvalRequest={approvalRequest} | ||
onConfirm={onConfirm} | ||
onCancel={onReject} | ||
/> | ||
); | ||
case SnapInstallState.AcceptPermissions: | ||
return ( | ||
<InstallSnapPermissionsRequest | ||
approvalRequest={approvalRequest} | ||
onConfirm={onPermissionsConfirm} | ||
onCancel={onReject} | ||
/> | ||
); | ||
case SnapInstallState.SnapInstalled: | ||
return ( | ||
<InstallSnapSuccess | ||
approvalRequest={approvalRequest} | ||
onConfirm={onInstallSnapFinished} | ||
/> | ||
); | ||
case SnapInstallState.SnapInstallError: | ||
return ( | ||
<InstallSnapError | ||
approvalRequest={approvalRequest} | ||
onConfirm={onInstallSnapFinished} | ||
error={installError} | ||
/> | ||
); | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
const content = renderModalContent(); | ||
|
||
return content ? ( | ||
<ApprovalModal | ||
isVisible={installState !== undefined && !isFinished} | ||
onCancel={onReject} | ||
> | ||
{content} | ||
</ApprovalModal> | ||
); | ||
) : null; | ||
}; | ||
|
||
export default React.memo(InstallSnapApproval); | ||
export default InstallSnapApproval; |
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
Oops, something went wrong.