@metamask/social-controllers 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +20 -0
  3. package/README.md +15 -0
  4. package/dist/SocialController-method-action-types.cjs +7 -0
  5. package/dist/SocialController-method-action-types.cjs.map +1 -0
  6. package/dist/SocialController-method-action-types.d.cts +56 -0
  7. package/dist/SocialController-method-action-types.d.cts.map +1 -0
  8. package/dist/SocialController-method-action-types.d.mts +56 -0
  9. package/dist/SocialController-method-action-types.d.mts.map +1 -0
  10. package/dist/SocialController-method-action-types.mjs +6 -0
  11. package/dist/SocialController-method-action-types.mjs.map +1 -0
  12. package/dist/SocialController.cjs +129 -0
  13. package/dist/SocialController.cjs.map +1 -0
  14. package/dist/SocialController.d.cts +71 -0
  15. package/dist/SocialController.d.cts.map +1 -0
  16. package/dist/SocialController.d.mts +71 -0
  17. package/dist/SocialController.d.mts.map +1 -0
  18. package/dist/SocialController.mjs +124 -0
  19. package/dist/SocialController.mjs.map +1 -0
  20. package/dist/SocialService-method-action-types.cjs +7 -0
  21. package/dist/SocialService-method-action-types.cjs.map +1 -0
  22. package/dist/SocialService-method-action-types.d.cts +125 -0
  23. package/dist/SocialService-method-action-types.d.cts.map +1 -0
  24. package/dist/SocialService-method-action-types.d.mts +125 -0
  25. package/dist/SocialService-method-action-types.d.mts.map +1 -0
  26. package/dist/SocialService-method-action-types.mjs +6 -0
  27. package/dist/SocialService-method-action-types.mjs.map +1 -0
  28. package/dist/SocialService.cjs +434 -0
  29. package/dist/SocialService.cjs.map +1 -0
  30. package/dist/SocialService.d.cts +113 -0
  31. package/dist/SocialService.d.cts.map +1 -0
  32. package/dist/SocialService.d.mts +113 -0
  33. package/dist/SocialService.d.mts.map +1 -0
  34. package/dist/SocialService.mjs +430 -0
  35. package/dist/SocialService.mjs.map +1 -0
  36. package/dist/index.cjs +12 -0
  37. package/dist/index.cjs.map +1 -0
  38. package/dist/index.d.cts +9 -0
  39. package/dist/index.d.cts.map +1 -0
  40. package/dist/index.d.mts +9 -0
  41. package/dist/index.d.mts.map +1 -0
  42. package/dist/index.mjs +4 -0
  43. package/dist/index.mjs.map +1 -0
  44. package/dist/social-constants.cjs +24 -0
  45. package/dist/social-constants.cjs.map +1 -0
  46. package/dist/social-constants.d.cts +21 -0
  47. package/dist/social-constants.d.cts.map +1 -0
  48. package/dist/social-constants.d.mts +21 -0
  49. package/dist/social-constants.d.mts.map +1 -0
  50. package/dist/social-constants.mjs +21 -0
  51. package/dist/social-constants.mjs.map +1 -0
  52. package/dist/social-types.cjs +6 -0
  53. package/dist/social-types.cjs.map +1 -0
  54. package/dist/social-types.d.cts +212 -0
  55. package/dist/social-types.d.cts.map +1 -0
  56. package/dist/social-types.d.mts +212 -0
  57. package/dist/social-types.d.mts.map +1 -0
  58. package/dist/social-types.mjs +5 -0
  59. package/dist/social-types.mjs.map +1 -0
  60. package/package.json +75 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0]
