diff --git a/packages/social-controllers/CHANGELOG.md b/packages/social-controllers/CHANGELOG.md index 0a6a607f260..8c8da7efed5 100644 --- a/packages/social-controllers/CHANGELOG.md +++ b/packages/social-controllers/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add `intent` and optional `category` fields to `Trade` type ([#8410](https://github.com/MetaMask/core/pull/8410)) +- Export `TradeStruct` superstruct schema; derive `Trade` type via `Infer` ([#8410](https://github.com/MetaMask/core/pull/8410)) +- Narrow `direction` to `'buy' | 'sell'` and `intent` to `'enter' | 'exit'` on `Trade` type ([#8410](https://github.com/MetaMask/core/pull/8410)) + ### Changed - Bump `@metamask/messenger` from `^1.1.0` to `^1.1.1` ([#8373](https://github.com/MetaMask/core/pull/8373)) diff --git a/packages/social-controllers/src/SocialService.test.ts b/packages/social-controllers/src/SocialService.test.ts index fa7c40b95b1..eb8ad32f1ce 100644 --- a/packages/social-controllers/src/SocialService.test.ts +++ b/packages/social-controllers/src/SocialService.test.ts @@ -24,6 +24,7 @@ const mockSocialHandles = { const mockTrade = { direction: 'buy', + intent: 'enter', tokenAmount: 1.5, usdCost: 3000, timestamp: 1700000000, diff --git a/packages/social-controllers/src/SocialService.ts b/packages/social-controllers/src/SocialService.ts index 4d043bcdbcd..7c753b22203 100644 --- a/packages/social-controllers/src/SocialService.ts +++ b/packages/social-controllers/src/SocialService.ts @@ -36,6 +36,7 @@ import type { UnfollowOptions, UnfollowResponse, } from './social-types'; +import { TradeStruct } from './social-types'; import type { SocialServiceMethodActions } from './SocialService-method-action-types'; // --------------------------------------------------------------------------- @@ -56,14 +57,6 @@ const ProfileSummaryStruct = structType({ imageUrl: optional(nullable(string())), }); -const TradeStruct = structType({ - direction: string(), - tokenAmount: number(), - usdCost: number(), - timestamp: number(), - transactionHash: string(), -}); - const PositionStruct = structType({ tokenSymbol: string(), tokenName: string(), diff --git a/packages/social-controllers/src/index.ts b/packages/social-controllers/src/index.ts index 021b9f57c5e..3409ec72c49 100644 --- a/packages/social-controllers/src/index.ts +++ b/packages/social-controllers/src/index.ts @@ -36,6 +36,7 @@ export type { SocialServiceUnfollowAction, } from './SocialService-method-action-types'; +export { TradeStruct } from './social-types'; export type { FetchFollowersOptions, FetchFollowingOptions, diff --git a/packages/social-controllers/src/social-types.ts b/packages/social-controllers/src/social-types.ts index effd7a3e1d7..e80b9abd57e 100644 --- a/packages/social-controllers/src/social-types.ts +++ b/packages/social-controllers/src/social-types.ts @@ -1,3 +1,12 @@ +import type { Infer } from '@metamask/superstruct'; +import { + enums, + number, + optional, + string, + type as structType, +} from '@metamask/superstruct'; + // --------------------------------------------------------------------------- // Shared sub-types // --------------------------------------------------------------------------- @@ -26,21 +35,17 @@ export type SocialHandles = { lens?: string | null; }; -/** - * A single trade within a position. - */ -export type Trade = { - /** "buy" or "sell". */ - direction: string; - /** Quantity traded. */ - tokenAmount: number; - /** USD value of the trade. */ - usdCost: number; - /** Unix timestamp. */ - timestamp: number; - /** On-chain transaction hash. */ - transactionHash: string; -}; +export const TradeStruct = structType({ + direction: enums(['buy', 'sell']), + intent: enums(['enter', 'exit']), + category: optional(string()), + tokenAmount: number(), + usdCost: number(), + timestamp: number(), + transactionHash: string(), +}); + +export type Trade = Infer; // --------------------------------------------------------------------------- // Leaderboard