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

feat: Editing flow #26635

Merged
merged 160 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 123 commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
4e2ceac
added networks screen modal
NidhiKJha Jul 24, 2024
5d1adc4
added test and checkbo
NidhiKJha Jul 29, 2024
ec54d0b
lint fix
NidhiKJha Jul 29, 2024
62fc967
lint fix
NidhiKJha Jul 30, 2024
cfe64f4
updated snapshot
NidhiKJha Jul 30, 2024
2a038a8
updated jest
NidhiKJha Jul 30, 2024
46d3441
updated tests
NidhiKJha Jul 30, 2024
6b4486c
lint fix
NidhiKJha Jul 31, 2024
1d3180b
added edit accounts modal
NidhiKJha Aug 14, 2024
1fde970
added toast for permission switch
NidhiKJha Aug 14, 2024
0f9b049
added review perm page
NidhiKJha Aug 21, 2024
e0d2bce
added review permission page
NidhiKJha Aug 22, 2024
f60df8f
editing flow
NidhiKJha Aug 23, 2024
b6cc4d9
updated selector
NidhiKJha Aug 23, 2024
a295937
fix
adonesky1 Aug 23, 2024
c7f4507
permitted chains and accounts updated for review screen
NidhiKJha Aug 25, 2024
ecdf8a5
removed unused console
NidhiKJha Aug 25, 2024
6c81230
added edit accounts functionality
NidhiKJha Aug 26, 2024
43eb0dc
updated toast
NidhiKJha Aug 26, 2024
d2da713
added no connection page
NidhiKJha Aug 26, 2024
5e0cacf
added edit networks functionality
NidhiKJha Aug 28, 2024
aa4c368
fix
adonesky1 Aug 28, 2024
5ce582a
removed console statements
NidhiKJha Sep 3, 2024
acaddf8
updated final screen for editing flow
NidhiKJha Sep 4, 2024
1b44b21
updated controllers
NidhiKJha Sep 4, 2024
27bf622
updated edit networks
NidhiKJha Sep 4, 2024
676c90c
lint fix
NidhiKJha Sep 4, 2024
a590b91
lint fix
NidhiKJha Sep 4, 2024
388ae6a
prep build fix
NidhiKJha Sep 4, 2024
855bee2
lint fix
NidhiKJha Sep 4, 2024
f4c7ef9
feat: Connections flow (#26922)
NidhiKJha Sep 11, 2024
9fcb6e7
Merge branch 'develop' into editing-flow
NidhiKJha Sep 11, 2024
35f675e
lint fix
NidhiKJha Sep 11, 2024
5ef36cb
lint fix
NidhiKJha Sep 11, 2024
bc50ba1
error fix
NidhiKJha Sep 12, 2024
1338574
updated permissions
NidhiKJha Sep 12, 2024
7bee52a
jest update
NidhiKJha Sep 12, 2024
58c11e4
lint fix
NidhiKJha Sep 12, 2024
0654541
updated lint errors
NidhiKJha Sep 12, 2024
0dab618
lint fix
NidhiKJha Sep 12, 2024
216f1c3
lint fix
NidhiKJha Sep 12, 2024
36c5c31
updated controller
NidhiKJha Sep 12, 2024
a99826f
Merge branch 'develop' into editing-flow
NidhiKJha Sep 12, 2024
be9e6a5
updated syntax
NidhiKJha Sep 12, 2024
2a3ab14
updated stories
NidhiKJha Sep 12, 2024
8e8fc4f
lint fix
NidhiKJha Sep 12, 2024
9017c11
Fix requestPermissionsForOrigin
jiexi Sep 12, 2024
47a89c7
Merge remote-tracking branch 'origin/editing-flow' into editing-flow
jiexi Sep 12, 2024
067bd1c
only request permittedChains when feature flag and eth_accounts is re…
jiexi Sep 13, 2024
9fc03e9
remove approvedChainIds from legacy permission page submit
jiexi Sep 13, 2024
50c1163
Merge branch 'develop' into editing-flow
jiexi Sep 16, 2024
cba4d48
Merge branch 'develop' into editing-flow
jiexi Sep 16, 2024
3b224f1
Jl/editing flow fix incremental (#27181)
jiexi Sep 16, 2024
5ef45cc
updated edit accounts modal story
NidhiKJha Sep 17, 2024
f120d34
lint fix
NidhiKJha Sep 17, 2024
753c28d
Fix wallet_addEthereumChain handler test
jiexi Sep 17, 2024
f9f8c30
Merge branch 'develop' into editing-flow
jiexi Sep 17, 2024
f945e28
updated changes
NidhiKJha Sep 17, 2024
83789f4
lint fix
NidhiKJha Sep 17, 2024
8c6615f
Jl/editing flow network client switch (#27225)
jiexi Sep 17, 2024
baa58c8
Merge branch 'develop' into editing-flow
NidhiKJha Sep 17, 2024
dab66ec
fixed ts errors
NidhiKJha Sep 17, 2024
ee2fe20
Fix permissions/selectors
jiexi Sep 17, 2024
31edcdf
fixed ts errors
NidhiKJha Sep 18, 2024
36a8b53
Merge branch 'develop' into editing-flow
NidhiKJha Sep 18, 2024
77e5fb5
Merge branch 'develop' into editing-flow
NidhiKJha Sep 18, 2024
ee59fc8
lint fix
NidhiKJha Sep 18, 2024
4e08e8d
Fix sonar cloud default assignment warning
jiexi Sep 18, 2024
bf7eba4
remove infura key
jiexi Sep 18, 2024
a3bc08c
Merge branch 'develop' into editing-flow
jiexi Sep 18, 2024
c11b4f7
Merge branch 'develop' into editing-flow
jiexi Sep 18, 2024
db2d3d1
update data-testid tags
jiexi Sep 18, 2024
9f55140
Merge branch 'develop' into editing-flow
jiexi Sep 18, 2024
f2495d6
Deal with code dupe
jiexi Sep 18, 2024
19d8b78
Merge branch 'develop' into editing-flow
jiexi Sep 18, 2024
72bf769
Merge branch 'develop' into editing-flow
NidhiKJha Sep 18, 2024
5aaafd5
removed yarn change
NidhiKJha Sep 18, 2024
27b6904
updated url Params
NidhiKJha Sep 18, 2024
f02ce6b
updated url Params
NidhiKJha Sep 18, 2024
3868d34
nit fix
NidhiKJha Sep 18, 2024
be170f8
updated for test nets
NidhiKJha Sep 18, 2024
024597d
rename getChangedOrigins to diffMap
jiexi Sep 18, 2024
144dea4
Merge remote-tracking branch 'origin/editing-flow' into editing-flow
jiexi Sep 18, 2024
0dc84aa
permission-page-container named vars
jiexi Sep 18, 2024
7a1e426
lint
jiexi Sep 18, 2024
9238525
reduce type casts
jiexi Sep 18, 2024
8984bab
Merge branch 'develop' into editing-flow
jiexi Sep 18, 2024
d065a0c
cleanup checked isIndeterminate assignment
jiexi Sep 18, 2024
fdeb285
updated permissions page
NidhiKJha Sep 19, 2024
38bdbcc
swap !checked condition order
jiexi Sep 19, 2024
62f749b
Merge remote-tracking branch 'origin/editing-flow' into editing-flow
jiexi Sep 19, 2024
4fb591d
Merge branch 'develop' into editing-flow
jiexi Sep 19, 2024
6253029
lint fix
NidhiKJha Sep 19, 2024
178ba33
Fix approvedAccounts selection in connection flow
jiexi Sep 19, 2024
428d3ac
Merge remote-tracking branch 'origin/editing-flow' into editing-flow
jiexi Sep 19, 2024
5eff06e
Merge branch 'develop' into editing-flow
jiexi Sep 19, 2024
607a63e
add SiteCellConnectionListItem
jiexi Sep 19, 2024
6568ee0
Merge branch 'develop' into editing-flow
NidhiKJha Sep 19, 2024
cb03172
Add PermissionsHeader
jiexi Sep 19, 2024
d250465
Merge remote-tracking branch 'origin/editing-flow' into editing-flow
jiexi Sep 19, 2024
413d85a
Fix missingi mports
jiexi Sep 19, 2024
fe9fee4
updated connect page
NidhiKJha Sep 19, 2024
3329bcd
Merge branch 'develop' into editing-flow
jiexi Sep 20, 2024
e4b1a25
Jl/editing flow refactor (#27309)
jiexi Sep 23, 2024
3ccc81a
story fix site cell
NidhiKJha Sep 23, 2024
b9b9a8f
fixed story for accounts
NidhiKJha Sep 23, 2024
a9f44fe
fixed test for edit networks
NidhiKJha Sep 23, 2024
b08fb0e
updated lint fix
NidhiKJha Sep 23, 2024
99f6eaf
Merge branch 'develop' into editing-flow
NidhiKJha Sep 23, 2024
28cb681
updated copy for disconnect modal
NidhiKJha Sep 23, 2024
dffa90e
lint fix
NidhiKJha Sep 23, 2024
3899ac6
Lint
jiexi Sep 23, 2024
2ecf6eb
Merge branch 'develop' into editing-flow
jiexi Sep 23, 2024
ff51b36
Shallow review-permissions-page connect-page snapshot test
jiexi Sep 23, 2024
3833009
Rename Request type. lint
jiexi Sep 23, 2024
b30adc7
Merge branch 'develop' into editing-flow
jiexi Sep 23, 2024
9bf45ee
Shallow EditNetworksModal test
jiexi Sep 23, 2024
a022cf8
add actions specs
jiexi Sep 23, 2024
27f4345
lint
jiexi Sep 23, 2024
aff9dd3
Switch actions.test.js back to sinon
jiexi Sep 23, 2024
9e89e4e
Merge branch 'develop' into editing-flow
jiexi Sep 23, 2024
dfd85ad
add background-api spec
jiexi Sep 23, 2024
e236efd
update background-api test requestAccountsAndChainPermissionsWithId
jiexi Sep 23, 2024
171d52e
Add edit modal scenarios
jiexi Sep 23, 2024
17ee102
Merge branch 'develop' into editing-flow
NidhiKJha Sep 24, 2024
c709725
lint fix
NidhiKJha Sep 24, 2024
62d6bc7
lint fix
NidhiKJha Sep 24, 2024
0d1f0a7
updated test for site cell
NidhiKJha Sep 24, 2024
0df6988
updated test
NidhiKJha Sep 24, 2024
6c2fe5e
updated test and fixed prep dep
NidhiKJha Sep 24, 2024
113e848
lintfix
NidhiKJha Sep 24, 2024
0c926b0
Fix restricted import in actions test
jiexi Sep 24, 2024
0c0b6c5
add EndowmentTypes to shared constants
jiexi Sep 24, 2024
d4dd5ba
Fix actions
jiexi Sep 24, 2024
304e70f
Merge branch 'develop' into editing-flow
jiexi Sep 24, 2024
534796b
Remove infura key
jiexi Sep 24, 2024
5526dd7
Merge branch 'develop' into editing-flow
jiexi Sep 24, 2024
68ab18a
Fix wrong return type in actions
jiexi Sep 24, 2024
9f15dad
rename addMorePermittedChains
jiexi Sep 24, 2024
6e33afb
Fix review permissions permitted chains
jiexi Sep 24, 2024
e0ee102
Fix background-api test
jiexi Sep 24, 2024
c686dd9
Fix action return types
jiexi Sep 24, 2024
4bdf4bc
added logo to review page
NidhiKJha Sep 25, 2024
84d1c48
removed unnecessary type
NidhiKJha Sep 25, 2024
9b8a484
nit fix
NidhiKJha Sep 25, 2024
35c81db
lint fix
NidhiKJha Sep 25, 2024
76808f6
reverted change for connections
NidhiKJha Sep 25, 2024
0342f15
updated site cell
NidhiKJha Sep 25, 2024
1bc9e0f
fix typo in actions
jiexi Sep 25, 2024
3bbcb3d
Merge remote-tracking branch 'origin/editing-flow' into editing-flow
jiexi Sep 25, 2024
b4395ad
Merge branch 'develop' into editing-flow
jiexi Sep 25, 2024
1b853f4
updated test
NidhiKJha Sep 25, 2024
bb51d59
updated test
NidhiKJha Sep 25, 2024
c67c60f
Fix action grantPermittedChain specs
jiexi Sep 25, 2024
ab5b004
Merge remote-tracking branch 'origin/editing-flow' into editing-flow
jiexi Sep 25, 2024
2e955c5
Merge branch 'develop' into editing-flow
jiexi Sep 25, 2024
84159e5
do not grant permitted changes on network switch if origin does not h…
jiexi Sep 25, 2024
e69d0f7
fix permitted chain toast being shown when network is switched to an …
jiexi Sep 25, 2024
5fadd78
Use showPermittedNetworkToastOpen in ReviewPermissions page to trigge…
jiexi Sep 25, 2024
2429f51
Merge branch 'develop' into editing-flow
NidhiKJha Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 44 additions & 2 deletions app/scripts/controllers/permissions/background-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
CaveatTypes,
RestrictedMethods,
} from '../../../../shared/constants/permissions';
import { CaveatFactories } from './specifications';
import { CaveatFactories, PermissionNames } from './specifications';

export function getPermissionBackgroundApiMethods(permissionController) {
const addMoreAccounts = (origin, accountOrAccounts) => {
Expand All @@ -26,7 +26,6 @@ export function getPermissionBackgroundApiMethods(permissionController) {
// To add more than one account when already connected to the dapp
addMorePermittedAccounts: (origin, accounts) =>
addMoreAccounts(origin, accounts),

removePermittedAccount: (origin, account) => {
const { value: existingAccounts } = permissionController.getCaveat(
origin,
Expand Down Expand Up @@ -57,6 +56,49 @@ export function getPermissionBackgroundApiMethods(permissionController) {
}
},

removePermittedChain: (origin, chain) => {
const { value: existingChains } = permissionController.getCaveat(
origin,
RestrictedMethods.permittedChains,
CaveatTypes.restrictNetworkSwitching,
);

const remainingChains = existingChains.filter(
(existingChain) => existingChain !== chain,
);

if (remainingChains.length === existingChains.length) {
return;
}

if (remainingChains.length === 0) {
permissionController.revokePermission(
origin,
RestrictedMethods.permittedChains,
);
} else {
permissionController.updateCaveat(
origin,
RestrictedMethods.permittedChains,
CaveatTypes.restrictNetworkSwitching,
remainingChains,
);
}
},

requestAccountsAndChainPermissionsWithId: async (origin) => {
const id = nanoid();
permissionController.requestPermissions(
{ origin },
{
[PermissionNames.eth_accounts]: {},
[PermissionNames.permittedChains]: {},
},
{ id },
);
return id;
},

requestAccountsPermissionWithId: async (origin) => {
const id = nanoid();
permissionController.requestPermissions(
Expand Down
124 changes: 123 additions & 1 deletion app/scripts/controllers/permissions/background-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
RestrictedMethods,
} from '../../../../shared/constants/permissions';
import { getPermissionBackgroundApiMethods } from './background-api';
import { CaveatFactories } from './specifications';
import { CaveatFactories, PermissionNames } from './specifications';

describe('permission background API methods', () => {
const getApprovedPermissions = (accounts) => ({
Expand Down Expand Up @@ -194,4 +194,126 @@ describe('permission background API methods', () => {
);
});
});

describe('requestAccountsAndChainPermissionsWithId', () => {
it('request eth_accounts and permittedChains permissions and returns the request id', async () => {
const permissionController = {
requestPermissions: jest
.fn()
.mockImplementationOnce(async (_, __, { id }) => {
return [null, { id }];
}),
};

const id = await getPermissionBackgroundApiMethods(
permissionController,
).requestAccountsAndChainPermissionsWithId('foo.com');

expect(permissionController.requestPermissions).toHaveBeenCalledTimes(1);
expect(permissionController.requestPermissions).toHaveBeenCalledWith(
{ origin: 'foo.com' },
{
[PermissionNames.eth_accounts]: {},
[PermissionNames.permittedChains]: {},
},
{ id: expect.any(String) },
);

expect(id.length > 0).toBe(true);
expect(id).toStrictEqual(
permissionController.requestPermissions.mock.calls[0][2].id,
);
});
});

describe('removePermittedChain', () => {
it('removes a permitted chain', () => {
const permissionController = {
getCaveat: jest.fn().mockImplementationOnce(() => {
return {
type: CaveatTypes.restrictNetworkSwitching,
value: ['0x1', '0x2'],
};
}),
revokePermission: jest.fn(),
updateCaveat: jest.fn(),
};

getPermissionBackgroundApiMethods(
permissionController,
).removePermittedChain('foo.com', '0x2');

expect(permissionController.getCaveat).toHaveBeenCalledTimes(1);
expect(permissionController.getCaveat).toHaveBeenCalledWith(
'foo.com',
RestrictedMethods.permittedChains,
CaveatTypes.restrictNetworkSwitching,
);

expect(permissionController.revokePermission).not.toHaveBeenCalled();

expect(permissionController.updateCaveat).toHaveBeenCalledTimes(1);
expect(permissionController.updateCaveat).toHaveBeenCalledWith(
'foo.com',
RestrictedMethods.permittedChains,
CaveatTypes.restrictNetworkSwitching,
['0x1'],
);
});

it('revokes the permittedChains permission if the removed chain is the only permitted chain', () => {
const permissionController = {
getCaveat: jest.fn().mockImplementationOnce(() => {
return {
type: CaveatTypes.restrictNetworkSwitching,
value: ['0x1'],
};
}),
revokePermission: jest.fn(),
updateCaveat: jest.fn(),
};

getPermissionBackgroundApiMethods(
permissionController,
).removePermittedChain('foo.com', '0x1');

expect(permissionController.getCaveat).toHaveBeenCalledTimes(1);
expect(permissionController.getCaveat).toHaveBeenCalledWith(
'foo.com',
RestrictedMethods.permittedChains,
CaveatTypes.restrictNetworkSwitching,
);

expect(permissionController.revokePermission).toHaveBeenCalledTimes(1);
expect(permissionController.revokePermission).toHaveBeenCalledWith(
'foo.com',
RestrictedMethods.permittedChains,
);

expect(permissionController.updateCaveat).not.toHaveBeenCalled();
});

it('does not call permissionController.updateCaveat if the specified chain is not permitted', () => {
const permissionController = {
getCaveat: jest.fn().mockImplementationOnce(() => {
return { type: CaveatTypes.restrictNetworkSwitching, value: ['0x1'] };
}),
revokePermission: jest.fn(),
updateCaveat: jest.fn(),
};

getPermissionBackgroundApiMethods(
permissionController,
).removePermittedChain('foo.com', '0x2');
expect(permissionController.getCaveat).toHaveBeenCalledTimes(1);
expect(permissionController.getCaveat).toHaveBeenCalledWith(
'foo.com',
RestrictedMethods.permittedChains,
CaveatTypes.restrictNetworkSwitching,
);

expect(permissionController.revokePermission).not.toHaveBeenCalled();
expect(permissionController.updateCaveat).not.toHaveBeenCalled();
});
});
});
Loading