@metamask-previews/social-controllers 1.0.0-preview-5e99f980f → 2.0.0-preview-42c8fd288
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.
- package/CHANGELOG.md +11 -1
- package/dist/SocialController-method-action-types.cjs.map +1 -1
- package/dist/SocialController-method-action-types.d.cts +8 -7
- package/dist/SocialController-method-action-types.d.cts.map +1 -1
- package/dist/SocialController-method-action-types.d.mts +8 -7
- package/dist/SocialController-method-action-types.d.mts.map +1 -1
- package/dist/SocialController-method-action-types.mjs.map +1 -1
- package/dist/SocialController.cjs +10 -9
- package/dist/SocialController.cjs.map +1 -1
- package/dist/SocialController.d.cts +10 -9
- package/dist/SocialController.d.cts.map +1 -1
- package/dist/SocialController.d.mts +10 -9
- package/dist/SocialController.d.mts.map +1 -1
- package/dist/SocialController.mjs +10 -9
- package/dist/SocialController.mjs.map +1 -1
- package/dist/SocialService-method-action-types.cjs.map +1 -1
- package/dist/SocialService-method-action-types.d.cts +11 -12
- package/dist/SocialService-method-action-types.d.cts.map +1 -1
- package/dist/SocialService-method-action-types.d.mts +11 -12
- package/dist/SocialService-method-action-types.d.mts.map +1 -1
- package/dist/SocialService-method-action-types.mjs.map +1 -1
- package/dist/SocialService.cjs +20 -22
- package/dist/SocialService.cjs.map +1 -1
- package/dist/SocialService.d.cts +13 -14
- package/dist/SocialService.d.cts.map +1 -1
- package/dist/SocialService.d.mts +13 -14
- package/dist/SocialService.d.mts.map +1 -1
- package/dist/SocialService.mjs +20 -22
- package/dist/SocialService.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/social-types.cjs.map +1 -1
- package/dist/social-types.d.cts +3 -11
- package/dist/social-types.d.cts.map +1 -1
- package/dist/social-types.d.mts +3 -11
- package/dist/social-types.d.mts.map +1 -1
- package/dist/social-types.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.0.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING:** `SocialService.follow`, `SocialService.unfollow`, and `SocialController.followTrader`, `SocialController.unfollowTrader` no longer accept an `addressOrUid` option. The caller is identified server-side from the JWT `sub` claim carried in the `Authorization` header. ([#8520](https://github.com/MetaMask/core/pull/8520))
|
|
15
|
+
- **BREAKING:** `SocialService.fetchFollowing` and `SocialController.updateFollowing` now take no arguments (previously `{ addressOrUid }`). ([#8520](https://github.com/MetaMask/core/pull/8520))
|
|
16
|
+
- **BREAKING:** Remove `FetchFollowingOptions` type export (no longer needed). ([#8520](https://github.com/MetaMask/core/pull/8520))
|
|
17
|
+
- `SocialService` now calls `PUT /v1/users/me/follows`, `DELETE /v1/users/me/follows`, and `GET /v1/users/me/following` (previously `/v1/users/:addressOrUid/...`). ([#8520](https://github.com/MetaMask/core/pull/8520))
|
|
18
|
+
|
|
10
19
|
## [1.0.0]
|
|
11
20
|
|
|
12
21
|
### Uncategorized
|
|
@@ -51,7 +60,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
51
60
|
- `unfollowTrader` — unfollows traders and removes addresses from state
|
|
52
61
|
- `updateFollowing` — fetches following list and replaces addresses in state
|
|
53
62
|
|
|
54
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/social-controllers@
|
|
63
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/social-controllers@2.0.0...HEAD
|
|
64
|
+
[2.0.0]: https://github.com/MetaMask/core/compare/@metamask/social-controllers@1.0.0...@metamask/social-controllers@2.0.0
|
|
55
65
|
[1.0.0]: https://github.com/MetaMask/core/compare/@metamask/social-controllers@0.2.0...@metamask/social-controllers@1.0.0
|
|
56
66
|
[0.2.0]: https://github.com/MetaMask/core/compare/@metamask/social-controllers@0.1.0...@metamask/social-controllers@0.2.0
|
|
57
67
|
[0.1.0]: https://github.com/MetaMask/core/releases/tag/@metamask/social-controllers@0.1.0
|
|
@@ -1 +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
|
|
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 on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\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 on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\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. The caller is identified server-side\n * from the JWT attached by the SocialService.\n *\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"]}
|
|
@@ -14,10 +14,11 @@ export type SocialControllerUpdateLeaderboardAction = {
|
|
|
14
14
|
handler: SocialController['updateLeaderboard'];
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
* Follows one or more traders
|
|
17
|
+
* Follows one or more traders on behalf of the current user and updates
|
|
18
|
+
* the following list in state. The caller is identified server-side from
|
|
19
|
+
* the JWT attached by the SocialService.
|
|
18
20
|
*
|
|
19
21
|
* @param options - Options bag.
|
|
20
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
21
22
|
* @param options.targets - Addresses or profile IDs to follow.
|
|
22
23
|
* @returns The follow response with confirmed follows.
|
|
23
24
|
*/
|
|
@@ -26,10 +27,11 @@ export type SocialControllerFollowTraderAction = {
|
|
|
26
27
|
handler: SocialController['followTrader'];
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
|
-
* Unfollows one or more traders
|
|
30
|
+
* Unfollows one or more traders on behalf of the current user and updates
|
|
31
|
+
* the following list in state. The caller is identified server-side from
|
|
32
|
+
* the JWT attached by the SocialService.
|
|
30
33
|
*
|
|
31
34
|
* @param options - Options bag.
|
|
32
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
33
35
|
* @param options.targets - Addresses or profile IDs to unfollow.
|
|
34
36
|
* @returns The unfollow response with confirmed unfollows.
|
|
35
37
|
*/
|
|
@@ -39,10 +41,9 @@ export type SocialControllerUnfollowTraderAction = {
|
|
|
39
41
|
};
|
|
40
42
|
/**
|
|
41
43
|
* Fetches the list of traders the current user follows and replaces
|
|
42
|
-
* the following addresses in state.
|
|
44
|
+
* the following addresses in state. The caller is identified server-side
|
|
45
|
+
* from the JWT attached by the SocialService.
|
|
43
46
|
*
|
|
44
|
-
* @param options - Options bag.
|
|
45
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
46
47
|
* @returns The following response.
|
|
47
48
|
*/
|
|
48
49
|
export type SocialControllerUpdateFollowingAction = {
|
|
@@ -1 +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
|
|
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;;;;;;;;GAQG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;GAMG;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"}
|
|
@@ -14,10 +14,11 @@ export type SocialControllerUpdateLeaderboardAction = {
|
|
|
14
14
|
handler: SocialController['updateLeaderboard'];
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
* Follows one or more traders
|
|
17
|
+
* Follows one or more traders on behalf of the current user and updates
|
|
18
|
+
* the following list in state. The caller is identified server-side from
|
|
19
|
+
* the JWT attached by the SocialService.
|
|
18
20
|
*
|
|
19
21
|
* @param options - Options bag.
|
|
20
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
21
22
|
* @param options.targets - Addresses or profile IDs to follow.
|
|
22
23
|
* @returns The follow response with confirmed follows.
|
|
23
24
|
*/
|
|
@@ -26,10 +27,11 @@ export type SocialControllerFollowTraderAction = {
|
|
|
26
27
|
handler: SocialController['followTrader'];
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
|
-
* Unfollows one or more traders
|
|
30
|
+
* Unfollows one or more traders on behalf of the current user and updates
|
|
31
|
+
* the following list in state. The caller is identified server-side from
|
|
32
|
+
* the JWT attached by the SocialService.
|
|
30
33
|
*
|
|
31
34
|
* @param options - Options bag.
|
|
32
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
33
35
|
* @param options.targets - Addresses or profile IDs to unfollow.
|
|
34
36
|
* @returns The unfollow response with confirmed unfollows.
|
|
35
37
|
*/
|
|
@@ -39,10 +41,9 @@ export type SocialControllerUnfollowTraderAction = {
|
|
|
39
41
|
};
|
|
40
42
|
/**
|
|
41
43
|
* Fetches the list of traders the current user follows and replaces
|
|
42
|
-
* the following addresses in state.
|
|
44
|
+
* the following addresses in state. The caller is identified server-side
|
|
45
|
+
* from the JWT attached by the SocialService.
|
|
43
46
|
*
|
|
44
|
-
* @param options - Options bag.
|
|
45
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
46
47
|
* @returns The following response.
|
|
47
48
|
*/
|
|
48
49
|
export type SocialControllerUpdateFollowingAction = {
|
|
@@ -1 +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
|
|
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;;;;;;;;GAQG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;GAMG;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"}
|
|
@@ -1 +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
|
|
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 on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\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 on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\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. The caller is identified server-side\n * from the JWT attached by the SocialService.\n *\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"]}
|
|
@@ -81,10 +81,11 @@ class SocialController extends base_controller_1.BaseController {
|
|
|
81
81
|
return leaderboardResponse;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
-
* Follows one or more traders
|
|
84
|
+
* Follows one or more traders on behalf of the current user and updates
|
|
85
|
+
* the following list in state. The caller is identified server-side from
|
|
86
|
+
* the JWT attached by the SocialService.
|
|
85
87
|
*
|
|
86
88
|
* @param options - Options bag.
|
|
87
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
88
89
|
* @param options.targets - Addresses or profile IDs to follow.
|
|
89
90
|
* @returns The follow response with confirmed follows.
|
|
90
91
|
*/
|
|
@@ -107,10 +108,11 @@ class SocialController extends base_controller_1.BaseController {
|
|
|
107
108
|
return followResponse;
|
|
108
109
|
}
|
|
109
110
|
/**
|
|
110
|
-
* Unfollows one or more traders
|
|
111
|
+
* Unfollows one or more traders on behalf of the current user and updates
|
|
112
|
+
* the following list in state. The caller is identified server-side from
|
|
113
|
+
* the JWT attached by the SocialService.
|
|
111
114
|
*
|
|
112
115
|
* @param options - Options bag.
|
|
113
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
114
116
|
* @param options.targets - Addresses or profile IDs to unfollow.
|
|
115
117
|
* @returns The unfollow response with confirmed unfollows.
|
|
116
118
|
*/
|
|
@@ -126,14 +128,13 @@ class SocialController extends base_controller_1.BaseController {
|
|
|
126
128
|
}
|
|
127
129
|
/**
|
|
128
130
|
* Fetches the list of traders the current user follows and replaces
|
|
129
|
-
* the following addresses in state.
|
|
131
|
+
* the following addresses in state. The caller is identified server-side
|
|
132
|
+
* from the JWT attached by the SocialService.
|
|
130
133
|
*
|
|
131
|
-
* @param options - Options bag.
|
|
132
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
133
134
|
* @returns The following response.
|
|
134
135
|
*/
|
|
135
|
-
async updateFollowing(
|
|
136
|
-
const followingResponse = await this.messenger.call('SocialService:fetchFollowing'
|
|
136
|
+
async updateFollowing() {
|
|
137
|
+
const followingResponse = await this.messenger.call('SocialService:fetchFollowing');
|
|
137
138
|
this.update((state) => {
|
|
138
139
|
state.followingAddresses = followingResponse.following.map((profile) => profile.address);
|
|
139
140
|
state.followingProfileIds = followingResponse.following.map((profile) => profile.profileId);
|
|
@@ -1 +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;QACtB,mBAAmB,EAAE,EAAE;KACxB,CAAC;AACJ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H,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF;AA3ID,4CA2IC","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 followingProfileIds: [],\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 followingProfileIds: {\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 const newProfileIds = [\n ...new Set(followResponse.followed.map((profile) => profile.profileId)),\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 const existingIds = new Set(state.followingProfileIds);\n const uniqueNewIds = newProfileIds.filter((id) => !existingIds.has(id));\n state.followingProfileIds.push(...uniqueNewIds);\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 const removedProfileIds = new Set(\n unfollowResponse.unfollowed.map((profile) => profile.profileId),\n );\n\n this.update((state) => {\n state.followingAddresses = state.followingAddresses.filter(\n (address) => !removedAddresses.has(address),\n );\n state.followingProfileIds = state.followingProfileIds.filter(\n (id) => !removedProfileIds.has(id),\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 state.followingProfileIds = followingResponse.following.map(\n (profile) => profile.profileId,\n );\n });\n\n return followingResponse;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SocialController.cjs","sourceRoot":"","sources":["../src/SocialController.ts"],"names":[],"mappings":";;;AAKA,+DAA2D;AAG3D,6DAAoD;AAmBpD,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;QACtB,mBAAmB,EAAE,EAAE;KACxB,CAAC;AACJ,CAAC;AAND,0EAMC;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;QAClB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,QAAQ,EAAE,IAAI;KACf;IACD,mBAAmB,EAAE;QACnB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,qBAAqB;AAErB;;;;;;;GAOG;AACH,MAAa,gBAAiB,SAAQ,gCAIrC;IACC,YAAY,EAAE,SAAS,EAAE,KAAK,EAA2B;QACvD,KAAK,CAAC;YACJ,IAAI,EAAE,iCAAc;YACpB,QAAQ,EAAE,wBAAwB;YAClC,KAAK,EAAE;gBACL,GAAG,+BAA+B,EAAE;gBACpC,GAAG,KAAK;aACT;YACD,SAAS;SACV,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ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BAAiB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACjD,8BAA8B,CAC/B,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,kBAAkB,GAAG,iBAAiB,CAAC,SAAS,CAAC,GAAG,CACxD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAC7B,CAAC;YACF,KAAK,CAAC,mBAAmB,GAAG,iBAAiB,CAAC,SAAS,CAAC,GAAG,CACzD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAC/B,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF;AAzID,4CAyIC","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 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 followingProfileIds: [],\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 followingProfileIds: {\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 on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\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 const newProfileIds = [\n ...new Set(followResponse.followed.map((profile) => profile.profileId)),\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 const existingIds = new Set(state.followingProfileIds);\n const uniqueNewIds = newProfileIds.filter((id) => !existingIds.has(id));\n state.followingProfileIds.push(...uniqueNewIds);\n });\n\n return followResponse;\n }\n\n /**\n * Unfollows one or more traders on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\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 const removedProfileIds = new Set(\n unfollowResponse.unfollowed.map((profile) => profile.profileId),\n );\n\n this.update((state) => {\n state.followingAddresses = state.followingAddresses.filter(\n (address) => !removedAddresses.has(address),\n );\n state.followingProfileIds = state.followingProfileIds.filter(\n (id) => !removedProfileIds.has(id),\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. The caller is identified server-side\n * from the JWT attached by the SocialService.\n *\n * @returns The following response.\n */\n async updateFollowing(): Promise<FollowingResponse> {\n const followingResponse = await this.messenger.call(\n 'SocialService:fetchFollowing',\n );\n\n this.update((state) => {\n state.followingAddresses = followingResponse.following.map(\n (profile) => profile.address,\n );\n state.followingProfileIds = followingResponse.following.map(\n (profile) => profile.profileId,\n );\n });\n\n return followingResponse;\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@meta
|
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { Messenger } from "@metamask/messenger";
|
|
4
4
|
import { controllerName } from "./social-constants.cjs";
|
|
5
|
-
import type {
|
|
5
|
+
import type { FetchLeaderboardOptions, FollowOptions, FollowResponse, FollowingResponse, LeaderboardResponse, SocialControllerState, UnfollowOptions, UnfollowResponse } from "./social-types.cjs";
|
|
6
6
|
import type { SocialControllerMethodActions } from "./SocialController-method-action-types.cjs";
|
|
7
7
|
import type { SocialServiceFetchFollowingAction, SocialServiceFetchLeaderboardAction, SocialServiceFollowAction, SocialServiceUnfollowAction } from "./SocialService-method-action-types.cjs";
|
|
8
8
|
export type SocialControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SocialControllerState>;
|
|
@@ -40,32 +40,33 @@ export declare class SocialController extends BaseController<typeof controllerNa
|
|
|
40
40
|
*/
|
|
41
41
|
updateLeaderboard(options?: FetchLeaderboardOptions): Promise<LeaderboardResponse>;
|
|
42
42
|
/**
|
|
43
|
-
* Follows one or more traders
|
|
43
|
+
* Follows one or more traders on behalf of the current user and updates
|
|
44
|
+
* the following list in state. The caller is identified server-side from
|
|
45
|
+
* the JWT attached by the SocialService.
|
|
44
46
|
*
|
|
45
47
|
* @param options - Options bag.
|
|
46
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
47
48
|
* @param options.targets - Addresses or profile IDs to follow.
|
|
48
49
|
* @returns The follow response with confirmed follows.
|
|
49
50
|
*/
|
|
50
51
|
followTrader(options: FollowOptions): Promise<FollowResponse>;
|
|
51
52
|
/**
|
|
52
|
-
* Unfollows one or more traders
|
|
53
|
+
* Unfollows one or more traders on behalf of the current user and updates
|
|
54
|
+
* the following list in state. The caller is identified server-side from
|
|
55
|
+
* the JWT attached by the SocialService.
|
|
53
56
|
*
|
|
54
57
|
* @param options - Options bag.
|
|
55
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
56
58
|
* @param options.targets - Addresses or profile IDs to unfollow.
|
|
57
59
|
* @returns The unfollow response with confirmed unfollows.
|
|
58
60
|
*/
|
|
59
61
|
unfollowTrader(options: UnfollowOptions): Promise<UnfollowResponse>;
|
|
60
62
|
/**
|
|
61
63
|
* Fetches the list of traders the current user follows and replaces
|
|
62
|
-
* the following addresses in state.
|
|
64
|
+
* the following addresses in state. The caller is identified server-side
|
|
65
|
+
* from the JWT attached by the SocialService.
|
|
63
66
|
*
|
|
64
|
-
* @param options - Options bag.
|
|
65
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
66
67
|
* @returns The following response.
|
|
67
68
|
*/
|
|
68
|
-
updateFollowing(
|
|
69
|
+
updateFollowing(): Promise<FollowingResponse>;
|
|
69
70
|
}
|
|
70
71
|
export {};
|
|
71
72
|
//# sourceMappingURL=SocialController.d.cts.map
|
|
@@ -1 +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,
|
|
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,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,MAAM,uBAAuB,GAC/B,8BAA8B,GAC9B,6BAA6B,CAAC;AAIlC,MAAM,MAAM,gCAAgC,GAAG,0BAA0B,CACvE,OAAO,cAAc,EACrB,qBAAqB,CACtB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,gCAAgC,CAAC;AAItE,KAAK,cAAc,GACf,mCAAmC,GACnC,yBAAyB,GACzB,2BAA2B,GAC3B,iCAAiC,CAAC;AAEtC,KAAK,aAAa,GAAG,KAAK,CAAC;AAI3B,MAAM,MAAM,yBAAyB,GAAG,SAAS,CAC/C,OAAO,cAAc,EACrB,uBAAuB,GAAG,cAAc,EACxC,sBAAsB,GAAG,aAAa,CACvC,CAAC;AAIF,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,yBAAyB,CAAC;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACxC,CAAC;AAIF;;;;GAIG;AACH,wBAAgB,+BAA+B,IAAI,qBAAqB,CAMvE;AA2BD;;;;;;;GAOG;AACH,qBAAa,gBAAiB,SAAQ,cAAc,CAClD,OAAO,cAAc,EACrB,qBAAqB,EACrB,yBAAyB,CAC1B;gBACa,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,uBAAuB;IAiBzD;;;;;OAKG;IACG,iBAAiB,CACrB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,mBAAmB,CAAC;IAa/B;;;;;;;;OAQG;IACG,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IA4BnE;;;;;;;;OAQG;IACG,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyBzE;;;;;;OAMG;IACG,eAAe,IAAI,OAAO,CAAC,iBAAiB,CAAC;CAgBpD"}
|
|
@@ -2,7 +2,7 @@ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@meta
|
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { Messenger } from "@metamask/messenger";
|
|
4
4
|
import { controllerName } from "./social-constants.mjs";
|
|
5
|
-
import type {
|
|
5
|
+
import type { FetchLeaderboardOptions, FollowOptions, FollowResponse, FollowingResponse, LeaderboardResponse, SocialControllerState, UnfollowOptions, UnfollowResponse } from "./social-types.mjs";
|
|
6
6
|
import type { SocialControllerMethodActions } from "./SocialController-method-action-types.mjs";
|
|
7
7
|
import type { SocialServiceFetchFollowingAction, SocialServiceFetchLeaderboardAction, SocialServiceFollowAction, SocialServiceUnfollowAction } from "./SocialService-method-action-types.mjs";
|
|
8
8
|
export type SocialControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SocialControllerState>;
|
|
@@ -40,32 +40,33 @@ export declare class SocialController extends BaseController<typeof controllerNa
|
|
|
40
40
|
*/
|
|
41
41
|
updateLeaderboard(options?: FetchLeaderboardOptions): Promise<LeaderboardResponse>;
|
|
42
42
|
/**
|
|
43
|
-
* Follows one or more traders
|
|
43
|
+
* Follows one or more traders on behalf of the current user and updates
|
|
44
|
+
* the following list in state. The caller is identified server-side from
|
|
45
|
+
* the JWT attached by the SocialService.
|
|
44
46
|
*
|
|
45
47
|
* @param options - Options bag.
|
|
46
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
47
48
|
* @param options.targets - Addresses or profile IDs to follow.
|
|
48
49
|
* @returns The follow response with confirmed follows.
|
|
49
50
|
*/
|
|
50
51
|
followTrader(options: FollowOptions): Promise<FollowResponse>;
|
|
51
52
|
/**
|
|
52
|
-
* Unfollows one or more traders
|
|
53
|
+
* Unfollows one or more traders on behalf of the current user and updates
|
|
54
|
+
* the following list in state. The caller is identified server-side from
|
|
55
|
+
* the JWT attached by the SocialService.
|
|
53
56
|
*
|
|
54
57
|
* @param options - Options bag.
|
|
55
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
56
58
|
* @param options.targets - Addresses or profile IDs to unfollow.
|
|
57
59
|
* @returns The unfollow response with confirmed unfollows.
|
|
58
60
|
*/
|
|
59
61
|
unfollowTrader(options: UnfollowOptions): Promise<UnfollowResponse>;
|
|
60
62
|
/**
|
|
61
63
|
* Fetches the list of traders the current user follows and replaces
|
|
62
|
-
* the following addresses in state.
|
|
64
|
+
* the following addresses in state. The caller is identified server-side
|
|
65
|
+
* from the JWT attached by the SocialService.
|
|
63
66
|
*
|
|
64
|
-
* @param options - Options bag.
|
|
65
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
66
67
|
* @returns The following response.
|
|
67
68
|
*/
|
|
68
|
-
updateFollowing(
|
|
69
|
+
updateFollowing(): Promise<FollowingResponse>;
|
|
69
70
|
}
|
|
70
71
|
export {};
|
|
71
72
|
//# sourceMappingURL=SocialController.d.mts.map
|
|
@@ -1 +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,
|
|
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,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,MAAM,uBAAuB,GAC/B,8BAA8B,GAC9B,6BAA6B,CAAC;AAIlC,MAAM,MAAM,gCAAgC,GAAG,0BAA0B,CACvE,OAAO,cAAc,EACrB,qBAAqB,CACtB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,gCAAgC,CAAC;AAItE,KAAK,cAAc,GACf,mCAAmC,GACnC,yBAAyB,GACzB,2BAA2B,GAC3B,iCAAiC,CAAC;AAEtC,KAAK,aAAa,GAAG,KAAK,CAAC;AAI3B,MAAM,MAAM,yBAAyB,GAAG,SAAS,CAC/C,OAAO,cAAc,EACrB,uBAAuB,GAAG,cAAc,EACxC,sBAAsB,GAAG,aAAa,CACvC,CAAC;AAIF,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,yBAAyB,CAAC;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACxC,CAAC;AAIF;;;;GAIG;AACH,wBAAgB,+BAA+B,IAAI,qBAAqB,CAMvE;AA2BD;;;;;;;GAOG;AACH,qBAAa,gBAAiB,SAAQ,cAAc,CAClD,OAAO,cAAc,EACrB,qBAAqB,EACrB,yBAAyB,CAC1B;gBACa,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,uBAAuB;IAiBzD;;;;;OAKG;IACG,iBAAiB,CACrB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,mBAAmB,CAAC;IAa/B;;;;;;;;OAQG;IACG,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IA4BnE;;;;;;;;OAQG;IACG,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyBzE;;;;;;OAMG;IACG,eAAe,IAAI,OAAO,CAAC,iBAAiB,CAAC;CAgBpD"}
|
|
@@ -77,10 +77,11 @@ export class SocialController extends BaseController {
|
|
|
77
77
|
return leaderboardResponse;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
|
-
* Follows one or more traders
|
|
80
|
+
* Follows one or more traders on behalf of the current user and updates
|
|
81
|
+
* the following list in state. The caller is identified server-side from
|
|
82
|
+
* the JWT attached by the SocialService.
|
|
81
83
|
*
|
|
82
84
|
* @param options - Options bag.
|
|
83
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
84
85
|
* @param options.targets - Addresses or profile IDs to follow.
|
|
85
86
|
* @returns The follow response with confirmed follows.
|
|
86
87
|
*/
|
|
@@ -103,10 +104,11 @@ export class SocialController extends BaseController {
|
|
|
103
104
|
return followResponse;
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
106
|
-
* Unfollows one or more traders
|
|
107
|
+
* Unfollows one or more traders on behalf of the current user and updates
|
|
108
|
+
* the following list in state. The caller is identified server-side from
|
|
109
|
+
* the JWT attached by the SocialService.
|
|
107
110
|
*
|
|
108
111
|
* @param options - Options bag.
|
|
109
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
110
112
|
* @param options.targets - Addresses or profile IDs to unfollow.
|
|
111
113
|
* @returns The unfollow response with confirmed unfollows.
|
|
112
114
|
*/
|
|
@@ -122,14 +124,13 @@ export class SocialController extends BaseController {
|
|
|
122
124
|
}
|
|
123
125
|
/**
|
|
124
126
|
* Fetches the list of traders the current user follows and replaces
|
|
125
|
-
* the following addresses in state.
|
|
127
|
+
* the following addresses in state. The caller is identified server-side
|
|
128
|
+
* from the JWT attached by the SocialService.
|
|
126
129
|
*
|
|
127
|
-
* @param options - Options bag.
|
|
128
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
129
130
|
* @returns The following response.
|
|
130
131
|
*/
|
|
131
|
-
async updateFollowing(
|
|
132
|
-
const followingResponse = await this.messenger.call('SocialService:fetchFollowing'
|
|
132
|
+
async updateFollowing() {
|
|
133
|
+
const followingResponse = await this.messenger.call('SocialService:fetchFollowing');
|
|
133
134
|
this.update((state) => {
|
|
134
135
|
state.followingAddresses = followingResponse.following.map((profile) => profile.address);
|
|
135
136
|
state.followingProfileIds = followingResponse.following.map((profile) => profile.profileId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SocialController.mjs","sourceRoot":"","sources":["../src/SocialController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,EAAE,cAAc,EAAE,+BAA2B;AAoBpD,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,mBAAmB;IAC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E,EAAE,CAAC,OAAO,CAAC,OAAO,CAC7B,CAAC;YACF,KAAK,CAAC,mBAAmB,GAAG,iBAAiB,CAAC,SAAS,CAAC,GAAG,CACzD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAC/B,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF","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 followingProfileIds: [],\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 followingProfileIds: {\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 const newProfileIds = [\n ...new Set(followResponse.followed.map((profile) => profile.profileId)),\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 const existingIds = new Set(state.followingProfileIds);\n const uniqueNewIds = newProfileIds.filter((id) => !existingIds.has(id));\n state.followingProfileIds.push(...uniqueNewIds);\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 const removedProfileIds = new Set(\n unfollowResponse.unfollowed.map((profile) => profile.profileId),\n );\n\n this.update((state) => {\n state.followingAddresses = state.followingAddresses.filter(\n (address) => !removedAddresses.has(address),\n );\n state.followingProfileIds = state.followingProfileIds.filter(\n (id) => !removedProfileIds.has(id),\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 state.followingProfileIds = followingResponse.following.map(\n (profile) => profile.profileId,\n );\n });\n\n return followingResponse;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SocialController.mjs","sourceRoot":"","sources":["../src/SocialController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,EAAE,cAAc,EAAE,+BAA2B;AAmBpD,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,mBAAmB;IACnB,cAAc;IACd,gBAAgB;IAChB,iBAAiB;CACT,CAAC;AA+CX,wBAAwB;AAExB;;;;GAIG;AACH,MAAM,UAAU,+BAA+B;IAC7C,OAAO;QACL,kBAAkB,EAAE,EAAE;QACtB,kBAAkB,EAAE,EAAE;QACtB,mBAAmB,EAAE,EAAE;KACxB,CAAC;AACJ,CAAC;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;QAClB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,QAAQ,EAAE,IAAI;KACf;IACD,mBAAmB,EAAE;QACnB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,qBAAqB;AAErB;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAiB,SAAQ,cAIrC;IACC,YAAY,EAAE,SAAS,EAAE,KAA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mBAAmB,CAAC,MAAM,CAC1D,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,CACnC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACjD,8BAA8B,CAC/B,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,kBAAkB,GAAG,iBAAiB,CAAC,SAAS,CAAC,GAAG,CACxD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAC7B,CAAC;YACF,KAAK,CAAC,mBAAmB,GAAG,iBAAiB,CAAC,SAAS,CAAC,GAAG,CACzD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAC/B,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF","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 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 followingProfileIds: [],\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 followingProfileIds: {\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 on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\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 const newProfileIds = [\n ...new Set(followResponse.followed.map((profile) => profile.profileId)),\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 const existingIds = new Set(state.followingProfileIds);\n const uniqueNewIds = newProfileIds.filter((id) => !existingIds.has(id));\n state.followingProfileIds.push(...uniqueNewIds);\n });\n\n return followResponse;\n }\n\n /**\n * Unfollows one or more traders on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\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 const removedProfileIds = new Set(\n unfollowResponse.unfollowed.map((profile) => profile.profileId),\n );\n\n this.update((state) => {\n state.followingAddresses = state.followingAddresses.filter(\n (address) => !removedAddresses.has(address),\n );\n state.followingProfileIds = state.followingProfileIds.filter(\n (id) => !removedProfileIds.has(id),\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. The caller is identified server-side\n * from the JWT attached by the SocialService.\n *\n * @returns The following response.\n */\n async updateFollowing(): Promise<FollowingResponse> {\n const followingResponse = await this.messenger.call(\n 'SocialService:fetchFollowing',\n );\n\n this.update((state) => {\n state.followingAddresses = followingResponse.following.map(\n (profile) => profile.address,\n );\n state.followingProfileIds = followingResponse.following.map(\n (profile) => profile.profileId,\n );\n });\n\n return followingResponse;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SocialService-method-action-types.cjs","sourceRoot":"","sources":["../src/SocialService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SocialService } from './SocialService';\n\n/**\n * Fetches the leaderboard of top traders.\n *\n * Calls `GET ${baseUrl}/leaderboard`.\n *\n * @param options - Optional query parameters for sorting, chain filtering, and limit.\n * @returns The leaderboard response with ranked traders.\n */\nexport type SocialServiceFetchLeaderboardAction = {\n type: `SocialService:fetchLeaderboard`;\n handler: SocialService['fetchLeaderboard'];\n};\n\n/**\n * Fetches a trader's profile by address or profile ID.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/profile`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @returns The trader profile response.\n */\nexport type SocialServiceFetchTraderProfileAction = {\n type: `SocialService:fetchTraderProfile`;\n handler: SocialService['fetchTraderProfile'];\n};\n\n/**\n * Fetches a trader's open positions.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/positions/open`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @param options.chain - Filter by chain.\n * @param options.sort - Sort by 'value' or 'latest'.\n * @param options.limit - Number of results per page.\n * @param options.page - Page number (1-based).\n * @returns The positions response.\n */\nexport type SocialServiceFetchOpenPositionsAction = {\n type: `SocialService:fetchOpenPositions`;\n handler: SocialService['fetchOpenPositions'];\n};\n\n/**\n * Fetches a trader's closed positions.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/positions/closed`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @param options.chain - Filter by chain.\n * @param options.sort - Sort by 'value' or 'latest'.\n * @param options.limit - Number of results per page.\n * @param options.page - Page number (1-based).\n * @returns The positions response.\n */\nexport type SocialServiceFetchClosedPositionsAction = {\n type: `SocialService:fetchClosedPositions`;\n handler: SocialService['fetchClosedPositions'];\n};\n\n/**\n * Fetches a trader's MetaMask followers.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/followers`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @returns The followers response.\n */\nexport type SocialServiceFetchFollowersAction = {\n type: `SocialService:fetchFollowers`;\n handler: SocialService['fetchFollowers'];\n};\n\n/**\n * Fetches the list of traders
|
|
1
|
+
{"version":3,"file":"SocialService-method-action-types.cjs","sourceRoot":"","sources":["../src/SocialService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SocialService } from './SocialService';\n\n/**\n * Fetches the leaderboard of top traders.\n *\n * Calls `GET ${baseUrl}/leaderboard`.\n *\n * @param options - Optional query parameters for sorting, chain filtering, and limit.\n * @returns The leaderboard response with ranked traders.\n */\nexport type SocialServiceFetchLeaderboardAction = {\n type: `SocialService:fetchLeaderboard`;\n handler: SocialService['fetchLeaderboard'];\n};\n\n/**\n * Fetches a trader's profile by address or profile ID.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/profile`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @returns The trader profile response.\n */\nexport type SocialServiceFetchTraderProfileAction = {\n type: `SocialService:fetchTraderProfile`;\n handler: SocialService['fetchTraderProfile'];\n};\n\n/**\n * Fetches a trader's open positions.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/positions/open`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @param options.chain - Filter by chain.\n * @param options.sort - Sort by 'value' or 'latest'.\n * @param options.limit - Number of results per page.\n * @param options.page - Page number (1-based).\n * @returns The positions response.\n */\nexport type SocialServiceFetchOpenPositionsAction = {\n type: `SocialService:fetchOpenPositions`;\n handler: SocialService['fetchOpenPositions'];\n};\n\n/**\n * Fetches a trader's closed positions.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/positions/closed`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @param options.chain - Filter by chain.\n * @param options.sort - Sort by 'value' or 'latest'.\n * @param options.limit - Number of results per page.\n * @param options.page - Page number (1-based).\n * @returns The positions response.\n */\nexport type SocialServiceFetchClosedPositionsAction = {\n type: `SocialService:fetchClosedPositions`;\n handler: SocialService['fetchClosedPositions'];\n};\n\n/**\n * Fetches a trader's MetaMask followers.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/followers`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @returns The followers response.\n */\nexport type SocialServiceFetchFollowersAction = {\n type: `SocialService:fetchFollowers`;\n handler: SocialService['fetchFollowers'];\n};\n\n/**\n * Fetches the list of traders the current user is following.\n *\n * Calls `GET ${baseUrl}/users/me/following`. The caller is identified\n * server-side from the JWT sub claim carried in the Authorization header.\n *\n * @returns The following response.\n */\nexport type SocialServiceFetchFollowingAction = {\n type: `SocialService:fetchFollowing`;\n handler: SocialService['fetchFollowing'];\n};\n\n/**\n * Follows one or more traders on behalf of the current user.\n *\n * Calls `PUT ${baseUrl}/users/me/follows`. The caller is identified\n * server-side from the JWT sub claim carried in the Authorization header.\n *\n * @param options - Options bag.\n * @param options.targets - Array of wallet addresses or profile IDs to follow.\n * @returns The follow response with confirmed follows.\n */\nexport type SocialServiceFollowAction = {\n type: `SocialService:follow`;\n handler: SocialService['follow'];\n};\n\n/**\n * Unfollows one or more traders on behalf of the current user.\n *\n * Calls `DELETE ${baseUrl}/users/me/follows?targets=...`. Targets are sent\n * as query params because Fastify does not parse request bodies on DELETE\n * requests per RFC 9110. The caller is identified server-side from the JWT\n * sub claim carried in the Authorization header.\n *\n * @param options - Options bag.\n * @param options.targets - Array of wallet addresses or profile IDs to unfollow.\n * @returns The unfollow response with confirmed unfollows.\n */\nexport type SocialServiceUnfollowAction = {\n type: `SocialService:unfollow`;\n handler: SocialService['unfollow'];\n};\n\n/**\n * Union of all SocialService action types.\n */\nexport type SocialServiceMethodActions =\n | SocialServiceFetchLeaderboardAction\n | SocialServiceFetchTraderProfileAction\n | SocialServiceFetchOpenPositionsAction\n | SocialServiceFetchClosedPositionsAction\n | SocialServiceFetchFollowersAction\n | SocialServiceFetchFollowingAction\n | SocialServiceFollowAction\n | SocialServiceUnfollowAction;\n"]}
|
|
@@ -76,12 +76,11 @@ export type SocialServiceFetchFollowersAction = {
|
|
|
76
76
|
handler: SocialService['fetchFollowers'];
|
|
77
77
|
};
|
|
78
78
|
/**
|
|
79
|
-
* Fetches the list of traders
|
|
79
|
+
* Fetches the list of traders the current user is following.
|
|
80
80
|
*
|
|
81
|
-
* Calls `GET ${baseUrl}/users
|
|
81
|
+
* Calls `GET ${baseUrl}/users/me/following`. The caller is identified
|
|
82
|
+
* server-side from the JWT sub claim carried in the Authorization header.
|
|
82
83
|
*
|
|
83
|
-
* @param options - Options bag.
|
|
84
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID.
|
|
85
84
|
* @returns The following response.
|
|
86
85
|
*/
|
|
87
86
|
export type SocialServiceFetchFollowingAction = {
|
|
@@ -89,12 +88,12 @@ export type SocialServiceFetchFollowingAction = {
|
|
|
89
88
|
handler: SocialService['fetchFollowing'];
|
|
90
89
|
};
|
|
91
90
|
/**
|
|
92
|
-
* Follows one or more traders.
|
|
91
|
+
* Follows one or more traders on behalf of the current user.
|
|
93
92
|
*
|
|
94
|
-
* Calls `PUT ${baseUrl}/users
|
|
93
|
+
* Calls `PUT ${baseUrl}/users/me/follows`. The caller is identified
|
|
94
|
+
* server-side from the JWT sub claim carried in the Authorization header.
|
|
95
95
|
*
|
|
96
96
|
* @param options - Options bag.
|
|
97
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the user.
|
|
98
97
|
* @param options.targets - Array of wallet addresses or profile IDs to follow.
|
|
99
98
|
* @returns The follow response with confirmed follows.
|
|
100
99
|
*/
|
|
@@ -103,14 +102,14 @@ export type SocialServiceFollowAction = {
|
|
|
103
102
|
handler: SocialService['follow'];
|
|
104
103
|
};
|
|
105
104
|
/**
|
|
106
|
-
* Unfollows one or more traders.
|
|
105
|
+
* Unfollows one or more traders on behalf of the current user.
|
|
107
106
|
*
|
|
108
|
-
* Calls `DELETE ${baseUrl}/users
|
|
109
|
-
*
|
|
110
|
-
*
|
|
107
|
+
* Calls `DELETE ${baseUrl}/users/me/follows?targets=...`. Targets are sent
|
|
108
|
+
* as query params because Fastify does not parse request bodies on DELETE
|
|
109
|
+
* requests per RFC 9110. The caller is identified server-side from the JWT
|
|
110
|
+
* sub claim carried in the Authorization header.
|
|
111
111
|
*
|
|
112
112
|
* @param options - Options bag.
|
|
113
|
-
* @param options.addressOrUid - Wallet address or Clicker profile ID of the user.
|
|
114
113
|
* @param options.targets - Array of wallet addresses or profile IDs to unfollow.
|
|
115
114
|
* @returns The unfollow response with confirmed unfollows.
|
|
116
115
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SocialService-method-action-types.d.cts","sourceRoot":"","sources":["../src/SocialService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,4BAAwB;AAErD;;;;;;;GAOG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;CAC1C,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"SocialService-method-action-types.d.cts","sourceRoot":"","sources":["../src/SocialService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,4BAAwB;AAErD;;;;;;;GAOG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,aAAa,CAAC,kBAAk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