Skip to content

Commit d802f93

Browse files
Merge pull request #685 from AlphadayHQ/dev
v3.8.0 - Polymarket Events Widget + Improvements
2 parents 962df85 + ec336b7 commit d802f93

File tree

14 files changed

+569
-306
lines changed

14 files changed

+569
-306
lines changed

packages/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@alphaday/frontend",
33
"private": true,
4-
"version": "3.7.2",
4+
"version": "3.8.0",
55
"type": "module",
66
"scripts": {
77
"prepare": "export VITE_COMMIT=$(git rev-parse --short HEAD)",

packages/frontend/src/api/hooks/useCustomAnalytics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export type TButtonClickEventPayload = {
1313
| "kasandra-disclaimer"
1414
| "kasandra-datapoint"
1515
| "polymarket-market"
16-
| "polymarket-top-volume";
16+
| "polymarket-top-volume"
17+
| "polymarket-event";
1718
data?: JSONValue;
1819
};
1920

packages/frontend/src/api/services/polymarket/polymarketEndpoints.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import type {
1313
TRawGetPolymarketMarketByTopVolumeResponse,
1414
TGetPolymarketMarketByTopVolumeRequest,
1515
TGetPolymarketMarketByTopVolumeResponse,
16-
TPolymarketMarketGroup,
16+
TRawPolymarketMarketEvent,
17+
TRawGetPolymarketMarketEventsResponse,
1718
} from "./types";
1819

1920
const { POLYMARKET } = CONFIG.API.DEFAULT.ROUTES;
2021

21-
const mapRawGetPolymarketMarketByTopVolumeResponse = (
22-
response: TRawGetPolymarketMarketByTopVolumeResponse
23-
): TPolymarketMarketGroup => {
22+
const mapRawGetPolymarketEvent = (
23+
response: TRawPolymarketMarketEvent
24+
): TPolymarketEvent => {
2425
return {
2526
id: response.id,
2627
title: response.title,
@@ -79,6 +80,17 @@ const polymarketApi = alphadayApi.injectEndpoints({
7980
return `${POLYMARKET.BASE}${POLYMARKET.EVENTS}?${params}`;
8081
},
8182
providesTags: ["PolymarketEvents"],
83+
transformResponse: (
84+
response: TRawGetPolymarketMarketEventsResponse
85+
) => {
86+
const events = response.results.map((event) =>
87+
mapRawGetPolymarketEvent(event)
88+
);
89+
return {
90+
...response,
91+
results: events,
92+
};
93+
},
8294
}),
8395

8496
getPolymarketEventById: builder.query<TPolymarketEvent, { id: number }>(
@@ -153,7 +165,7 @@ const polymarketApi = alphadayApi.injectEndpoints({
153165
transformResponse: (
154166
response: TRawGetPolymarketMarketByTopVolumeResponse
155167
) => {
156-
return mapRawGetPolymarketMarketByTopVolumeResponse(response);
168+
return mapRawGetPolymarketEvent(response);
157169
},
158170
}),
159171
}),

packages/frontend/src/api/services/polymarket/types.ts

Lines changed: 42 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,40 @@ import type { TPagination, TRemoteTagReadOnly } from "../baseTypes";
66

77
export type TPolymarketEvent = {
88
id: number;
9+
eventId: string;
910
title: string;
1011
description: string;
11-
category: string;
12-
created_at: string;
13-
updated_at: string;
14-
start_date: string | null;
15-
end_date: string | null;
16-
image: string | null;
1712
slug: string;
18-
tags: TRemoteTagReadOnly[];
13+
url: string;
14+
image: string;
15+
icon: string;
16+
category: string | null;
17+
active: boolean;
18+
createdAt: string;
19+
updatedAt: string;
20+
marketsCount: number;
21+
volume: number;
22+
markets: {
23+
id: number;
24+
marketId: string;
25+
question: string;
26+
active: boolean;
27+
closed: boolean;
28+
archived: boolean;
29+
volume: number;
30+
liquidity: number;
31+
image: string;
32+
category: string | null;
33+
endDate: string | null;
34+
outcomes: {
35+
id: number;
36+
outcomeName: string;
37+
outcomeId: string;
38+
price: number;
39+
volume: number;
40+
liquidity: number;
41+
}[];
42+
}[];
1943
};
2044

2145
export type TPolymarketOutcome = {
@@ -94,172 +118,15 @@ export type TPolymarketMarketGroup = {
94118
}[];
95119
};
96120

97-
// sample market in market group data
98-
export const sampleMarketData = {
99-
id: 611,
100-
market_id: "574073",
101-
question: "Will Bitcoin reach $170,000 by December 31, 2025?",
102-
active: true,
103-
closed: false,
104-
archived: false,
105-
volume_num: 790855.69,
106-
liquidity_num: 49062.87,
107-
image: "https://polymarket-upload.s3.us-east-2.amazonaws.com/BTC+fullsize.png",
108-
category: null,
109-
tags: [
110-
{
111-
id: 136,
112-
name: "bitcoin",
113-
slug: "bitcoin",
114-
keywords: [
115-
{
116-
id: 212,
117-
name: "BTC",
118-
is_excluded: false,
119-
ignore_trending: false,
120-
},
121-
{
122-
id: 7241,
123-
name: "Bitcoins",
124-
is_excluded: false,
125-
ignore_trending: false,
126-
},
127-
{
128-
id: 211,
129-
name: "Bitcoin",
130-
is_excluded: false,
131-
ignore_trending: false,
132-
},
133-
],
134-
parents: [
135-
{
136-
name: "chain",
137-
slug: "chain",
138-
keywords: [
139-
{
140-
id: 81379,
141-
name: "Chain",
142-
is_excluded: false,
143-
ignore_trending: true,
144-
},
145-
],
146-
},
147-
{
148-
name: "coin",
149-
slug: "coin",
150-
keywords: [],
151-
},
152-
{
153-
name: "layer1 (l1)",
154-
slug: "layer-1",
155-
keywords: [
156-
{
157-
id: 15830,
158-
name: "Layer1",
159-
is_excluded: false,
160-
ignore_trending: true,
161-
},
162-
{
163-
id: 15831,
164-
name: "Layer 1",
165-
is_excluded: false,
166-
ignore_trending: true,
167-
},
168-
{
169-
id: 15832,
170-
name: "L1",
171-
is_excluded: false,
172-
ignore_trending: true,
173-
},
174-
{
175-
id: 19257,
176-
name: "Layer 1s",
177-
is_excluded: false,
178-
ignore_trending: true,
179-
},
180-
],
181-
},
182-
{
183-
name: "pow",
184-
slug: "proof-of-work",
185-
keywords: [
186-
{
187-
id: 6714,
188-
name: "Proof of Work",
189-
is_excluded: false,
190-
ignore_trending: true,
191-
},
192-
{
193-
id: 12590,
194-
name: "Proof-of-Work",
195-
is_excluded: false,
196-
ignore_trending: true,
197-
},
198-
{
199-
id: 6715,
200-
name: "PoW",
201-
is_excluded: false,
202-
ignore_trending: true,
203-
},
204-
],
205-
},
206-
],
207-
},
208-
{
209-
id: 185485,
210-
name: "reach",
211-
slug: "reach",
212-
keywords: [
213-
{
214-
id: 70499,
215-
name: "Reach",
216-
is_excluded: false,
217-
ignore_trending: true,
218-
},
219-
{
220-
id: 70500,
221-
name: "$REACH",
222-
is_excluded: false,
223-
ignore_trending: true,
224-
},
225-
],
226-
parents: [],
227-
},
228-
],
229-
end_date: null,
230-
outcomes: [
231-
{
232-
id: 5571,
233-
outcome_name: "Yes",
234-
outcome_id:
235-
"54897787457036657865994456184914764553135864680096835028443076525607070890895",
236-
price: 0.085,
237-
volume: 67222.73,
238-
liquidity: 4170.34,
239-
created_at: "2025-10-15T16:01:21.753474Z",
240-
updated_at: "2025-10-15T16:01:21.816557Z",
241-
},
242-
{
243-
id: 5572,
244-
outcome_name: "No",
245-
outcome_id:
246-
"78805316555677329424627438782382022900925020552651782446877236048212682328103",
247-
price: 0.915,
248-
volume: 723632.95,
249-
liquidity: 44892.52,
250-
created_at: "2025-10-15T16:01:21.753487Z",
251-
updated_at: "2025-10-15T16:01:21.816583Z",
252-
},
253-
],
254-
};
255-
256121
/**
257122
* API Request/Response types
258123
*/
259124

260125
export type TGetPolymarketEventsRequest = {
261126
page?: number;
262127
limit?: number;
128+
active?: boolean;
129+
ordering?: string;
263130
category?: string;
264131
tags?: string;
265132
search?: string;
@@ -310,7 +177,9 @@ export type TGetPolymarketMarketByTopVolumeRequest = {
310177
ordering?: string;
311178
};
312179

313-
export type TRawGetPolymarketMarketByTopVolumeResponse = {
180+
export type TGetPolymarketMarketByTopVolumeResponse = TPolymarketEvent;
181+
182+
export type TRawPolymarketMarketEvent = {
314183
id: number;
315184
event_id: string;
316185
title: string;
@@ -350,4 +219,9 @@ export type TRawGetPolymarketMarketByTopVolumeResponse = {
350219
}[];
351220
};
352221

353-
export type TGetPolymarketMarketByTopVolumeResponse = TPolymarketMarketGroup;
222+
export type TRawGetPolymarketMarketByTopVolumeResponse =
223+
TRawPolymarketMarketEvent;
224+
225+
export type TRawGetPolymarketMarketEventsResponse = TPagination & {
226+
results: TRawPolymarketMarketEvent[];
227+
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { FC } from "react";
2+
import { CenteredBlock } from "@alphaday/ui-kit";
3+
import { useTranslation } from "react-i18next";
4+
import {
5+
TPolymarketMarket,
6+
TPolymarketMarketGroup,
7+
} from "src/api/services/polymarket/types";
8+
import PolymarketTopVolumeCard from "./PolymarketTopVolumeCard";
9+
10+
export interface IPolymarketEvents {
11+
markets: TPolymarketMarketGroup["markets"];
12+
onSelectMarket: (market: TPolymarketMarket) => void;
13+
onSelectEvent: () => void;
14+
}
15+
16+
const PolymarketEvents: FC<IPolymarketEvents> = ({
17+
markets,
18+
onSelectMarket,
19+
onSelectEvent,
20+
}) => {
21+
const { t } = useTranslation();
22+
23+
if (markets.length === 0) {
24+
return (
25+
<CenteredBlock>
26+
<p>{t("polymarket.noMarketsFound")}</p>
27+
</CenteredBlock>
28+
);
29+
}
30+
31+
return (
32+
<div className="relative pl-10 pr-[2px]">
33+
{markets.slice(0, 3).map((market) => (
34+
<PolymarketTopVolumeCard
35+
key={market.id}
36+
market={market}
37+
onSelectMarket={onSelectMarket}
38+
isSingleMarket={markets.length === 1}
39+
/>
40+
))}
41+
{markets.length > 3 && (
42+
<div className="-bottom-2 absolute -translate-x-1/2 left-1/2 flex items-center justify-center">
43+
<button
44+
type="button"
45+
className="text-accentVariant100 px-2 bg-background"
46+
onClick={() => onSelectEvent?.()}
47+
>
48+
{t("navigation.general.more")}
49+
</button>
50+
</div>
51+
)}
52+
</div>
53+
);
54+
};
55+
56+
export default PolymarketEvents;

0 commit comments

Comments
 (0)