Skip to content

Commit

Permalink
upsert empty wallet:eip155 on add (#27845)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27845?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] 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-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
  • Loading branch information
jiexi authored Oct 14, 2024
1 parent f66a26b commit 10fb361
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 10 deletions.
82 changes: 82 additions & 0 deletions app/scripts/controllers/permissions/background-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ describe('permission background API methods', () => {
'eip155:1:0x4',
],
},
'wallet:eip155': {
methods: [],
notifications: [],
accounts: [
'wallet:eip155:0x2',
'wallet:eip155:0x3',
'wallet:eip155:0x1',
'wallet:eip155:0x4',
],
},
wallet: {
methods: [],
notifications: [],
accounts: [
'wallet:eip155:0x2',
'wallet:eip155:0x3',
'wallet:eip155:0x1',
'wallet:eip155:0x4',
],
},
},
isMultichainOrigin: true,
},
Expand Down Expand Up @@ -267,6 +287,28 @@ describe('permission background API methods', () => {
'eip155:1:0x5',
],
},
'wallet:eip155': {
methods: [],
notifications: [],
accounts: [
'wallet:eip155:0x2',
'wallet:eip155:0x3',
'wallet:eip155:0x1',
'wallet:eip155:0x4',
'wallet:eip155:0x5',
],
},
wallet: {
methods: [],
notifications: [],
accounts: [
'wallet:eip155:0x2',
'wallet:eip155:0x3',
'wallet:eip155:0x1',
'wallet:eip155:0x4',
'wallet:eip155:0x5',
],
},
},
isMultichainOrigin: true,
},
Expand Down Expand Up @@ -462,6 +504,16 @@ describe('permission background API methods', () => {
notifications: [],
accounts: ['eip155:1:0x3', 'eip155:1:0x1'],
},
'wallet:eip155': {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0x3', 'wallet:eip155:0x1'],
},
wallet: {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0x3', 'wallet:eip155:0x1'],
},
},
isMultichainOrigin: true,
},
Expand Down Expand Up @@ -549,6 +601,16 @@ describe('permission background API methods', () => {
notifications: KnownNotifications.eip155,
accounts: ['eip155:5:0xdeadbeef'],
},
'wallet:eip155': {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0xdeadbeef'],
},
wallet: {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0xdeadbeef'],
},
},
isMultichainOrigin: false,
},
Expand Down Expand Up @@ -670,6 +732,16 @@ describe('permission background API methods', () => {
notifications: KnownNotifications.eip155,
accounts: ['eip155:1337:0x1', 'eip155:1337:0x2'],
},
'wallet:eip155': {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0x1', 'wallet:eip155:0x2'],
},
wallet: {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0x1', 'wallet:eip155:0x2'],
},
},
isMultichainOrigin: true,
},
Expand Down Expand Up @@ -792,6 +864,16 @@ describe('permission background API methods', () => {
notifications: KnownNotifications.eip155,
accounts: ['eip155:5:0x1', 'eip155:5:0x2'],
},
'wallet:eip155': {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0x1', 'wallet:eip155:0x2'],
},
wallet: {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0x1', 'wallet:eip155:0x2'],
},
},
isMultichainOrigin: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ describe('CAIP-25 permittedChains adapters', () => {
notifications: [],
accounts: ['eip155:100:0x100'],
},
'wallet:eip155': {
methods: [],
notifications: [],
},
},
isMultichainOrigin: false,
},
Expand All @@ -94,6 +98,60 @@ describe('CAIP-25 permittedChains adapters', () => {
notifications: KnownNotifications.eip155,
accounts: [],
},
'wallet:eip155': {
methods: [],
notifications: [],
},
},
isMultichainOrigin: false,
});
});

