Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/social-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions packages/social-controllers/src/SocialService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const mockSocialHandles = {

const mockTrade = {
direction: 'buy',
intent: 'enter',
tokenAmount: 1.5,
usdCost: 3000,
timestamp: 1700000000,
Expand Down
9 changes: 1 addition & 8 deletions packages/social-controllers/src/SocialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import type {
UnfollowOptions,
UnfollowResponse,
} from './social-types';
import { TradeStruct } from './social-types';
import type { SocialServiceMethodActions } from './SocialService-method-action-types';

// ---------------------------------------------------------------------------
Expand All @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions packages/social-controllers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type {
SocialServiceUnfollowAction,
} from './SocialService-method-action-types';

export { TradeStruct } from './social-types';
export type {
FetchFollowersOptions,
FetchFollowingOptions,
Expand Down
35 changes: 20 additions & 15 deletions packages/social-controllers/src/social-types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import type { Infer } from '@metamask/superstruct';
import {
enums,
number,
optional,
string,
type as structType,
} from '@metamask/superstruct';

// ---------------------------------------------------------------------------
// Shared sub-types
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -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<typeof TradeStruct>;

// ---------------------------------------------------------------------------
// Leaderboard
Expand Down
Loading