@orderly.network/ui-notification 2.8.2-alpha.0

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/dist/index.js ADDED
@@ -0,0 +1,853 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var i18n = require('@orderly.network/i18n');
5
+ var ui = require('@orderly.network/ui');
6
+ var types = require('@orderly.network/types');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
+ var utc = require('@date-fns/utc');
9
+ var dateFns = require('date-fns');
10
+ var immer = require('immer');
11
+ var hooks = require('@orderly.network/hooks');
12
+ var reactApp = require('@orderly.network/react-app');
13
+ var utils = require('@orderly.network/utils');
14
+
15
+ // src/components/announcementCenter/announcementCenter.ui.tsx
16
+ var BattleIcon = (props) => {
17
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Icon, { size: 18, viewBox: "0 0 18 18", ...props, children: [
18
+ /* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsxs(
19
+ "linearGradient",
20
+ {
21
+ id: "paint0_linear_555_7374",
22
+ x1: "17.0157",
23
+ y1: "9.26513",
24
+ x2: "0.969849",
25
+ y2: "9.26513",
26
+ gradientUnits: "userSpaceOnUse",
27
+ children: [
28
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "rgb(var(--oui-gradient-brand-end))" }),
29
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "1", stopColor: "rgb(var(--oui-gradient-brand-start))" })
30
+ ]
31
+ }
32
+ ) }),
33
+ /* @__PURE__ */ jsxRuntime.jsx(
34
+ "path",
35
+ {
36
+ fill: "url(#paint0_linear_555_7374)",
37
+ fillOpacity: 1,
38
+ d: "m1.5 1.5.75 3 4.843 4.56-1.808 1.919-.63-.633-1.06 1.06.665.665-1.88 1.996-.35-.346-1.06 1.06 2.25 2.25 1.06-1.06-.348-.349 1.998-1.878.665.662 1.06-1.06-.63-.63L9 10.852l1.969 1.854-.639.639 1.06 1.06.672-.67 1.998 1.877-.358.358 1.064 1.06 2.25-2.25-1.06-1.06-.34.34-1.881-1.998.656-.657-1.06-1.06-.625.624-1.799-1.91.003-.003L9 7.03 4.5 2.25zm15 0-3 .75-3.636 3.861 2.022 2.025L15.75 4.5z"
39
+ }
40
+ )
41
+ ] });
42
+ };
43
+ var CampaignIcon = (props) => {
44
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { size: 18, viewBox: "0 0 18 18", ...props, children: /* @__PURE__ */ jsxRuntime.jsx(
45
+ "path",
46
+ {
47
+ fill: "currentcolor",
48
+ fillOpacity: 1,
49
+ d: "m1.5 1.5.75 3 4.843 4.56-1.808 1.919-.63-.633-1.06 1.06.665.665-1.88 1.996-.35-.346-1.06 1.06 2.25 2.25 1.06-1.06-.348-.349 1.998-1.878.665.662 1.06-1.06-.63-.63L9 10.852l1.969 1.854-.639.639 1.06 1.06.672-.67 1.998 1.877-.358.358 1.064 1.06 2.25-2.25-1.06-1.06-.34.34-1.881-1.998.656-.657-1.06-1.06-.625.624-1.799-1.91.003-.003L9 7.03 4.5 2.25zm15 0-3 .75-3.636 3.861 2.022 2.025L15.75 4.5z"
50
+ }
51
+ ) });
52
+ };
53
+ var ArrowRightShortIcon = (props) => {
54
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Icon, { size: 18, viewBox: "0 0 18 18", ...props, children: [
55
+ /* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsxs(
56
+ "linearGradient",
57
+ {
58
+ id: "paint0_linear_555_7374",
59
+ x1: "17.0157",
60
+ y1: "9.26513",
61
+ x2: "0.969849",
62
+ y2: "9.26513",
63
+ gradientUnits: "userSpaceOnUse",
64
+ children: [
65
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "rgb(var(--oui-gradient-brand-end))" }),
66
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "1", stopColor: "rgb(var(--oui-gradient-brand-start))" })
67
+ ]
68
+ }
69
+ ) }),
70
+ /* @__PURE__ */ jsxRuntime.jsx(
71
+ "path",
72
+ {
73
+ fill: "url(#paint0_linear_555_7374)",
74
+ fillOpacity: 1,
75
+ d: "M4.509 8.995a.75.75 0 0 1 .75-.75h5.666L8.7 5.998l1.054-1.054 3.535 3.512c.147.146.22.343.22.54a.76.76 0 0 1-.22.537l-3.535 3.512L8.7 11.992l2.225-2.248H5.258a.75.75 0 0 1-.749-.75"
76
+ }
77
+ )
78
+ ] });
79
+ };
80
+ var FundIcon = (props) => {
81
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { size: 18, viewBox: "0 0 18 18", ...props, children: /* @__PURE__ */ jsxRuntime.jsx(
82
+ "path",
83
+ {
84
+ fill: "currentcolor",
85
+ fillOpacity: 0.8,
86
+ d: "M15.694 7.087c-.788-.393-1.857-.618-2.925-.618-1.125 0-2.138.225-2.925.618-.056 0-.113.057-.113.057V3.769c0-.9-.731-1.575-1.462-1.913-.788-.394-1.857-.619-2.925-.619-1.069 0-2.25.225-3.038.62C1.575 2.193.844 2.868.844 3.768v10.519c0 .9.731 1.575 1.462 1.912.788.394 1.856.619 2.925.619s2.138-.225 2.925-.619c.281-.169.563-.337.788-.562.225.225.506.393.787.562.788.394 1.857.619 2.925.619 1.125 0 2.138-.225 2.925-.619.732-.394 1.463-1.012 1.463-1.912V9c.112-.9-.619-1.519-1.35-1.913m-7.369 7.144c0 .113-.112.45-.731.732-.563.28-1.407.506-2.363.506s-1.8-.169-2.362-.506c-.619-.282-.731-.62-.731-.732V13.5c.056 0 .112 0 .168.056.788.394 1.856.619 2.925.619s2.138-.225 2.925-.619c.056 0 .113-.056.113-.056v.731zm0-2.587c0 .112-.112.45-.731.731-.563.281-1.407.506-2.363.506s-1.8-.168-2.362-.506c-.619-.281-.731-.619-.731-.731v-.788c.056 0 .112.056.112.056.788.394 1.856.62 2.925.62s2.138-.226 2.925-.62c.056 0 .113-.056.113-.056v.788zm0-2.644c0 .112-.112.45-.731.731-.563.281-1.407.507-2.363.507s-1.8-.17-2.362-.507C2.25 9.45 2.138 9.112 2.138 9v-.788c.056 0 .112.057.112.057.788.393 1.856.618 2.925.618S7.313 8.662 8.1 8.27c.056 0 .113-.057.113-.057V9zm0-2.644c0 .113-.112.45-.731.731-.563.282-1.407.507-2.363.507s-1.8-.169-2.362-.507c-.619-.28-.731-.618-.731-.73v-.732c.056 0 .112 0 .168.056.788.394 1.856.619 2.925.619s2.138-.225 2.925-.619c.056 0 .113-.056.113-.056v.731zM7.594 4.5c-.563.281-1.407.506-2.363.506S3.488 4.781 2.925 4.5c-.619-.338-.731-.619-.731-.731 0-.113.112-.45.731-.732.563-.28 1.406-.506 2.363-.506.956 0 1.8.169 2.362.506.619.282.731.62.731.732-.056.112-.168.393-.787.731m8.212 9.731c0 .113-.112.45-.731.732-.562.28-1.406.506-2.362.506s-1.8-.169-2.363-.506c-.619-.282-.731-.62-.731-.732V13.5c.056 0 .112.056.112.056.788.394 1.857.619 2.925.619 1.125 0 2.138-.225 2.925-.619.056 0 .113-.056.113-.056v.731zm0-2.587c0 .112-.112.45-.731.731-.562.281-1.406.506-2.362.506s-1.8-.168-2.363-.506c-.619-.281-.731-.619-.731-.731v-.788c.056 0 .112.056.112.056.788.394 1.857.62 2.925.62 1.125 0 2.138-.226 2.925-.62.056 0 .113-.056.113-.056v.788zm-.675-1.913c-.562.281-1.406.507-2.362.507s-1.8-.17-2.363-.507c-.619-.281-.731-.619-.731-.731 0-.113.112-.45.731-.731.563-.282 1.406-.507 2.363-.507.956 0 1.8.17 2.362.507.619.281.732.618.732.731-.057.112-.17.45-.732.731"
87
+ }
88
+ ) });
89
+ };
90
+ var AnnouncementIcon = (props) => {
91
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { size: 18, viewBox: "0 0 18 18", ...props, children: /* @__PURE__ */ jsxRuntime.jsx(
92
+ "path",
93
+ {
94
+ fill: "currentcolor",
95
+ fillOpacity: 0.8,
96
+ d: "M11.53 2.255a.745.745 0 0 0-.82.165c-.525.524-1.188.959-1.947 1.284-.77.33-2.353.757-3.508.75-2.248-.015-3.756 1.259-3.756 3.726 0 2.163 1.228 3.42 2.994 3.703l.006 1.565a2.25 2.25 0 0 0 2.25 2.247c1.142 0 2.083-.883 2.228-1.988.007-.053.022-.26.022-1.01.674.315 1.232.812 1.711 1.29.473.472 1.29.13 1.29-.538 0-.678-.004-1.906-.004-3.13.884-.327 1.503-1.165 1.503-2.115s-.585-1.81-1.496-2.129c0-1.225-.004-2.439-.004-3.117a.76.76 0 0 0-.469-.703m1.805 1.335a.73.73 0 0 0-.445.351.75.75 0 0 0 .258 1.03 3.74 3.74 0 0 1 1.851 3.233 3.74 3.74 0 0 1-1.851 3.231.76.76 0 0 0-.282 1.03.754.754 0 0 0 1.032.258 5.24 5.24 0 0 0 2.601-4.52 5.24 5.24 0 0 0-2.601-4.519.74.74 0 0 0-.563-.094m-2.832.884c0 .694-.004 1.417-.004 2.231v2.997c0 .815.003 1.508.003 2.202-1.52-.896-3.085-1.294-4.501-1.421 0-1.144-.004-3.406-.004-4.584.147-.007.318-.026.565-.06a11.2 11.2 0 0 0 2.812-.773c.43-.184.75-.35 1.129-.592m-6.005 1.55-.001 4.34c-.976-.27-1.498-.959-1.498-2.184 0-1.21.47-1.928 1.499-2.155M6 11.998c.238.008 1.098.161 1.493.261l.007 1.19a.75.75 0 0 1-1.5 0z"
97
+ }
98
+ ) });
99
+ };
100
+ var SecurityIcon = (props) => {
101
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Icon, { size: 18, viewBox: "0 0 18 18", ...props, children: [
102
+ /* @__PURE__ */ jsxRuntime.jsx(
103
+ "path",
104
+ {
105
+ d: "M6.563 7.678V6.603c0-1.153 1.09-2.088 2.437-2.088s2.438.935 2.438 2.088v1.075c.448 0 .812.311.812.696v3.479c0 .384-.364.696-.812.696H6.563c-.449 0-.813-.312-.813-.696v-3.48c0-.384.364-.695.813-.695m1.187-.006 1.431.006h1.07V6.564c0-.64-.504-1.104-1.25-1.104-.748 0-1.25.465-1.25 1.104zm1.956 2.14c0-.335-.317-.605-.706-.605-.39 0-.706.27-.706.604v.77c0 .335.316.605.706.605s.706-.27.706-.604z",
106
+ fill: "currentcolor",
107
+ fillOpacity: ".8"
108
+ }
109
+ ),
110
+ /* @__PURE__ */ jsxRuntime.jsx(
111
+ "path",
112
+ {
113
+ d: "M2 3.607c.003 5.606.146 11.651 6.879 13.378.078.02.164.02.242 0C15.854 15.258 15.997 9.213 16 3.607c0-.217-.14-.41-.345-.477L9.31 1.05a1 1 0 0 0-.62 0L2.345 3.13A.5.5 0 0 0 2 3.607m2.326 7.63c-.707-1.954-.81-4.33-.824-6.902L9 2.532l5.498 1.803c-.014 2.573-.117 4.948-.824 6.901-.697 1.93-1.987 3.463-4.674 4.222-2.687-.759-3.977-2.293-4.674-4.222",
114
+ fill: "currentcolor",
115
+ fillOpacity: ".8"
116
+ }
117
+ )
118
+ ] });
119
+ };
120
+ var AnnouncementItem = (props) => {
121
+ const { t } = i18n.useTranslation();
122
+ const Icon2 = react.useMemo(() => {
123
+ switch (props.type) {
124
+ case types.AnnouncementType.Campaign:
125
+ return CampaignIcon;
126
+ case types.AnnouncementType.Listing:
127
+ return FundIcon;
128
+ case types.AnnouncementType.Maintenance:
129
+ return SecurityIcon;
130
+ case types.AnnouncementType.Delisting:
131
+ default:
132
+ return AnnouncementIcon;
133
+ }
134
+ }, [props.type]);
135
+ const title = react.useMemo(() => {
136
+ switch (props.type) {
137
+ case types.AnnouncementType.Campaign:
138
+ return t("notification.campaign");
139
+ case types.AnnouncementType.Delisting:
140
+ return t("notification.delisting");
141
+ case types.AnnouncementType.Listing:
142
+ return t("notification.listing");
143
+ case types.AnnouncementType.Maintenance:
144
+ return t("notification.maintenance");
145
+ default:
146
+ return t("notification.general");
147
+ }
148
+ }, [props.type, t]);
149
+ const action = react.useMemo(() => {
150
+ if (props.type === types.AnnouncementType.Campaign && typeof props.url === "string" && props.url !== "" && typeof props.onItemClick === "function") {
151
+ return /* @__PURE__ */ jsxRuntime.jsxs(
152
+ ui.Flex,
153
+ {
154
+ gap: 1,
155
+ itemAlign: "center",
156
+ className: "oui-cursor-pointer",
157
+ onClick: (event) => {
158
+ event.stopPropagation();
159
+ props.onItemClick(props.url);
160
+ },
161
+ children: [
162
+ /* @__PURE__ */ jsxRuntime.jsx(
163
+ ui.Text,
164
+ {
165
+ size: "xs",
166
+ color: "buy",
167
+ className: "oui-bg-clip-text oui-text-transparent oui-gradient-brand",
168
+ children: t("notification.joinNow")
169
+ }
170
+ ),
171
+ /* @__PURE__ */ jsxRuntime.jsx(ArrowRightShortIcon, { size: 18 })
172
+ ]
173
+ }
174
+ );
175
+ }
176
+ return null;
177
+ }, [props.type, props.url, t]);
178
+ const updateTime = react.useMemo(() => {
179
+ if (props.type === types.AnnouncementType.Maintenance) {
180
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "2xs", intensity: 36, children: t("notification.recentlyUpdated") });
181
+ }
182
+ return /* @__PURE__ */ jsxRuntime.jsx(
183
+ ui.Text.formatted,
184
+ {
185
+ size: "2xs",
186
+ intensity: 36,
187
+ rule: "date",
188
+ formatString: "yyyy-MM-dd HH:mm:ss",
189
+ children: props.updatedTime
190
+ }
191
+ );
192
+ }, [props.updatedTime, props.type, t]);
193
+ return /* @__PURE__ */ jsxRuntime.jsxs(
194
+ ui.Flex,
195
+ {
196
+ gap: 2,
197
+ itemAlign: "start",
198
+ className: ui.cn(
199
+ "oui-px-2 oui-py-[6px] oui-text-base-contrast-80",
200
+ !props.showDivider && "oui-rounded-md hover:oui-bg-base-6",
201
+ !props.showDivider && props.expanded && "oui-bg-base-6",
202
+ props.className
203
+ ),
204
+ onClick: () => {
205
+ props.onExpandToggle?.();
206
+ },
207
+ children: [
208
+ /* @__PURE__ */ jsxRuntime.jsx(Icon2, { color: "white", className: "oui-mt-3 oui-shrink-0" }),
209
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", itemAlign: "start", grow: true, children: [
210
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xs", intensity: 80, weight: "bold", children: title }),
211
+ updateTime,
212
+ /* @__PURE__ */ jsxRuntime.jsx(
213
+ "div",
214
+ {
215
+ className: "oui-grid oui-transition-all oui-duration-300 oui-ease-in-out",
216
+ style: {
217
+ gridTemplateRows: props.expanded ? "1fr" : "0fr"
218
+ },
219
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-flex oui-flex-col oui-gap-2 oui-overflow-hidden", children: [
220
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "2xs", intensity: 80, as: "div", className: "oui-pt-2", children: props.message }),
221
+ action
222
+ ] })
223
+ }
224
+ )
225
+ ] }),
226
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-pt-3", children: /* @__PURE__ */ jsxRuntime.jsx(
227
+ ui.ChevronDownIcon,
228
+ {
229
+ color: "white",
230
+ size: 18,
231
+ className: `oui-transition-transform oui-duration-300 oui-ease-in-out ${props.expanded ? "oui-rotate-180" : "oui-rotate-0"}`
232
+ }
233
+ ) })
234
+ ]
235
+ }
236
+ );
237
+ };
238
+ var AnnouncementContent = (props) => {
239
+ const { dataSource, current, onExpandToggle, onItemClick } = props;
240
+ const { t } = i18n.useTranslation();
241
+ if (!Array.isArray(dataSource) || dataSource.length === 0) {
242
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-flex oui-h-[160px] oui-items-center oui-justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
243
+ ui.ExtensionSlot,
244
+ {
245
+ position: ui.ExtensionPositionEnum.EmptyDataIdentifier,
246
+ title: t("notification.empty")
247
+ }
248
+ ) });
249
+ }
250
+ return /* @__PURE__ */ jsxRuntime.jsx(
251
+ "div",
252
+ {
253
+ className: ui.cn(
254
+ "p-5 oui-flex oui-flex-col oui-space-y-1",
255
+ props.showDivider && "[&>*:not(:first-child)]:oui-border-t [&>*:not(:first-child)]:oui-border-line-12 [&>*:not(:first-child)]:oui-pt-1"
256
+ ),
257
+ children: dataSource.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
258
+ AnnouncementItem,
259
+ {
260
+ url: item.url,
261
+ onItemClick,
262
+ message: item.message,
263
+ updatedTime: item.updated_time ?? 0,
264
+ expanded: current === item.announcement_id,
265
+ type: item.type,
266
+ showDivider: props.showDivider,
267
+ onExpandToggle: () => {
268
+ if (current === item.announcement_id) {
269
+ onExpandToggle(null);
270
+ } else {
271
+ onExpandToggle(item.announcement_id);
272
+ }
273
+ }
274
+ },
275
+ item.announcement_id
276
+ ))
277
+ }
278
+ );
279
+ };
280
+ var AnnouncementCenterUI = (props) => {
281
+ const { t } = i18n.useTranslation();
282
+ const [expanded, setExpanded] = react.useState(null);
283
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
284
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-px-5 oui-pt-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { intensity: 80, weight: "bold", children: t("notification.title") }) }),
285
+ /* @__PURE__ */ jsxRuntime.jsx(ui.ScrollArea, { className: "oui-flex oui-h-[300px] oui-flex-col oui-space-y-1 oui-p-3", children: /* @__PURE__ */ jsxRuntime.jsx(
286
+ AnnouncementContent,
287
+ {
288
+ dataSource: props.dataSource,
289
+ current: expanded,
290
+ onExpandToggle: setExpanded,
291
+ onItemClick: props.onItemClick
292
+ }
293
+ ) })
294
+ ] });
295
+ };
296
+ var CampaignContentCard = ({ message, coverImage, url, onItemClick }) => {
297
+ const { t } = i18n.useTranslation();
298
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-flex oui-flex-col oui-gap-5", children: [
299
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", weight: "bold", children: message }),
300
+ /* @__PURE__ */ jsxRuntime.jsx(
301
+ "div",
302
+ {
303
+ className: "oui-rounded-xl oui-bg-base-9 oui-bg-cover oui-bg-center oui-bg-no-repeat",
304
+ style: {
305
+ backgroundImage: `url(${coverImage})`,
306
+ height: "100px"
307
+ }
308
+ }
309
+ ),
310
+ typeof url === "string" && url !== "" && typeof onItemClick === "function" && /* @__PURE__ */ jsxRuntime.jsxs(
311
+ "button",
312
+ {
313
+ className: "oui-flex oui-items-center oui-gap-1",
314
+ onClick: () => onItemClick(url),
315
+ children: [
316
+ /* @__PURE__ */ jsxRuntime.jsx(
317
+ ui.Text,
318
+ {
319
+ size: "xs",
320
+ color: "buy",
321
+ className: "oui-bg-clip-text oui-text-transparent oui-gradient-brand",
322
+ children: t("notification.joinNow")
323
+ }
324
+ ),
325
+ /* @__PURE__ */ jsxRuntime.jsx(ArrowRightShortIcon, { size: 18, color: "success" })
326
+ ]
327
+ }
328
+ )
329
+ ] });
330
+ };
331
+ var MaintenanceContentCard = ({ message, startTime, endTime }) => {
332
+ const { t } = i18n.useTranslation();
333
+ const formattedMessage = react.useMemo(() => {
334
+ const hours = dateFns.differenceInHours(endTime, startTime);
335
+ const startUtc = new utc.UTCDate(startTime);
336
+ const endUtc = new utc.UTCDate(endTime);
337
+ const startTimeFormatted = dateFns.format(startUtc, "HH:mm");
338
+ const endTimeFormatted = dateFns.format(endUtc, "hh:mm a");
339
+ return t("notification.maintenanceDuration", {
340
+ hours,
341
+ startTimeFormatted,
342
+ endTimeFormatted
343
+ });
344
+ }, [startTime, endTime, t]);
345
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-flex oui-flex-col oui-gap-1", children: [
346
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xs", intensity: 54, children: t("notification.recentlyUpdated") }),
347
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { itemAlign: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xs", weight: "bold", children: formattedMessage }) }),
348
+ message && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "2xs", intensity: 80, as: "div", className: "oui-mt-2", children: message })
349
+ ] });
350
+ };
351
+ var DelistingContentCard = ({ message, updateTime }) => {
352
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-flex oui-flex-col oui-gap-1", children: [
353
+ /* @__PURE__ */ jsxRuntime.jsx(
354
+ ui.Text.formatted,
355
+ {
356
+ rule: "date",
357
+ intensity: 54,
358
+ formatString: "yyyy-MM-dd HH:mm:ss",
359
+ size: "xs",
360
+ children: updateTime
361
+ }
362
+ ),
363
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", weight: "bold", children: message })
364
+ ] });
365
+ };
366
+ var ListingContentCard = ({ message, updateTime }) => {
367
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-flex oui-flex-col oui-gap-1", children: [
368
+ /* @__PURE__ */ jsxRuntime.jsx(
369
+ ui.Text.formatted,
370
+ {
371
+ rule: "date",
372
+ intensity: 54,
373
+ formatString: "yyyy-MM-dd HH:mm:ss",
374
+ size: "xs",
375
+ children: updateTime
376
+ }
377
+ ),
378
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", weight: "bold", children: message })
379
+ ] });
380
+ };
381
+ var NotificationHeader = (props) => {
382
+ const { t } = i18n.useTranslation();
383
+ const { expanded } = props;
384
+ const { type } = props.dataSource[props.current];
385
+ const title = react.useMemo(() => {
386
+ switch (type) {
387
+ case types.AnnouncementType.Campaign:
388
+ return /* @__PURE__ */ jsxRuntime.jsx(
389
+ ui.Text,
390
+ {
391
+ size: "sm",
392
+ className: "oui-text-transparent oui-bg-clip-text oui-gradient-brand",
393
+ children: t("notification.campaignTitle")
394
+ }
395
+ );
396
+ case types.AnnouncementType.Delisting:
397
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", children: t("notification.delistingTitle") });
398
+ case types.AnnouncementType.Listing:
399
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", color: "buy", children: t("notification.listing") });
400
+ case types.AnnouncementType.Maintenance:
401
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", color: "warning", children: t("notification.maintenanceTitle") });
402
+ default:
403
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", color: "inherit", children: t("notification.generalTitle") });
404
+ }
405
+ }, [type, t]);
406
+ const icon = react.useMemo(() => {
407
+ switch (type) {
408
+ case types.AnnouncementType.Campaign:
409
+ return /* @__PURE__ */ jsxRuntime.jsx(BattleIcon, { color: "white" });
410
+ case types.AnnouncementType.Listing:
411
+ return /* @__PURE__ */ jsxRuntime.jsx(FundIcon, { color: "success" });
412
+ case types.AnnouncementType.Maintenance:
413
+ return /* @__PURE__ */ jsxRuntime.jsx(SecurityIcon, { color: "warning" });
414
+ case types.AnnouncementType.Delisting:
415
+ default:
416
+ return /* @__PURE__ */ jsxRuntime.jsx(AnnouncementIcon, { color: "white" });
417
+ }
418
+ }, [type]);
419
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { itemAlign: "center", justify: "between", className: "oui-px-4 oui-py-3", children: [
420
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "orderly-notification-header oui-flex oui-items-center oui-gap-2", children: [
421
+ icon,
422
+ title
423
+ ] }),
424
+ /* @__PURE__ */ jsxRuntime.jsx(
425
+ "button",
426
+ {
427
+ onClick: props.onExpandToggle,
428
+ className: "oui-transition-transform oui-duration-300",
429
+ style: {
430
+ transform: !expanded ? "rotate(180deg)" : "rotate(0deg)"
431
+ },
432
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.ChevronDownIcon, { size: 18, color: "white" })
433
+ }
434
+ )
435
+ ] });
436
+ };
437
+ var NotificationFooter = (props) => {
438
+ const { total, current, onCloseAll, onPrev, onNext } = props;
439
+ const { t } = i18n.useTranslation();
440
+ return /* @__PURE__ */ jsxRuntime.jsxs(
441
+ ui.Flex,
442
+ {
443
+ className: "orderly-notification-footer oui-px-4 oui-py-2",
444
+ itemAlign: "center",
445
+ justify: "between",
446
+ children: [
447
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, children: [
448
+ /* @__PURE__ */ jsxRuntime.jsx(
449
+ "button",
450
+ {
451
+ disabled: current - 1 < 0,
452
+ onClick: onPrev,
453
+ className: "oui-flex oui-size-[18px] oui-items-center oui-justify-center oui-rounded-full oui-bg-base-6 hover:oui-bg-base-5 disabled:oui-opacity-50",
454
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.ChevronLeftIcon, { size: 14, color: "white" })
455
+ }
456
+ ),
457
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { intensity: 54, size: "sm", children: [
458
+ current + 1,
459
+ "/",
460
+ total
461
+ ] }),
462
+ /* @__PURE__ */ jsxRuntime.jsx(
463
+ "button",
464
+ {
465
+ disabled: current + 1 >= total,
466
+ onClick: onNext,
467
+ className: "oui-flex oui-size-[18px] oui-items-center oui-justify-center oui-rounded-full oui-bg-base-6 hover:oui-bg-base-5 disabled:oui-opacity-50",
468
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.ChevronRightIcon, { size: 14, color: "white" })
469
+ }
470
+ )
471
+ ] }),
472
+ /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: onCloseAll, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xs", color: "primary", children: t("notification.closeAll", { total }) }) })
473
+ ]
474
+ }
475
+ );
476
+ };
477
+ var NotificationContent = (props) => {
478
+ const elements = react.useMemo(() => {
479
+ return props.dataSource.map((message) => {
480
+ const { type } = message;
481
+ switch (type) {
482
+ case types.AnnouncementType.Campaign:
483
+ return /* @__PURE__ */ jsxRuntime.jsx(
484
+ CampaignContentCard,
485
+ {
486
+ message: message.message,
487
+ coverImage: message.coverImage ?? "",
488
+ updateTime: message.updated_time ?? 0,
489
+ url: message.url ?? "",
490
+ onItemClick: props.onItemClick
491
+ }
492
+ );
493
+ case types.AnnouncementType.Maintenance:
494
+ return /* @__PURE__ */ jsxRuntime.jsx(
495
+ MaintenanceContentCard,
496
+ {
497
+ message: message.message,
498
+ startTime: message.startTime ?? 0,
499
+ endTime: message.endTime ?? 0
500
+ }
501
+ );
502
+ case types.AnnouncementType.Delisting:
503
+ return /* @__PURE__ */ jsxRuntime.jsx(
504
+ DelistingContentCard,
505
+ {
506
+ message: message.message,
507
+ updateTime: message.updated_time ?? 0
508
+ }
509
+ );
510
+ default:
511
+ return /* @__PURE__ */ jsxRuntime.jsx(
512
+ ListingContentCard,
513
+ {
514
+ message: message.message,
515
+ updateTime: message.updated_time ?? 0
516
+ }
517
+ );
518
+ }
519
+ });
520
+ }, [props.dataSource]);
521
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: elements[props.current] });
522
+ };
523
+ var NotificationUI = (props) => {
524
+ const [expanded, setExpanded] = react.useState(true);
525
+ const [current, setCurrent] = react.useState(0);
526
+ const len = react.useMemo(() => props.dataSource?.length ?? 0, [props.dataSource]);
527
+ if (len === 0) {
528
+ return null;
529
+ }
530
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "orderly-notification oui-w-full ", children: [
531
+ /* @__PURE__ */ jsxRuntime.jsx(
532
+ NotificationHeader,
533
+ {
534
+ dataSource: props.dataSource ?? [],
535
+ current,
536
+ expanded,
537
+ onExpandToggle: () => {
538
+ setExpanded(!expanded);
539
+ }
540
+ }
541
+ ),
542
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { className: "oui-mx-4" }),
543
+ /* @__PURE__ */ jsxRuntime.jsx(
544
+ "div",
545
+ {
546
+ className: "oui-grid oui-transition-all oui-duration-300 oui-ease-in-out",
547
+ style: {
548
+ gridTemplateRows: expanded ? "1fr" : "0fr"
549
+ },
550
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-min-h-0 oui-overflow-hidden ", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-px-4 oui-py-3", children: /* @__PURE__ */ jsxRuntime.jsx(
551
+ NotificationContent,
552
+ {
553
+ dataSource: props.dataSource ?? [],
554
+ current,
555
+ onItemClick: props.onItemClick
556
+ }
557
+ ) }) })
558
+ }
559
+ ),
560
+ /* @__PURE__ */ jsxRuntime.jsx(
561
+ NotificationFooter,
562
+ {
563
+ total: len,
564
+ current,
565
+ onCloseAll: props.onClose ?? (() => {
566
+ }),
567
+ onPrev: () => {
568
+ if (current - 1 < 0) {
569
+ return;
570
+ }
571
+ setCurrent(current - 1);
572
+ },
573
+ onNext: () => {
574
+ if (current + 1 >= len) {
575
+ return;
576
+ }
577
+ setCurrent(current + 1);
578
+ }
579
+ }
580
+ )
581
+ ] });
582
+ };
583
+ var oneDay = 1e3 * 60 * 60 * 24;
584
+ var maintentanceId = "-1";
585
+ var ORDERLY_ANNOUNCEMENT_KEY = "orderly_announcement";
586
+ var getTimeString = (timestamp) => {
587
+ const date = dateFns.format(new utc.UTCDateMini(timestamp), "MMM dd");
588
+ const time = dateFns.format(new utc.UTCDateMini(timestamp), "h:mm aa");
589
+ return `${time} (UTC) on ${date}`;
590
+ };
591
+ var sortDataByUpdatedTime = (ori) => {
592
+ return immer.produce(ori, (draft) => {
593
+ if (Array.isArray(draft.rows)) {
594
+ draft.rows.sort((a, b) => {
595
+ if (a.updated_time && b.updated_time) {
596
+ return b.updated_time - a.updated_time;
597
+ }
598
+ return 0;
599
+ });
600
+ }
601
+ });
602
+ };
603
+ var useAnnouncementData = () => {
604
+ const ws = hooks.useWS();
605
+ const [announcementStore, setStore] = hooks.useLocalStorage(
606
+ ORDERLY_ANNOUNCEMENT_KEY,
607
+ {}
608
+ );
609
+ const [tips, setTips] = react.useState({});
610
+ const [maintenanceDialogInfo, setMaintenanceDialogInfo] = react.useState();
611
+ const { startTime, endTime, status, brokerName } = hooks.useMaintenanceStatus();
612
+ const { t } = i18n.useTranslation();
613
+ const { data: announcements } = hooks.useQuery(
614
+ `/v2/public/announcement`,
615
+ {
616
+ revalidateOnFocus: false,
617
+ refreshInterval: 60 * 60 * 1e3,
618
+ // refresh every 1 hour
619
+ formatter: (data) => data
620
+ }
621
+ );
622
+ const getMaintentTipsContent = (brokerName2, startDate, endDate) => t("maintenance.tips.description", { brokerName: brokerName2, startDate, endDate });
623
+ const getMaintentDialogContent = (brokerName2, endDate) => t("maintenance.dialog.description", { brokerName: brokerName2, endDate });
624
+ react.useEffect(() => {
625
+ const unsubscribe = ws.subscribe("announcement", {
626
+ onMessage(message) {
627
+ if (message) {
628
+ setTips((prev) => {
629
+ return immer.produce(prev, (draft) => {
630
+ if (!Array.isArray(draft.rows)) {
631
+ draft.rows = [];
632
+ }
633
+ const idx = draft.rows.findIndex(
634
+ (tip) => tip.announcement_id === message.announcement_id
635
+ );
636
+ if (idx !== -1) {
637
+ draft.rows.splice(idx, 1);
638
+ }
639
+ draft.rows.push({
640
+ announcement_id: message.announcement_id,
641
+ message: message.message,
642
+ url: message.url,
643
+ i18n: message.i18n,
644
+ type: message.type,
645
+ updated_time: message.updated_time
646
+ });
647
+ });
648
+ });
649
+ setStore((prev) => ({ ...prev, show: true }));
650
+ }
651
+ },
652
+ onError(err) {
653
+ }
654
+ });
655
+ return () => {
656
+ unsubscribe?.();
657
+ };
658
+ }, [ws]);
659
+ react.useEffect(() => {
660
+ if (!announcements?.rows) {
661
+ return;
662
+ }
663
+ const apiTime = announcements.last_updated_time ?? 0;
664
+ const cachedTime = announcementStore.lastUpdateTime ?? 0;
665
+ if (cachedTime < apiTime) {
666
+ setTips((prev) => ({ ...prev, rows: announcements?.rows }));
667
+ setStore({ show: true, lastUpdateTime: apiTime });
668
+ } else {
669
+ setTips((prev) => {
670
+ return immer.produce(prev, (draft) => {
671
+ if (announcements?.rows?.length) {
672
+ const existingIds = new Set(
673
+ prev.rows?.map((tip) => tip.announcement_id)
674
+ );
675
+ const maintenanceTip = prev.rows?.find(
676
+ (tip) => tip.announcement_id === maintentanceId
677
+ );
678
+ draft.rows = [];
679
+ announcements.rows.forEach((item) => {
680
+ if (!existingIds.has(item.announcement_id)) {
681
+ draft.rows?.push(item);
682
+ }
683
+ });
684
+ if (maintenanceTip) {
685
+ draft.rows.unshift(maintenanceTip);
686
+ }
687
+ } else {
688
+ const idx = draft.rows?.findIndex(
689
+ (tip) => tip.announcement_id === maintentanceId
690
+ );
691
+ if (idx !== void 0 && idx !== -1) {
692
+ draft.rows?.splice(idx, 1);
693
+ }
694
+ }
695
+ });
696
+ });
697
+ }
698
+ }, [announcements]);
699
+ react.useEffect(() => {
700
+ const startDate = startTime ? getTimeString(startTime) : "-";
701
+ const endDate = endTime ? getTimeString(endTime) : "-";
702
+ if (status === hooks.MaintenanceStatus.Maintenance) {
703
+ setMaintenanceDialogInfo(getMaintentDialogContent(brokerName, endDate));
704
+ return;
705
+ }
706
+ setMaintenanceDialogInfo(void 0);
707
+ if (startTime) {
708
+ if (startTime < utils.getTimestamp() + oneDay) {
709
+ setTips(
710
+ (prev) => immer.produce(prev, (draft) => {
711
+ if (!Array.isArray(draft.rows)) {
712
+ draft.rows = [];
713
+ }
714
+ draft.rows = [
715
+ {
716
+ announcement_id: maintentanceId,
717
+ type: types.AnnouncementType.Maintenance,
718
+ /** @ts-ignore */
719
+ startTime,
720
+ /** @ts-ignore */
721
+ endTime,
722
+ message: getMaintentTipsContent(brokerName, startDate, endDate)
723
+ },
724
+ ...draft.rows.filter(
725
+ (tip) => tip.type !== types.AnnouncementType.Maintenance
726
+ )
727
+ ];
728
+ })
729
+ );
730
+ }
731
+ } else {
732
+ setTips((prev) => {
733
+ return immer.produce(prev, (draft) => {
734
+ const index = draft.rows?.findIndex(
735
+ (tip) => tip.announcement_id === maintentanceId
736
+ );
737
+ if (index !== void 0 && index !== -1) {
738
+ draft.rows?.splice(index, 1);
739
+ }
740
+ });
741
+ });
742
+ }
743
+ }, [startTime, endTime, status, brokerName, t]);
744
+ return {
745
+ tips: sortDataByUpdatedTime(tips),
746
+ maintenanceDialogInfo
747
+ };
748
+ };
749
+ var useAnnouncement = (options) => {
750
+ const { showAnnouncement, setShowAnnouncement } = reactApp.useAppContext();
751
+ const { dataAdapter } = hooks.useOrderlyContext();
752
+ const { tips, maintenanceDialogInfo } = useAnnouncementData();
753
+ const memoizedTips = react.useMemo(() => {
754
+ if (typeof dataAdapter?.announcementList === "function") {
755
+ return dataAdapter.announcementList(
756
+ tips?.rows ?? types.EMPTY_LIST
757
+ );
758
+ }
759
+ return tips?.rows ?? types.EMPTY_LIST;
760
+ }, [dataAdapter?.announcementList, tips?.rows]);
761
+ const [announcementStore, setStore] = hooks.useLocalStorage(
762
+ ORDERLY_ANNOUNCEMENT_KEY,
763
+ {}
764
+ );
765
+ const closeTips = () => {
766
+ setStore((prev) => ({ ...prev, show: false }));
767
+ };
768
+ react.useEffect(() => {
769
+ const len = memoizedTips.length;
770
+ setShowAnnouncement(
771
+ Boolean(len) && announcementStore.show && !options?.hideTips
772
+ );
773
+ }, [
774
+ memoizedTips,
775
+ announcementStore.show,
776
+ options?.hideTips,
777
+ setShowAnnouncement
778
+ ]);
779
+ return {
780
+ maintenanceDialogInfo,
781
+ tips: memoizedTips,
782
+ closeTips,
783
+ showAnnouncement
784
+ };
785
+ };
786
+
787
+ // src/pages/announcementCenter.script.tsx
788
+ var useAnnouncementCenterScript = () => {
789
+ const { tips } = useAnnouncement();
790
+ const [current, setCurrent] = react.useState(null);
791
+ return {
792
+ dataSource: tips,
793
+ current,
794
+ setCurrent
795
+ };
796
+ };
797
+ var AnnouncementCenterUI2 = (props) => {
798
+ const { dataSource, current, setCurrent, onItemClick } = props;
799
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-m-1 oui-rounded-xl oui-bg-base-9 oui-p-2", children: /* @__PURE__ */ jsxRuntime.jsx(
800
+ AnnouncementContent,
801
+ {
802
+ dataSource,
803
+ current,
804
+ onExpandToggle: setCurrent,
805
+ onItemClick,
806
+ showDivider: true
807
+ }
808
+ ) });
809
+ };
810
+ var AnnouncementCenterWidget = (props) => {
811
+ const { dataSource, current, setCurrent } = useAnnouncementCenterScript();
812
+ const onItemClick = react.useCallback(
813
+ (url) => {
814
+ if (!url)
815
+ return;
816
+ props.onRouteChange(url);
817
+ },
818
+ [props.onRouteChange]
819
+ );
820
+ return /* @__PURE__ */ jsxRuntime.jsx(
821
+ AnnouncementCenterUI2,
822
+ {
823
+ dataSource,
824
+ current,
825
+ setCurrent,
826
+ onItemClick
827
+ }
828
+ );
829
+ };
830
+ var AnnouncementCenterPage = (props) => {
831
+ return /* @__PURE__ */ jsxRuntime.jsx(
832
+ AnnouncementCenterWidget,
833
+ {
834
+ onRouteChange: (url) => {
835
+ if (!url)
836
+ return;
837
+ props.routerAdapter?.onRouteChange({
838
+ href: url,
839
+ name: url,
840
+ target: "_blank"
841
+ });
842
+ }
843
+ }
844
+ );
845
+ };
846
+
847
+ exports.AnnouncementCenterPage = AnnouncementCenterPage;
848
+ exports.AnnouncementCenterUI = AnnouncementCenterUI;
849
+ exports.AnnouncementItem = AnnouncementItem;
850
+ exports.NotificationUI = NotificationUI;
851
+ exports.useAnnouncement = useAnnouncement;
852
+ //# sourceMappingURL=out.js.map
853
+ //# sourceMappingURL=index.js.map