it('adds an optional scope for "wallet:eip155" if it does not already exist in the optional scopes', () => {
const result = addPermittedEthChainId(
{
requiredScopes: {
'eip155:1': {
methods: [],
notifications: [],
accounts: ['eip155:1:0x1', 'eip155:1:0x2'],
},
},
optionalScopes: {
'eip155:100': {
methods: [],
notifications: [],
accounts: ['eip155:100:0x100'],
},
},
isMultichainOrigin: false,
},
'0x65',
);

expect(result).toStrictEqual({
requiredScopes: {
'eip155:1': {
methods: [],
notifications: [],
accounts: ['eip155:1:0x1', 'eip155:1:0x2'],
},
},
optionalScopes: {
'eip155:100': {
methods: [],
notifications: [],
accounts: ['eip155:100:0x100'],
},
'eip155:101': {
methods: KnownRpcMethods.eip155,
notifications: KnownNotifications.eip155,
accounts: [],
},
'wallet:eip155': {
methods: [],
notifications: [],
},
},
isMultichainOrigin: false,
});
Expand Down Expand Up @@ -277,6 +335,10 @@ describe('CAIP-25 permittedChains adapters', () => {
notifications: KnownNotifications.eip155,
accounts: [],
},
'wallet:eip155': {
methods: [],
notifications: [],
},
},
isMultichainOrigin: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export const addPermittedEthChainId = (
return {
...caip25CaveatValue,
optionalScopes: {
'wallet:eip155': {
methods: [],
notifications: [],
},
...caip25CaveatValue.optionalScopes,
[scopeString]: {
methods: KnownRpcMethods.eip155,
Expand Down
2 changes: 0 additions & 2 deletions app/scripts/lib/multichain-api/caip25permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
CaveatConstraint,
CaveatMutatorOperation,
PermissionType,
SubjectType,
} from '@metamask/permission-controller';
import { NonEmptyArray } from '@metamask/controller-utils';
import * as Scope from './scope';
Expand Down Expand Up @@ -46,7 +45,6 @@ describe('endowment:caip25', () => {
targetName: Caip25EndowmentPermissionName,
endowmentGetter: expect.any(Function),
allowedCaveats: [Caip25CaveatType],
subjectTypes: [SubjectType.Website],
validator: expect.any(Function),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,16 @@ describe('wallet_createSession', () => {
notifications: KnownNotifications.eip155,
accounts: ['eip155:1337:0x1', 'eip155:1337:0x2'],
},
'wallet:eip155': {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0x1', 'wallet:eip155:0x2'],
},
wallet: {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0x1', 'wallet:eip155:0x2'],
},
},
isMultichainOrigin: true,
},
Expand Down Expand Up @@ -608,6 +618,16 @@ describe('wallet_createSession', () => {
notifications: ['chainChanged'],
accounts: ['eip155:100:0x1', 'eip155:100:0x2'],
},
'wallet:eip155': {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0x1', 'wallet:eip155:0x2'],
},
wallet: {
methods: [],
notifications: [],
accounts: ['wallet:eip155:0x1', 'wallet:eip155:0x2'],
},
},
});
});
Expand Down
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4177,20 +4177,13 @@ __metadata:
languageName: node
linkType: hard

"@json-schema-tools/traverse@npm:^1.10.4":
"@json-schema-tools/traverse@npm:^1.10.4, @json-schema-tools/traverse@npm:^1.7.5, @json-schema-tools/traverse@npm:^1.7.8":
version: 1.10.4
resolution: "@json-schema-tools/traverse@npm:1.10.4"
checksum: 10/0027bc90df01c5eeee0833e722b7320b53be8b5ce3f4e0e4a6e45713a38e6f88f21aba31e3dd973093ef75cd21a40c07fe8f112da8f49a7919b1c0e44c904d20
languageName: node
linkType: hard

"@json-schema-tools/traverse@npm:^1.7.5, @json-schema-tools/traverse@npm:^1.7.8":
version: 1.10.3
resolution: "@json-schema-tools/traverse@npm:1.10.3"
checksum: 10/690623740d223ea373d8e561dad5c70bf86461bcedc5fc45da01c87bcdf3284bbdbad3006d4a423f8d82e4b2d4580e45f92c0b272f006024fb597d7f01876215
languageName: node
linkType: hard

"@juggle/resize-observer@npm:^3.3.1":
version: 3.4.0
resolution: "@juggle/resize-observer@npm:3.4.0"
Expand Down

0 comments on commit 10fb361

Please sign in to comment.