@metamask-previews/social-controllers 0.0.0-preview-10a8a74 → 0.0.0-preview-bfb4d9f5a
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 +8 -1
- package/dist/SocialController-method-action-types.cjs +7 -0
- package/dist/SocialController-method-action-types.cjs.map +1 -0
- package/dist/SocialController-method-action-types.d.cts +56 -0
- package/dist/SocialController-method-action-types.d.cts.map +1 -0
- package/dist/SocialController-method-action-types.d.mts +56 -0
- package/dist/SocialController-method-action-types.d.mts.map +1 -0
- package/dist/SocialController-method-action-types.mjs +6 -0
- package/dist/SocialController-method-action-types.mjs.map +1 -0
- package/dist/SocialController.cjs +127 -0
- package/dist/SocialController.cjs.map +1 -0
- package/dist/SocialController.d.cts +71 -0
- package/dist/SocialController.d.cts.map +1 -0
- package/dist/SocialController.d.mts +71 -0
- package/dist/SocialController.d.mts.map +1 -0
- package/dist/SocialController.mjs +122 -0
- package/dist/SocialController.mjs.map +1 -0
- package/dist/SocialService-method-action-types.cjs +7 -0
- package/dist/SocialService-method-action-types.cjs.map +1 -0
- package/dist/SocialService-method-action-types.d.cts +125 -0
- package/dist/SocialService-method-action-types.d.cts.map +1 -0
- package/dist/SocialService-method-action-types.d.mts +125 -0
- package/dist/SocialService-method-action-types.d.mts.map +1 -0
- package/dist/SocialService-method-action-types.mjs +6 -0
- package/dist/SocialService-method-action-types.mjs.map +1 -0
- package/dist/SocialService.cjs +430 -0
- package/dist/SocialService.cjs.map +1 -0
- package/dist/SocialService.d.cts +113 -0
- package/dist/SocialService.d.cts.map +1 -0
- package/dist/SocialService.d.mts +113 -0
- package/dist/SocialService.d.mts.map +1 -0
- package/dist/SocialService.mjs +426 -0
- package/dist/SocialService.mjs.map +1 -0
- package/dist/index.cjs +9 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +8 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -9
- package/dist/index.mjs.map +1 -1
- package/dist/social-constants.cjs +24 -0
- package/dist/social-constants.cjs.map +1 -0
- package/dist/social-constants.d.cts +21 -0
- package/dist/social-constants.d.cts.map +1 -0
- package/dist/social-constants.d.mts +21 -0
- package/dist/social-constants.d.mts.map +1 -0
- package/dist/social-constants.mjs +21 -0
- package/dist/social-constants.mjs.map +1 -0
- package/dist/social-types.cjs +6 -0
- package/dist/social-types.cjs.map +1 -0
- package/dist/social-types.d.cts +206 -0
- package/dist/social-types.d.cts.map +1 -0
- package/dist/social-types.d.mts +206 -0
- package/dist/social-types.d.mts.map +1 -0
- package/dist/social-types.mjs +5 -0
- package/dist/social-types.mjs.map +1 -0
- package/package.json +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
-
- Initial release ([#8321](https://github.com/MetaMask/core/pull/8321))
|
|
12
|
+
- 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))
|
|
13
|
+
- Add `SocialService` data service wrapping social-api endpoints with superstruct response validation
|
|
14
|
+
- Add methods `fetchLeaderboard`, `fetchTraderProfile`, `fetchOpenPositions`, `fetchClosedPositions`, `fetchFollowers`, `fetchFollowing`, `follow`, `unfollow`
|
|
15
|
+
- Add `SocialController` extending `BaseController` with messenger actions for state management
|
|
16
|
+
- `updateLeaderboard` — fetches leaderboard and persists entries to state
|
|
17
|
+
- `followTrader` — follows traders and updates following addresses in state
|
|
18
|
+
- `unfollowTrader` — unfollows traders and removes addresses from state
|
|
19
|
+
- `updateFollowing` — fetches following list and replaces addresses in state
|
|
13
20
|
|
|
14
21
|
[Unreleased]: https://github.com/MetaMask/core/
|
|
@@ -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 @@
|
|
|
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,127 @@
|
|
|
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 = followResponse.followed.map((profile) => profile.address);
|
|
87
|
+
this.update((state) => {
|
|
88
|
+
const existing = new Set(state.followingAddresses);
|
|
89
|
+
const uniqueNewAddresses = newAddresses.filter((address) => !existing.has(address));
|
|
90
|
+
state.followingAddresses.push(...uniqueNewAddresses);
|
|
91
|
+
});
|
|
92
|
+
return followResponse;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Unfollows one or more traders and updates the following list in state.
|
|
96
|
+
*
|
|
97
|
+
* @param options - Options bag.
|
|
98
|
+
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
99
|
+
* @param options.targets - Addresses or profile IDs to unfollow.
|
|
100
|
+
* @returns The unfollow response with confirmed unfollows.
|
|
101
|
+
*/
|
|
102
|
+
async unfollowTrader(options) {
|
|
103
|
+
const unfollowResponse = await this.messenger.call('SocialService:unfollow', options);
|
|
104
|
+
const removedAddresses = new Set(unfollowResponse.unfollowed.map((profile) => profile.address));
|
|
105
|
+
this.update((state) => {
|
|
106
|
+
state.followingAddresses = state.followingAddresses.filter((address) => !removedAddresses.has(address));
|
|
107
|
+
});
|
|
108
|
+
return unfollowResponse;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Fetches the list of traders the current user follows and replaces
|
|
112
|
+
* the following addresses in state.
|
|
113
|
+
*
|
|
114
|
+
* @param options - Options bag.
|
|
115
|
+
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
116
|
+
* @returns The following response.
|
|
117
|
+
*/
|
|
118
|
+
async updateFollowing(options) {
|
|
119
|
+
const followingResponse = await this.messenger.call('SocialService:fetchFollowing', options);
|
|
120
|
+
this.update((state) => {
|
|
121
|
+
state.followingAddresses = followingResponse.following.map((profile) => profile.address);
|
|
122
|
+
});
|
|
123
|
+
return followingResponse;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.SocialController = SocialController;
|
|
127
|
+
//# 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,wBAA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B,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACjD,8BAA8B,EAC9B,OAAO,CACR,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;QACJ,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 = followResponse.followed.map(\n (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,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,CAKvE;AAqBD;;;;;;;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;;;;;;;OAOG;IACG,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAqBnE;;;;;;;OAOG;IACG,cAAc,CAAC,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,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.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,q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B,CAAC;IAa/B;;;;;;;OAOG;IACG,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAqBnE;;;;;;;OAOG;IACG,cAAc,CAAC,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,122 @@
|
|
|
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 = followResponse.followed.map((profile) => profile.address);
|
|
83
|
+
this.update((state) => {
|
|
84
|
+
const existing = new Set(state.followingAddresses);
|
|
85
|
+
const uniqueNewAddresses = newAddresses.filter((address) => !existing.has(address));
|
|
86
|
+
state.followingAddresses.push(...uniqueNewAddresses);
|
|
87
|
+
});
|
|
88
|
+
return followResponse;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Unfollows one or more traders and updates the following list in state.
|
|
92
|
+
*
|
|
93
|
+
* @param options - Options bag.
|
|
94
|
+
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
95
|
+
* @param options.targets - Addresses or profile IDs to unfollow.
|
|
96
|
+
* @returns The unfollow response with confirmed unfollows.
|
|
97
|
+
*/
|
|
98
|
+
async unfollowTrader(options) {
|
|
99
|
+
const unfollowResponse = await this.messenger.call('SocialService:unfollow', options);
|
|
100
|
+
const removedAddresses = new Set(unfollowResponse.unfollowed.map((profile) => profile.address));
|
|
101
|
+
this.update((state) => {
|
|
102
|
+
state.followingAddresses = state.followingAddresses.filter((address) => !removedAddresses.has(address));
|
|
103
|
+
});
|
|
104
|
+
return unfollowResponse;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Fetches the list of traders the current user follows and replaces
|
|
108
|
+
* the following addresses in state.
|
|
109
|
+
*
|
|
110
|
+
* @param options - Options bag.
|
|
111
|
+
* @param options.addressOrUid - Wallet address or Clicker profile ID of the current user.
|
|
112
|
+
* @returns The following response.
|
|
113
|
+
*/
|
|
114
|
+
async updateFollowing(options) {
|
|
115
|
+
const followingResponse = await this.messenger.call('SocialService:fetchFollowing', options);
|
|
116
|
+
this.update((state) => {
|
|
117
|
+
state.followingAddresses = followingResponse.following.map((profile) => profile.address);
|
|
118
|
+
});
|
|
119
|
+
return followingResponse;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=SocialController.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocialController.mjs","sourceRoot":"","sources":["../src/SocialController.ts"],"names":[],"mappings":"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AE,EAAE,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,CAC5C,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,eAAe,CACnB,OAA8B;QAE9B,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACjD,8BAA8B,EAC9B,OAAO,CACR,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;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 };\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 = followResponse.followed.map(\n (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 @@
|
|
|
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 a user is following.\n *\n * Calls `GET ${baseUrl}/users/${addressOrUid}/following`.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID.\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.\n *\n * Calls `PUT ${baseUrl}/users/${addressOrUid}/follows`.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the user.\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.\n *\n * Calls `DELETE ${baseUrl}/users/${addressOrUid}/follows?targets=...`.\n * Targets are sent as query params because Fastify does not parse\n * request bodies on DELETE requests per RFC 9110.\n *\n * @param options - Options bag.\n * @param options.addressOrUid - Wallet address or Clicker profile ID of the user.\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"]}
|