-
Notifications
You must be signed in to change notification settings - Fork 5k
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
refactor: connection Flow to use CAIP25 Permission format #29824
base: main
Are you sure you want to change the base?
Conversation
ui/components/multichain/pages/review-permissions-page/site-cell/site-cell.tsx
Outdated
Show resolved
Hide resolved
…n request is cancelled
…ons implementation to be fully caip25 compliant
5218ea4
to
f771a58
Compare
* @param hexChainIds - The list of permitted chains. | ||
* @returns The granted permissions with the target name of the {@link Caip25EndowmentPermissionName}. | ||
*/ | ||
export function parseCaip25PermissionsResponse( |
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.
[nit] - I think parse
maybe is a confusing word for this.
maybe just keep it pretty generic/straightforward:
export function parseCaip25PermissionsResponse( | |
export function getApprovedSessionsScopes( |
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.
resolved in ecad6ee
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. |
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.
LGTM
…allet_switchEthereumNetwork
…ding wallet_switchEthereumChain request
Builds ready [ae0bdb4]
Page Load Metrics (1747 ± 70 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [bfccd6e]
Page Load Metrics (1666 ± 78 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [80611dc]
Page Load Metrics (1643 ± 64 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
[Caip25EndowmentPermissionName]: ({ t, permissionValue }) => { | ||
const caveatValue = getRequestedSessionScopes({ | ||
permissions: permissionValue, | ||
}); | ||
const requestedAccounts = getEthAccounts(caveatValue); | ||
const isLegacySwitchChain = Boolean(!requestedAccounts.length); | ||
|
||
if (isLegacySwitchChain) { | ||
return { | ||
label: t('permission_walletSwitchEthereumChain'), | ||
leftIcon: IconName.Wifi, | ||
weight: PermissionWeight.permittedChains, | ||
}; | ||
} | ||
return { | ||
label: t('permission_ethereumAccounts'), | ||
leftIcon: IconName.Eye, | ||
weight: PermissionWeight.eth_accounts, | ||
}; | ||
}, |
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.
To make sure we render the proper UI on wallet_switchEthereumChain
request, we add an edge case.
Fortunately for us, this code is not triggered on:
{
"method": "wallet_requestPermissions",
"params": [
{
"eth_accounts": {
"caveats": [
{
"type": "restrictReturnedAccounts",
"value": []
}
]
},
"endowment:permitted-chains": {
"caveats": [
{
"type": "restrictNetworkSwitching",
"value": ["0x1"]
}
]
}
}
],
So we are safeguarded that the proper UI will render on every covered case (no UI changes after the refactor, all e2e tests make sure of that ✅ )
const lastPendingPermission = getLatestPendingPermissionFromOrigin( | ||
state, | ||
origin, | ||
); | ||
const isLegacySwitchEthChainRequest = | ||
lastPendingPermission?.method === 'wallet_switchEthereumChain'; | ||
|
||
const isRequestingAccounts = Boolean( | ||
permissionsRequest?.permissions?.[Caip25EndowmentPermissionName] && | ||
!isLegacySwitchEthChainRequest, | ||
); | ||
|
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.
Here I decided to check state object to get latest pending permission from current origin, so we can see the method to see if wallet_switchEthereumChain
was used to make the call.
This way, if it was used to make the call, we are sure isRequestingAccounts
(perhaps this variable name should be re-thinked...) is evaluated to false
.
So, downstream on ui/pages/permissions-connect/permissions-connect.component.js
we make sure to trigger
if (history.location.pathname === connectPath && !isRequestingAccounts) {
/* `isRequestingAccounts` is now false, so negating it becomes true and we enter the switch case */
switch (requestType) {
case 'wallet_installSnap':
history.replace(snapInstallPath);
break;
case 'wallet_updateSnap':
history.replace(snapUpdatePath);
break;
case 'wallet_installSnapResult':
history.replace(snapResultPath);
break;
case 'wallet_connectSnaps':
history.replace(snapsConnectPath);
break;
default:
history.replace(confirmPermissionPath); /* <---- We want the flow to come here to render the proper UI */
}
This seems to be a consistent way of making UI rendering behaviour stay the same after the refactor. But I'm open to discussion if you guys have a better approach to solving this problem.
For part of our collaboration with the Snaps team to enable Non EVM multichain API we are refactoring the connection flow UI.
The first step to enable this to modify what the connection confirmation UI components receive from the ApprovalController.
Currently they receive an object like this:
Basically the params for a
wallet_requestPermission
request.We want to change this so that instead they receive (and know how to interpret) a CAIP25 formatted request like:
Description
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Screen.Recording.2025-01-23.at.17.18.17.mov
NOTE: Don't mind different screens in the UI, this vid is outdated and all UI screens are same as
main
branchBefore
After
Pre-merge author checklist
Pre-merge reviewer checklist