Commit 6ad3206
authored
Only subscribe to selected accounts (#543)
Here are some demos
- https://www.loom.com/share/334a4f109b44498894be89f86afe5a5a
-
https://www.loom.com/share/bbafb65d3d624adea0bdf13269d25818?sid=ebf0d5c5-290a-480c-a919-7ecf8b00a0c0
Includes:
- Only subscribe to selected accounts
- Turn off account full sync on account creation
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Monitors WebSocket subscriptions only for user-selected accounts, adds
a SetSelectedAccounts API and test-dapp UI, removes background sync on
account creation, and refactors subscription/state handling with
dependency updates.
>
> - **Snap core**:
> - **Account monitoring**: Replace per-account monitor with
`setMonitoredAccounts` to start/stop subscriptions based on selection;
sync only monitored accounts on connection recovery.
> - **Selection API**: Add `keyring.setSelectedAccounts` (validates
UUIDs) and expose test-dapp RPC `setAccountSelected`; permit via
`permissions`.
> - **Background events**: Remove `OnSyncAccount` handler and stop
scheduling sync on account creation.
> - **Keyring**: Stop auto-monitoring on create/delete and remove sync
scheduling; emit events unchanged.
> - **Accounts service**: Add `getAllSelected` using
`getSelectedAccounts` from `@metamask/keyring-snap-sdk`.
> - **Subscriptions**:
> - Add unsubscription confirmation handling; delete repo entry
immediately on unsubscribe.
> - Tighten confirmation parsing; maintain re-subscribe and expiry
flows.
> - **Initialization**:
> - Add `MonitoredAccountsInitializer` to monitor selected accounts on
`onActive`.
> - **State**:
> - Change `deleteKey` to use `snap_setState` with `undefined` sentinel;
update tests.
> - **Test dapp (site)**:
> - Add UI to list/select accounts and inform snap via
`setAccountSelected`; keep manual sync action.
> - **Configs/manifest**:
> - Update `snap.manifest.json` shasum.
> - Permissions updated for new methods.
> - **Dependencies**:
> - Bump `@metamask/keyring-api` to `^21.1.0` and
`@metamask/keyring-snap-sdk` to `^7.1.0` (root, snap, site).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
e37a143. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 329111f commit 6ad3206
File tree
25 files changed
+665
-473
lines changed- packages
- site
- src/components/Handlers
- snap
- src
- core
- handlers
- onCronjob/backgroundEvents
- onKeyringRequest
- onRpcRequest
- services
- accounts
- state
- subscriptions
- entities
25 files changed
+665
-473
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | 38 | | |
42 | 39 | | |
43 | 40 | | |
| |||
47 | 44 | | |
48 | 45 | | |
49 | 46 | | |
| 47 | + | |
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | | - | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
10 | 34 | | |
11 | 35 | | |
12 | 36 | | |
| |||
26 | 50 | | |
27 | 51 | | |
28 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
29 | 64 | | |
30 | 65 | | |
31 | 66 | | |
32 | 67 | | |
33 | 68 | | |
34 | 69 | | |
35 | 70 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
40 | 105 | | |
41 | 106 | | |
42 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
| 44 | + | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
| |||
Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 28 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
| |||
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
47 | | - | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| |||
121 | 124 | | |
122 | 125 | | |
123 | 126 | | |
124 | | - | |
125 | | - | |
| 127 | + | |
126 | 128 | | |
127 | 129 | | |
128 | 130 | | |
| |||
531 | 533 | | |
532 | 534 | | |
533 | 535 | | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | 536 | | |
550 | 537 | | |
551 | 538 | | |
| |||
563 | 550 | | |
564 | 551 | | |
565 | 552 | | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | 553 | | |
579 | 554 | | |
580 | 555 | | |
| |||
611 | 586 | | |
612 | 587 | | |
613 | 588 | | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | 589 | | |
623 | 590 | | |
624 | 591 | | |
| |||
993 | 960 | | |
994 | 961 | | |
995 | 962 | | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
996 | 985 | | |
0 commit comments