11
+
12
+ ### Added
13
+
14
+ - Initial release ([#8321](https://github.com/MetaMask/core/pull/8321), [#8335](https://github.com/MetaMask/core/pull/8335), [#8337](https://github.com/MetaMask/core/pull/8337))
15
+ - Add `SocialService` data service wrapping social-api endpoints with superstruct response validation
16
+ - Add methods `fetchLeaderboard`, `fetchTraderProfile`, `fetchOpenPositions`, `fetchClosedPositions`, `fetchFollowers`, `fetchFollowing`, `follow`, `unfollow`
17
+ - Add `SocialController` extending `BaseController` with messenger actions for state management
18
+ - `updateLeaderboard` — fetches leaderboard and persists entries to state
19
+ - `followTrader` — follows traders and updates following addresses in state
20
+ - `unfollowTrader` — unfollows traders and removes addresses from state
21
+ - `updateFollowing` — fetches following list and replaces addresses in state
22
+
23
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/social-controllers@0.1.0...HEAD
24
+ [0.1.0]: https://github.com/MetaMask/core/releases/tag/@metamask/social-controllers@0.1.0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MetaMask
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # `@metamask/social-controllers`
2
+
3
+ A collection of social related controllers
4
+
5
+ ## Installation
6
+
7
+ `yarn add @metamask/social-controllers`
8
+
9
+ or
10
+
11
+ `npm install @metamask/social-controllers`
12
+
13
+ ## Contributing
14
+
15
+ This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=SocialController-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController-method-action-types.cjs","sourceRoot":"","sources":["../src/SocialController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SocialController } from './SocialController';\n\n/**\n * Fetches the leaderboard and persists the entries to state.\n *\n * @param options - Optional leaderboard query parameters.\n * @returns The leaderboard response from the social-api.\n */\nexport type SocialControllerUpdateLeaderboardAction = {\n type: `SocialController:updateLeaderboard`;\n handler: SocialController['updateLeaderboard'];\n};\n\n/**\n * Follows one or more traders and updates the following list in state.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.\n * @param options.targets - Addresses or profile IDs to follow.\n * @returns The follow response with confirmed follows.\n */\nexport type SocialControllerFollowTraderAction = {\n type: `SocialController:followTrader`;\n handler: SocialController['followTrader'];\n};\n\n/**\n * Unfollows one or more traders and updates the following list in state.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.\n * @param options.targets - Addresses or profile IDs to unfollow.\n * @returns The unfollow response with confirmed unfollows.\n */\nexport type SocialControllerUnfollowTraderAction = {\n type: `SocialController:unfollowTrader`;\n handler: SocialController['unfollowTrader'];\n};\n\n/**\n * Fetches the list of traders the current user follows and replaces\n * the following addresses in state.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.\n * @returns The following response.\n */\nexport type SocialControllerUpdateFollowingAction = {\n type: `SocialController:updateFollowing`;\n handler: SocialController['updateFollowing'];\n};\n\n/**\n * Union of all SocialController action types.\n */\nexport type SocialControllerMethodActions =\n | SocialControllerUpdateLeaderboardAction\n | SocialControllerFollowTraderAction\n | SocialControllerUnfollowTraderAction\n | SocialControllerUpdateFollowingAction;\n"]}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { SocialController } from "./SocialController.cjs";
6
+ /**
7
+ * Fetches the leaderboard and persists the entries to state.
8
+ *
9
+ * @param options - Optional leaderboard query parameters.
10
+ * @returns The leaderboard response from the social-api.
11
+ */
12
+ export type SocialControllerUpdateLeaderboardAction = {
13
+ type: `SocialController:updateLeaderboard`;
14
+ handler: SocialController['updateLeaderboard'];
15
+ };
16
+ /**
17
+ * Follows one or more traders and updates the following list in state.
18
+ *
19
+ * @param options - Options bag.
20
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
21
+ * @param options.targets - Addresses or profile IDs to follow.
22
+ * @returns The follow response with confirmed follows.
23
+ */
24
+ export type SocialControllerFollowTraderAction = {
25
+ type: `SocialController:followTrader`;
26
+ handler: SocialController['followTrader'];
27
+ };
28
+ /**
29
+ * Unfollows one or more traders and updates the following list in state.
30
+ *
31
+ * @param options - Options bag.
32
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
33
+ * @param options.targets - Addresses or profile IDs to unfollow.
34
+ * @returns The unfollow response with confirmed unfollows.
35
+ */
36
+ export type SocialControllerUnfollowTraderAction = {
37
+ type: `SocialController:unfollowTrader`;
38
+ handler: SocialController['unfollowTrader'];
39
+ };
40
+ /**
41
+ * Fetches the list of traders the current user follows and replaces
42
+ * the following addresses in state.
43
+ *
44
+ * @param options - Options bag.
45
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
46
+ * @returns The following response.
47
+ */
48
+ export type SocialControllerUpdateFollowingAction = {
49
+ type: `SocialController:updateFollowing`;
50
+ handler: SocialController['updateFollowing'];
51
+ };
52
+ /**
53
+ * Union of all SocialController action types.
54
+ */
55
+ export type SocialControllerMethodActions = SocialControllerUpdateLeaderboardAction | SocialControllerFollowTraderAction | SocialControllerUnfollowTraderAction | SocialControllerUpdateFollowingAction;
56
+ //# sourceMappingURL=SocialController-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController-method-action-types.d.cts","sourceRoot":"","sources":["../src/SocialController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,uCAAuC,GACvC,kCAAkC,GAClC,oCAAoC,GACpC,qCAAqC,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { SocialController } from "./SocialController.mjs";
6
+ /**
7
+ * Fetches the leaderboard and persists the entries to state.
8
+ *
9
+ * @param options - Optional leaderboard query parameters.
10
+ * @returns The leaderboard response from the social-api.
11
+ */
12
+ export type SocialControllerUpdateLeaderboardAction = {
13
+ type: `SocialController:updateLeaderboard`;
14
+ handler: SocialController['updateLeaderboard'];
15
+ };
16
+ /**
17
+ * Follows one or more traders and updates the following list in state.
18
+ *
19
+ * @param options - Options bag.
20
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
21
+ * @param options.targets - Addresses or profile IDs to follow.
22
+ * @returns The follow response with confirmed follows.
23
+ */
24
+ export type SocialControllerFollowTraderAction = {
25
+ type: `SocialController:followTrader`;
26
+ handler: SocialController['followTrader'];
27
+ };
28
+ /**
29
+ * Unfollows one or more traders and updates the following list in state.
30
+ *
31
+ * @param options - Options bag.
32
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
33
+ * @param options.targets - Addresses or profile IDs to unfollow.
34
+ * @returns The unfollow response with confirmed unfollows.
35
+ */
36
+ export type SocialControllerUnfollowTraderAction = {
37
+ type: `SocialController:unfollowTrader`;
38
+ handler: SocialController['unfollowTrader'];
39
+ };
40
+ /**
41
+ * Fetches the list of traders the current user follows and replaces
42
+ * the following addresses in state.
43
+ *
44
+ * @param options - Options bag.
45
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
46
+ * @returns The following response.
47
+ */
48
+ export type SocialControllerUpdateFollowingAction = {
49
+ type: `SocialController:updateFollowing`;
50
+ handler: SocialController['updateFollowing'];
51
+ };
52
+ /**
53
+ * Union of all SocialController action types.
54
+ */
55
+ export type SocialControllerMethodActions = SocialControllerUpdateLeaderboardAction | SocialControllerFollowTraderAction | SocialControllerUnfollowTraderAction | SocialControllerUpdateFollowingAction;
56
+ //# sourceMappingURL=SocialController-method-action-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController-method-action-types.d.mts","sourceRoot":"","sources":["../src/SocialController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,uCAAuC,GACvC,kCAAkC,GAClC,oCAAoC,GACpC,qCAAqC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=SocialController-method-action-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController-method-action-types.mjs","sourceRoot":"","sources":["../src/SocialController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SocialController } from './SocialController';\n\n/**\n * Fetches the leaderboard and persists the entries to state.\n *\n * @param options - Optional leaderboard query parameters.\n * @returns The leaderboard response from the social-api.\n */\nexport type SocialControllerUpdateLeaderboardAction = {\n type: `SocialController:updateLeaderboard`;\n handler: SocialController['updateLeaderboard'];\n};\n\n/**\n * Follows one or more traders and updates the following list in state.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.\n * @param options.targets - Addresses or profile IDs to follow.\n * @returns The follow response with confirmed follows.\n */\nexport type SocialControllerFollowTraderAction = {\n type: `SocialController:followTrader`;\n handler: SocialController['followTrader'];\n};\n\n/**\n * Unfollows one or more traders and updates the following list in state.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.\n * @param options.targets - Addresses or profile IDs to unfollow.\n * @returns The unfollow response with confirmed unfollows.\n */\nexport type SocialControllerUnfollowTraderAction = {\n type: `SocialController:unfollowTrader`;\n handler: SocialController['unfollowTrader'];\n};\n\n/**\n * Fetches the list of traders the current user follows and replaces\n * the following addresses in state.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.\n * @returns The following response.\n */\nexport type SocialControllerUpdateFollowingAction = {\n type: `SocialController:updateFollowing`;\n handler: SocialController['updateFollowing'];\n};\n\n/**\n * Union of all SocialController action types.\n */\nexport type SocialControllerMethodActions =\n | SocialControllerUpdateLeaderboardAction\n | SocialControllerFollowTraderAction\n | SocialControllerUnfollowTraderAction\n | SocialControllerUpdateFollowingAction;\n"]}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SocialController = exports.getDefaultSocialControllerState = void 0;
4
+ const base_controller_1 = require("@metamask/base-controller");
5
+ const social_constants_1 = require("./social-constants.cjs");
6
+ // === MESSENGER ===
7
+ const MESSENGER_EXPOSED_METHODS = [
8
+ 'updateLeaderboard',
9
+ 'followTrader',
10
+ 'unfollowTrader',
11
+ 'updateFollowing',
12
+ ];
13
+ // === DEFAULT STATE ===
14
+ /**
15
+ * Returns the default state for the SocialController.
16
+ *
17
+ * @returns A fresh default state object.
18
+ */
19
+ function getDefaultSocialControllerState() {
20
+ return {
21
+ leaderboardEntries: [],
22
+ followingAddresses: [],
23
+ };
24
+ }
25
+ exports.getDefaultSocialControllerState = getDefaultSocialControllerState;
26
+ // === STATE METADATA ===
27
+ const socialControllerMetadata = {
28
+ leaderboardEntries: {
29
+ persist: true,
30
+ includeInDebugSnapshot: false,
31
+ includeInStateLogs: false,
32
+ usedInUi: true,
33
+ },
34
+ followingAddresses: {
35
+ persist: true,
36
+ includeInDebugSnapshot: false,
37
+ includeInStateLogs: false,
38
+ usedInUi: true,
39
+ },
40
+ };
41
+ // === CONTROLLER ===
42
+ /**
43
+ * Controller that manages social trading state for the extension UI.
44
+ *
45
+ * Acts as a simple store with no TTL or eviction — the UI decides when
46
+ * to re-fetch, and the social-api's own cache layer handles upstream
47
+ * rate-limiting. State is persisted across sessions so the UI can render
48
+ * immediately on startup while a fresh fetch is in flight.
49
+ */
50
+ class SocialController extends base_controller_1.BaseController {
51
+ constructor({ messenger, state }) {
52
+ super({
53
+ name: social_constants_1.controllerName,
54
+ metadata: socialControllerMetadata,
55
+ state: {
56
+ ...getDefaultSocialControllerState(),
57
+ ...state,
58
+ },
59
+ messenger,
60
+ });
61
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
62
+ }
63
+ /**
64
+ * Fetches the leaderboard and persists the entries to state.
65
+ *
66
+ * @param options - Optional leaderboard query parameters.
67
+ * @returns The leaderboard response from the social-api.
68
+ */
69
+ async updateLeaderboard(options) {
70
+ const leaderboardResponse = await this.messenger.call('SocialService:fetchLeaderboard', options);
71
+ this.update((state) => {
72
+ state.leaderboardEntries = leaderboardResponse.traders;
73
+ });
74
+ return leaderboardResponse;
75
+ }
76
+ /**
77
+ * Follows one or more traders and updates the following list in state.
78
+ *
79
+ * @param options - Options bag.
80
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
81
+ * @param options.targets - Addresses or profile IDs to follow.
82
+ * @returns The follow response with confirmed follows.
83
+ */
84
+ async followTrader(options) {
85
+ const followResponse = await this.messenger.call('SocialService:follow', options);
86
+ const newAddresses = [
87
+ ...new Set(followResponse.followed.map((profile) => profile.address)),
88
+ ];
89
+ this.update((state) => {
90
+ const existing = new Set(state.followingAddresses);
91
+ const uniqueNewAddresses = newAddresses.filter((address) => !existing.has(address));
92
+ state.followingAddresses.push(...uniqueNewAddresses);
93
+ });
94
+ return followResponse;
95
+ }
96
+ /**
97
+ * Unfollows one or more traders and updates the following list in state.
98
+ *
99
+ * @param options - Options bag.
100
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
101
+ * @param options.targets - Addresses or profile IDs to unfollow.
102
+ * @returns The unfollow response with confirmed unfollows.
103
+ */
104
+ async unfollowTrader(options) {
105
+ const unfollowResponse = await this.messenger.call('SocialService:unfollow', options);
106
+ const removedAddresses = new Set(unfollowResponse.unfollowed.map((profile) => profile.address));
107
+ this.update((state) => {
108
+ state.followingAddresses = state.followingAddresses.filter((address) => !removedAddresses.has(address));
109
+ });
110
+ return unfollowResponse;
111
+ }
112
+ /**
113
+ * Fetches the list of traders the current user follows and replaces
114
+ * the following addresses in state.
115
+ *
116
+ * @param options - Options bag.
117
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
118
+ * @returns The following response.
119
+ */
120
+ async updateFollowing(options) {
121
+ const followingResponse = await this.messenger.call('SocialService:fetchFollowing', options);
122
+ this.update((state) => {
123
+ state.followingAddresses = followingResponse.following.map((profile) => profile.address);
124
+ });
125
+ return followingResponse;
126
+ }
127
+ }
128
+ exports.SocialController = SocialController;
129
+ //# sourceMappingURL=SocialController.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController.cjs","sourceRoot":"","sources":["../src/SocialController.ts"],"names":[],"mappings":";;;AAKA,+DAA2D;AAG3D,6DAAoD;AAoBpD,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,mBAAmB;IACnB,cAAc;IACd,gBAAgB;IAChB,iBAAiB;CACT,CAAC;AA+CX,wBAAwB;AAExB;;;;GAIG;AACH,SAAgB,+BAA+B;IAC7C,OAAO;QACL,kBAAkB,EAAE,EAAE;QACtB,kBAAkB,EAAE,EAAE;KACvB,CAAC;AACJ,CAAC;AALD,0EAKC;AAED,yBAAyB;AAEzB,MAAM,wBAAwB,GAAyC;IACrE,kBAAkB,EAAE;QAClB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,QAAQ,EAAE,IAAI;KACf;IACD,kBAAkB,EAAE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,CAAC,CAAC,CAAC;QAEH,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF;AA3HD,4CA2HC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport { controllerName } from './social-constants';\nimport type {\n FetchFollowingOptions,\n FetchLeaderboardOptions,\n FollowOptions,\n FollowResponse,\n FollowingResponse,\n LeaderboardResponse,\n SocialControllerState,\n UnfollowOptions,\n UnfollowResponse,\n} from './social-types';\nimport type { SocialControllerMethodActions } from './SocialController-method-action-types';\nimport type {\n SocialServiceFetchFollowingAction,\n SocialServiceFetchLeaderboardAction,\n SocialServiceFollowAction,\n SocialServiceUnfollowAction,\n} from './SocialService-method-action-types';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'updateLeaderboard',\n 'followTrader',\n 'unfollowTrader',\n 'updateFollowing',\n] as const;\n\n// === ACTION TYPES ===\n\nexport type SocialControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SocialControllerState\n>;\n\nexport type SocialControllerActions =\n | SocialControllerGetStateAction\n | SocialControllerMethodActions;\n\n// === EVENT TYPES ===\n\nexport type SocialControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n SocialControllerState\n>;\n\nexport type SocialControllerEvents = SocialControllerStateChangeEvent;\n\n// === ALLOWED ACTIONS/EVENTS ===\n\ntype AllowedActions =\n | SocialServiceFetchLeaderboardAction\n | SocialServiceFollowAction\n | SocialServiceUnfollowAction\n | SocialServiceFetchFollowingAction;\n\ntype AllowedEvents = never;\n\n// === MESSENGER TYPE ===\n\nexport type SocialControllerMessenger = Messenger<\n typeof controllerName,\n SocialControllerActions | AllowedActions,\n SocialControllerEvents | AllowedEvents\n>;\n\n// === OPTIONS ===\n\nexport type SocialControllerOptions = {\n messenger: SocialControllerMessenger;\n state?: Partial<SocialControllerState>;\n};\n\n// === DEFAULT STATE ===\n\n/**\n * Returns the default state for the SocialController.\n *\n * @returns A fresh default state object.\n */\nexport function getDefaultSocialControllerState(): SocialControllerState {\n return {\n leaderboardEntries: [],\n followingAddresses: [],\n };\n}\n\n// === STATE METADATA ===\n\nconst socialControllerMetadata: StateMetadata<SocialControllerState> = {\n leaderboardEntries: {\n persist: true,\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n usedInUi: true,\n },\n followingAddresses: {\n persist: true,\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n usedInUi: true,\n },\n};\n\n// === CONTROLLER ===\n\n/**\n * Controller that manages social trading state for the extension UI.\n *\n * Acts as a simple store with no TTL or eviction — the UI decides when\n * to re-fetch, and the social-api's own cache layer handles upstream\n * rate-limiting. State is persisted across sessions so the UI can render\n * immediately on startup while a fresh fetch is in flight.\n */\nexport class SocialController extends BaseController<\n typeof controllerName,\n SocialControllerState,\n SocialControllerMessenger\n> {\n constructor({ messenger, state }: SocialControllerOptions) {\n super({\n name: controllerName,\n metadata: socialControllerMetadata,\n state: {\n ...getDefaultSocialControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetches the leaderboard and persists the entries to state.\n *\n * @param options - Optional leaderboard query parameters.\n * @returns The leaderboard response from the social-api.\n */\n async updateLeaderboard(\n options?: FetchLeaderboardOptions,\n ): Promise<LeaderboardResponse> {\n const leaderboardResponse = await this.messenger.call(\n 'SocialService:fetchLeaderboard',\n options,\n );\n\n this.update((state) => {\n state.leaderboardEntries = leaderboardResponse.traders;\n });\n\n return leaderboardResponse;\n }\n\n /**\n * Follows one or more traders and updates the following list in state.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.\n * @param options.targets - Addresses or profile IDs to follow.\n * @returns The follow response with confirmed follows.\n */\n async followTrader(options: FollowOptions): Promise<FollowResponse> {\n const followResponse = await this.messenger.call(\n 'SocialService:follow',\n options,\n );\n\n const newAddresses = [\n ...new Set(followResponse.followed.map((profile) => profile.address)),\n ];\n\n this.update((state) => {\n const existing = new Set(state.followingAddresses);\n const uniqueNewAddresses = newAddresses.filter(\n (address) => !existing.has(address),\n );\n state.followingAddresses.push(...uniqueNewAddresses);\n });\n\n return followResponse;\n }\n\n /**\n * Unfollows one or more traders and updates the following list in state.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.\n * @param options.targets - Addresses or profile IDs to unfollow.\n * @returns The unfollow response with confirmed unfollows.\n */\n async unfollowTrader(options: UnfollowOptions): Promise<UnfollowResponse> {\n const unfollowResponse = await this.messenger.call(\n 'SocialService:unfollow',\n options,\n );\n\n const removedAddresses = new Set(\n unfollowResponse.unfollowed.map((profile) => profile.address),\n );\n\n this.update((state) => {\n state.followingAddresses = state.followingAddresses.filter(\n (address) => !removedAddresses.has(address),\n );\n });\n\n return unfollowResponse;\n }\n\n /**\n * Fetches the list of traders the current user follows and replaces\n * the following addresses in state.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.\n * @returns The following response.\n */\n async updateFollowing(\n options: FetchFollowingOptions,\n ): Promise<FollowingResponse> {\n const followingResponse = await this.messenger.call(\n 'SocialService:fetchFollowing',\n options,\n );\n\n this.update((state) => {\n state.followingAddresses = followingResponse.following.map(\n (profile) => profile.address,\n );\n });\n\n return followingResponse;\n }\n}\n"]}
@@ -0,0 +1,71 @@
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
+ import { BaseController } from "@metamask/base-controller";
3
+ import type { Messenger } from "@metamask/messenger";
4
+ import { controllerName } from "./social-constants.cjs";
5
+ import type { FetchFollowingOptions, FetchLeaderboardOptions, FollowOptions, FollowResponse, FollowingResponse, LeaderboardResponse, SocialControllerState, UnfollowOptions, UnfollowResponse } from "./social-types.cjs";
6
+ import type { SocialControllerMethodActions } from "./SocialController-method-action-types.cjs";
7
+ import type { SocialServiceFetchFollowingAction, SocialServiceFetchLeaderboardAction, SocialServiceFollowAction, SocialServiceUnfollowAction } from "./SocialService-method-action-types.cjs";
8
+ export type SocialControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SocialControllerState>;
9
+ export type SocialControllerActions = SocialControllerGetStateAction | SocialControllerMethodActions;
10
+ export type SocialControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SocialControllerState>;
11
+ export type SocialControllerEvents = SocialControllerStateChangeEvent;
12
+ type AllowedActions = SocialServiceFetchLeaderboardAction | SocialServiceFollowAction | SocialServiceUnfollowAction | SocialServiceFetchFollowingAction;
13
+ type AllowedEvents = never;
14
+ export type SocialControllerMessenger = Messenger<typeof controllerName, SocialControllerActions | AllowedActions, SocialControllerEvents | AllowedEvents>;
15
+ export type SocialControllerOptions = {
16
+ messenger: SocialControllerMessenger;
17
+ state?: Partial<SocialControllerState>;
18
+ };
19
+ /**
20
+ * Returns the default state for the SocialController.
21
+ *
22
+ * @returns A fresh default state object.
23
+ */
24
+ export declare function getDefaultSocialControllerState(): SocialControllerState;
25
+ /**
26
+ * Controller that manages social trading state for the extension UI.
27
+ *
28
+ * Acts as a simple store with no TTL or eviction — the UI decides when
29
+ * to re-fetch, and the social-api's own cache layer handles upstream
30
+ * rate-limiting. State is persisted across sessions so the UI can render
31
+ * immediately on startup while a fresh fetch is in flight.
32
+ */
33
+ export declare class SocialController extends BaseController<typeof controllerName, SocialControllerState, SocialControllerMessenger> {
34
+ constructor({ messenger, state }: SocialControllerOptions);
35
+ /**
36
+ * Fetches the leaderboard and persists the entries to state.
37
+ *
38
+ * @param options - Optional leaderboard query parameters.
39
+ * @returns The leaderboard response from the social-api.
40
+ */
41
+ updateLeaderboard(options?: FetchLeaderboardOptions): Promise<LeaderboardResponse>;
42
+ /**
43
+ * Follows one or more traders and updates the following list in state.
44
+ *
45
+ * @param options - Options bag.
46
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
47
+ * @param options.targets - Addresses or profile IDs to follow.
48
+ * @returns The follow response with confirmed follows.
49
+ */
50
+ followTrader(options: FollowOptions): Promise<FollowResponse>;
51
+ /**
52
+ * Unfollows one or more traders and updates the following list in state.
53
+ *
54
+ * @param options - Options bag.
55
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
56
+ * @param options.targets - Addresses or profile IDs to unfollow.
57
+ * @returns The unfollow response with confirmed unfollows.
58
+ */
59
+ unfollowTrader(options: UnfollowOptions): Promise<UnfollowResponse>;
60
+ /**
61
+ * Fetches the list of traders the current user follows and replaces
62
+ * the following addresses in state.
63
+ *
64
+ * @param options - Options bag.
65
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
66
+ * @returns The following response.
67
+ */
68
+ updateFollowing(options: FetchFollowingOptions): Promise<FollowingResponse>;
69
+ }
70
+ export {};
71
+ //# sourceMappingURL=SocialController.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController.d.cts","sourceRoot":"","sources":["../src/SocialController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,EAAE,cAAc,EAAE,+BAA2B;AACpD,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EACjB,2BAAuB;AACxB,OAAO,KAAK,EAAE,6BAA6B,EAAE,mDAA+C;AAC5F,OAAO,KAAK,EACV,iCAAiC,EACjC,mCAAmC,EACnC,yBAAyB,EACzB,2BAA2B,EAC5B,gDAA4C;AAa7C,MAAM,MAAM,8BAA8B,GAAG,wBAAwB,CACnE,OAAO,cAAc,EACrB,qBAAqB,CACtB,CAAC;AAEF,MAAM,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{ BaseController } from "@metamask/base-controller";
3
+ import type { Messenger } from "@metamask/messenger";
4
+ import { controllerName } from "./social-constants.mjs";
5
+ import type { FetchFollowingOptions, FetchLeaderboardOptions, FollowOptions, FollowResponse, FollowingResponse, LeaderboardResponse, SocialControllerState, UnfollowOptions, UnfollowResponse } from "./social-types.mjs";
6
+ import type { SocialControllerMethodActions } from "./SocialController-method-action-types.mjs";
7
+ import type { SocialServiceFetchFollowingAction, SocialServiceFetchLeaderboardAction, SocialServiceFollowAction, SocialServiceUnfollowAction } from "./SocialService-method-action-types.mjs";
8
+ export type SocialControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SocialControllerState>;
9
+ export type SocialControllerActions = SocialControllerGetStateAction | SocialControllerMethodActions;
10
+ export type SocialControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SocialControllerState>;
11
+ export type SocialControllerEvents = SocialControllerStateChangeEvent;
12
+ type AllowedActions = SocialServiceFetchLeaderboardAction | SocialServiceFollowAction | SocialServiceUnfollowAction | SocialServiceFetchFollowingAction;
13
+ type AllowedEvents = never;
14
+ export type SocialControllerMessenger = Messenger<typeof controllerName, SocialControllerActions | AllowedActions, SocialControllerEvents | AllowedEvents>;
15
+ export type SocialControllerOptions = {
16
+ messenger: SocialControllerMessenger;
17
+ state?: Partial<SocialControllerState>;
18
+ };
19
+ /**
20
+ * Returns the default state for the SocialController.
21
+ *
22
+ * @returns A fresh default state object.
23
+ */
24
+ export declare function getDefaultSocialControllerState(): SocialControllerState;
25
+ /**
26
+ * Controller that manages social trading state for the extension UI.
27
+ *
28
+ * Acts as a simple store with no TTL or eviction — the UI decides when
29
+ * to re-fetch, and the social-api's own cache layer handles upstream
30
+ * rate-limiting. State is persisted across sessions so the UI can render
31
+ * immediately on startup while a fresh fetch is in flight.
32
+ */
33
+ export declare class SocialController extends BaseController<typeof controllerName, SocialControllerState, SocialControllerMessenger> {
34
+ constructor({ messenger, state }: SocialControllerOptions);
35
+ /**
36
+ * Fetches the leaderboard and persists the entries to state.
37
+ *
38
+ * @param options - Optional leaderboard query parameters.
39
+ * @returns The leaderboard response from the social-api.
40
+ */
41
+ updateLeaderboard(options?: FetchLeaderboardOptions): Promise<LeaderboardResponse>;
42
+ /**
43
+ * Follows one or more traders and updates the following list in state.
44
+ *
45
+ * @param options - Options bag.
46
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
47
+ * @param options.targets - Addresses or profile IDs to follow.
48
+ * @returns The follow response with confirmed follows.
49
+ */
50
+ followTrader(options: FollowOptions): Promise<FollowResponse>;
51
+ /**
52
+ * Unfollows one or more traders and updates the following list in state.
53
+ *
54
+ * @param options - Options bag.
55
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
56
+ * @param options.targets - Addresses or profile IDs to unfollow.
57
+ * @returns The unfollow response with confirmed unfollows.
58
+ */
59
+ unfollowTrader(options: UnfollowOptions): Promise<UnfollowResponse>;
60
+ /**
61
+ * Fetches the list of traders the current user follows and replaces
62
+ * the following addresses in state.
63
+ *
64
+ * @param options - Options bag.
65
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
66
+ * @returns The following response.
67
+ */
68
+ updateFollowing(options: FetchFollowingOptions): Promise<FollowingResponse>;
69
+ }
70
+ export {};
71
+ //# sourceMappingURL=SocialController.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController.d.mts","sourceRoot":"","sources":["../src/SocialController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,EAAE,cAAc,EAAE,+BAA2B;AACpD,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EACjB,2BAAuB;AACx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C,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAmBzE;;;;;;;OAOG;IACG,eAAe,CACnB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;CAc9B"}
@@ -0,0 +1,124 @@
1
+ import { BaseController } from "@metamask/base-controller";
2
+ import { controllerName } from "./social-constants.mjs";
3
+ // === MESSENGER ===
4
+ const MESSENGER_EXPOSED_METHODS = [
5
+ 'updateLeaderboard',
6
+ 'followTrader',
7
+ 'unfollowTrader',
8
+ 'updateFollowing',
9
+ ];
10
+ // === DEFAULT STATE ===
11
+ /**
12
+ * Returns the default state for the SocialController.
13
+ *
14
+ * @returns A fresh default state object.
15
+ */
16
+ export function getDefaultSocialControllerState() {
17
+ return {
18
+ leaderboardEntries: [],
19
+ followingAddresses: [],
20
+ };
21
+ }
22
+ // === STATE METADATA ===
23
+ const socialControllerMetadata = {
24
+ leaderboardEntries: {
25
+ persist: true,
26
+ includeInDebugSnapshot: false,
27
+ includeInStateLogs: false,
28
+ usedInUi: true,
29
+ },
30
+ followingAddresses: {
31
+ persist: true,
32
+ includeInDebugSnapshot: false,
33
+ includeInStateLogs: false,
34
+ usedInUi: true,
35
+ },
36
+ };
37
+ // === CONTROLLER ===
38
+ /**
39
+ * Controller that manages social trading state for the extension UI.
40
+ *
41
+ * Acts as a simple store with no TTL or eviction — the UI decides when
42
+ * to re-fetch, and the social-api's own cache layer handles upstream
43
+ * rate-limiting. State is persisted across sessions so the UI can render
44
+ * immediately on startup while a fresh fetch is in flight.
45
+ */
46
+ export class SocialController extends BaseController {
47
+ constructor({ messenger, state }) {
48
+ super({
49
+ name: controllerName,
50
+ metadata: socialControllerMetadata,
51
+ state: {
52
+ ...getDefaultSocialControllerState(),
53
+ ...state,
54
+ },
55
+ messenger,
56
+ });
57
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
58
+ }
59
+ /**
60
+ * Fetches the leaderboard and persists the entries to state.
61
+ *
62
+ * @param options - Optional leaderboard query parameters.
63
+ * @returns The leaderboard response from the social-api.
64
+ */
65
+ async updateLeaderboard(options) {
66
+ const leaderboardResponse = await this.messenger.call('SocialService:fetchLeaderboard', options);
67
+ this.update((state) => {
68
+ state.leaderboardEntries = leaderboardResponse.traders;
69
+ });
70
+ return leaderboardResponse;
71
+ }
72
+ /**
73
+ * Follows one or more traders and updates the following list in state.
74
+ *
75
+ * @param options - Options bag.
76
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
77
+ * @param options.targets - Addresses or profile IDs to follow.
78
+ * @returns The follow response with confirmed follows.
79
+ */
80
+ async followTrader(options) {
81
+ const followResponse = await this.messenger.call('SocialService:follow', options);
82
+ const newAddresses = [
83
+ ...new Set(followResponse.followed.map((profile) => profile.address)),
84
+ ];
85
+ this.update((state) => {
86
+ const existing = new Set(state.followingAddresses);
87
+ const uniqueNewAddresses = newAddresses.filter((address) => !existing.has(address));
88
+ state.followingAddresses.push(...uniqueNewAddresses);
89
+ });
90
+ return followResponse;
91
+ }
92
+ /**
93
+ * Unfollows one or more traders and updates the following list in state.
94
+ *
95
+ * @param options - Options bag.
96
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
97
+ * @param options.targets - Addresses or profile IDs to unfollow.
98
+ * @returns The unfollow response with confirmed unfollows.
99
+ */
100
+ async unfollowTrader(options) {
101
+ const unfollowResponse = await this.messenger.call('SocialService:unfollow', options);
102
+ const removedAddresses = new Set(unfollowResponse.unfollowed.map((profile) => profile.address));
103
+ this.update((state) => {
104
+ state.followingAddresses = state.followingAddresses.filter((address) => !removedAddresses.has(address));
105
+ });
106
+ return unfollowResponse;
107
+ }
108
+ /**
109
+ * Fetches the list of traders the current user follows and replaces
110
+ * the following addresses in state.
111
+ *
112
+ * @param options - Options bag.
113
+ * @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
114
+ * @returns The following response.
115
+ */
116
+ async updateFollowing(options) {
117
+ const followingResponse = await this.messenger.call('SocialService:fetchFollowing', options);
118
+ this.update((state) => {
119
+ state.followingAddresses = followingResponse.following.map((profile) => profile.address);
120
+ });
121
+ return followingResponse;
122
+ }
123
+ }
124
+ //# sourceMappingURL=SocialController.mjs.map