@orderly.network/affiliate 2.8.14-alpha.0 → 2.9.0-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 CHANGED
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var ui = require('@orderly.network/ui');
4
- var i18n = require('@orderly.network/i18n');
5
- var jsxRuntime = require('react/jsx-runtime');
6
3
  var react = require('react');
7
- var dateFns = require('date-fns');
8
4
  var hooks = require('@orderly.network/hooks');
9
5
  var reactApp = require('@orderly.network/react-app');
10
6
  var types = require('@orderly.network/types');
7
+ var ui = require('@orderly.network/ui');
8
+ var dateFns = require('date-fns');
11
9
  var utils = require('@orderly.network/utils');
12
- var chart = require('@orderly.network/chart');
10
+ var jsxRuntime = require('react/jsx-runtime');
11
+ var i18n = require('@orderly.network/i18n');
13
12
  var uiConnector = require('@orderly.network/ui-connector');
14
13
  var uiScaffold = require('@orderly.network/ui-scaffold');
14
+ var chart = require('@orderly.network/chart');
15
15
 
16
16
  var __defProp = Object.defineProperty;
17
17
  var __export = (target, all) => {
@@ -27,67 +27,6 @@ __export(dashboard_exports, {
27
27
  HomePage: () => HomePage,
28
28
  TraderPage: () => TraderPage
29
29
  });
30
- var AffiliateIcon = (props) => {
31
- const { size = 16, className, ...rest } = props;
32
- return /* @__PURE__ */ jsxRuntime.jsxs(
33
- "svg",
34
- {
35
- width: size,
36
- height: size,
37
- viewBox: "0 0 16 16",
38
- fill: "#fff",
39
- fillOpacity: ".98",
40
- xmlns: "http://www.w3.org/2000/svg",
41
- className: props.className,
42
- ...rest,
43
- children: [
44
- /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8 1.302c-3.683 0-6.655 2.985-6.667 6.667-.013 3.676 2.987 6.68 6.666 6.687s6.674-3.037 6.667-6.687c-.007-3.682-2.985-6.667-6.667-6.667m0 1.333a5.333 5.333 0 0 1 5.333 5.334c0 1.5-.625 2.852-1.622 3.821-.49-1.062-1.545-1.821-2.753-1.821H7.04c-1.207 0-2.259.75-2.75 1.812A5.3 5.3 0 0 1 2.666 7.97a5.333 5.333 0 0 1 5.333-5.334M8 3.97a2.667 2.667 0 1 0 0 5.333A2.667 2.667 0 0 0 8 3.97" }),
45
- /* @__PURE__ */ jsxRuntime.jsx(
46
- "path",
47
- {
48
- d: "M16 12.667a3.333 3.333 0 1 1-6.667 0 3.333 3.333 0 0 1 6.667 0",
49
- fill: "#1828C3"
50
- }
51
- ),
52
- /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M11.917 11.433a.917.917 0 0 0-.917.917c0 .53.302 1.031.802 1.49a4.6 4.6 0 0 0 .713.53l.068.043c.05.027.117.027.167 0l.068-.042q.08-.05.177-.115c.182-.123.366-.26.536-.416.5-.459.802-.96.802-1.49a.917.917 0 0 0-.917-.917.97.97 0 0 0-.744.386.95.95 0 0 0-.756-.386" })
53
- ]
54
- }
55
- );
56
- };
57
- var TraderIcon = (props) => {
58
- const { size = 16, className, ...rest } = props;
59
- return /* @__PURE__ */ jsxRuntime.jsxs(
60
- "svg",
61
- {
62
- width: size,
63
- height: size,
64
- viewBox: "0 0 16 16",
65
- fill: "white",
66
- fillOpacity: "0.36",
67
- xmlns: "http://www.w3.org/2000/svg",
68
- className: props.className,
69
- ...rest,
70
- children: [
71
- /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M7.99929 1.30212C4.31735 1.30212 1.34509 4.28679 1.33262 7.96878C1.32015 11.6454 4.32042 14.6488 7.99929 14.6561C11.6782 14.6634 14.6726 11.6194 14.666 7.96878C14.6593 4.28679 11.6812 1.30212 7.99929 1.30212ZM7.99929 2.63546C10.9448 2.63546 13.3326 5.02345 13.3326 7.96878C13.3326 9.46878 12.7078 10.8208 11.7112 11.7901C11.2202 10.7281 10.1656 9.96878 8.95762 9.96878C8.71802 9.96878 7.28042 9.96878 7.04095 9.96878C5.83369 9.96878 4.78215 10.7188 4.29095 11.7814C3.29429 10.8121 2.66595 9.46878 2.66595 7.96878C2.66595 5.02345 5.05375 2.63546 7.99929 2.63546ZM7.99929 3.96879C6.52649 3.96879 5.33255 5.16279 5.33262 6.63545C5.33262 8.10812 6.52649 9.30212 7.99929 9.30212C9.47202 9.30212 10.666 8.10812 10.666 6.63545C10.666 5.16279 9.47202 3.96879 7.99929 3.96879Z" }),
72
- /* @__PURE__ */ jsxRuntime.jsx(
73
- "path",
74
- {
75
- d: "M16 12.6667C16 14.5076 14.5076 16 12.6666 16C10.8257 16 9.33331 14.5076 9.33331 12.6667C9.33331 10.8257 10.8257 9.33333 12.6666 9.33333C14.5076 9.33333 16 10.8257 16 12.6667Z",
76
- fill: "#005A4F"
77
- }
78
- ),
79
- /* @__PURE__ */ jsxRuntime.jsx(
80
- "path",
81
- {
82
- d: "M14.3325 13.3345C14.3325 13.2918 14.3182 13.2473 14.2857 13.2147L13.6658 12.6002L13.4315 12.8345L13.7595 13.1678H11.3325C11.2405 13.1678 11.1658 13.2425 11.1658 13.3345C11.1658 13.4265 11.2405 13.5012 11.3325 13.5012H13.7595L13.4315 13.8345L13.6658 14.0688L14.2857 13.4543C14.3182 13.4217 14.3325 13.3772 14.3325 13.3345ZM14.1658 12.0012C14.1658 11.9092 14.0912 11.8345 13.9992 11.8345H11.572L11.9002 11.5012L11.6658 11.2668L11.046 11.8813C10.981 11.9465 10.981 12.0558 11.046 12.121L11.6658 12.7355L11.9002 12.5012L11.572 12.1678H13.9992C14.0912 12.1678 14.1658 12.0932 14.1658 12.0012Z",
83
- fill: "white",
84
- fillOpacity: "0.98"
85
- }
86
- )
87
- ]
88
- }
89
- );
90
- };
91
30
  var TabTypes = /* @__PURE__ */ ((TabTypes2) => {
92
31
  TabTypes2["affiliate"] = "affiliate";
93
32
  TabTypes2["trader"] = "trader";
@@ -99,6 +38,76 @@ var ReferralContext = react.createContext(
99
38
  var useReferralContext = () => {
100
39
  return react.useContext(ReferralContext);
101
40
  };
41
+ var useVolumePrerequisite = () => {
42
+ return hooks.usePrivateQuery(
43
+ "/v1/referral/multi_level/volume_prerequisite",
44
+ {
45
+ revalidateOnFocus: false
46
+ }
47
+ );
48
+ };
49
+ var useMaxRebateRate = () => {
50
+ return hooks.usePrivateQuery(
51
+ "/v1/referral/multi_level/max_rebate_rate",
52
+ {
53
+ revalidateOnFocus: false
54
+ }
55
+ );
56
+ };
57
+ var useMultiLevelRebateInfo = () => {
58
+ return hooks.usePrivateQuery(
59
+ "/v1/referral/multi_level/rebate_info",
60
+ {
61
+ errorRetryCount: 0,
62
+ revalidateOnFocus: false
63
+ }
64
+ );
65
+ };
66
+ var useMultiLevelStatistics = (time_range) => {
67
+ return hooks.usePrivateQuery(
68
+ `/v1/referral/multi_level/statistics?time_range=${time_range}`,
69
+ {
70
+ revalidateOnFocus: false
71
+ }
72
+ );
73
+ };
74
+
75
+ // src/hooks/useMultiLevelReferralData.ts
76
+ var useMultiLevelReferralData = () => {
77
+ const { data: volumePrerequisite, isLoading: volumePrerequisiteLoading } = useVolumePrerequisite();
78
+ const { data: maxRebateRateRes, isLoading: maxRebateRateLoading } = useMaxRebateRate();
79
+ const {
80
+ data: multiLevelRebateInfoRes,
81
+ mutate: multiLevelRebateInfoMutate,
82
+ isLoading: multiLevelRebateInfoLoading
83
+ } = useMultiLevelRebateInfo();
84
+ const isMultiLevelReferralUnlocked = volumePrerequisite && volumePrerequisite.current_volume >= volumePrerequisite.required_volume;
85
+ const isMultiLevelEnabled = !!maxRebateRateRes;
86
+ const maxRebateRate = maxRebateRateRes?.max_rebate_rate;
87
+ const multiLevelRebateInfo = react.useMemo(() => {
88
+ if (!multiLevelRebateInfoRes) return;
89
+ const {
90
+ default_referee_rebate_rate: referee_rebate_rate,
91
+ max_rebate_rate
92
+ } = multiLevelRebateInfoRes;
93
+ const referrer_rebate_rate = new utils.Decimal(max_rebate_rate || 0).sub(referee_rebate_rate || 0).toNumber();
94
+ return {
95
+ ...multiLevelRebateInfoRes,
96
+ referee_rebate_rate,
97
+ referrer_rebate_rate
98
+ };
99
+ }, [multiLevelRebateInfoRes, maxRebateRate]);
100
+ const isLoading = volumePrerequisiteLoading || maxRebateRateLoading || multiLevelRebateInfoLoading;
101
+ return {
102
+ volumePrerequisite,
103
+ maxRebateRate,
104
+ multiLevelRebateInfo,
105
+ isMultiLevelEnabled,
106
+ isMultiLevelReferralUnlocked,
107
+ multiLevelRebateInfoMutate,
108
+ isLoading
109
+ };
110
+ };
102
111
  var ReferralProvider = (props) => {
103
112
  const {
104
113
  becomeAnAffiliateUrl = "https://orderly.network/",
@@ -119,15 +128,15 @@ var ReferralProvider = (props) => {
119
128
  mutate: referralInfoMutate,
120
129
  isLoading
121
130
  } = hooks.usePrivateQuery("/v1/referral/info", {
122
- revalidateOnFocus: true,
131
+ revalidateOnFocus: false,
123
132
  errorRetryCount: 3,
124
133
  ...hooks.noCacheConfig
125
134
  });
126
135
  const { data: generateCode, mutate: generateCodeMutate } = hooks.usePrivateQuery(
127
136
  "/v1/referral/auto_referral/progress",
128
137
  {
129
- revalidateOnFocus: true,
130
- errorRetryCount: 2,
138
+ revalidateOnFocus: false,
139
+ errorRetryCount: 0,
131
140
  formatter: (data2) => {
132
141
  return {
133
142
  code: data2.auto_referral_code,
@@ -137,6 +146,15 @@ var ReferralProvider = (props) => {
137
146
  }
138
147
  }
139
148
  );
149
+ const {
150
+ volumePrerequisite,
151
+ multiLevelRebateInfo,
152
+ isMultiLevelEnabled,
153
+ isMultiLevelReferralUnlocked,
154
+ multiLevelRebateInfoMutate,
155
+ maxRebateRate,
156
+ isLoading: isMultiLevelLoading
157
+ } = useMultiLevelReferralData();
140
158
  const [showHome, setShowHome] = react.useState(isLoading);
141
159
  react.useEffect(() => {
142
160
  setShowHome(true);
@@ -146,7 +164,7 @@ var ReferralProvider = (props) => {
146
164
  endDate: dateFns.subDays(/* @__PURE__ */ new Date(), 90)
147
165
  });
148
166
  const { data: volumeStatistics, mutate: volumeStatisticsMutate } = hooks.usePrivateQuery("/v1/volume/user/stats", {
149
- revalidateOnFocus: true
167
+ revalidateOnFocus: false
150
168
  });
151
169
  const isAffiliate = react.useMemo(() => {
152
170
  return (data?.referrer_info?.referral_codes?.length || 0) > 0;
@@ -207,64 +225,2932 @@ var ReferralProvider = (props) => {
207
225
  memoMutate();
208
226
  }, 1e3);
209
227
  }
210
- return () => {
211
- if (timerRef.current) {
212
- clearTimeout(timerRef.current);
213
- }
214
- };
215
- }, [memoMutate, state.status]);
216
- const memoizedValue = react.useMemo(() => {
228
+ return () => {
229
+ if (timerRef.current) {
230
+ clearTimeout(timerRef.current);
231
+ }
232
+ };
233
+ }, [memoMutate, state.status]);
234
+ const memoizedValue = react.useMemo(() => {
235
+ return {
236
+ generateCode,
237
+ showHome,
238
+ referralInfo: data,
239
+ isAffiliate,
240
+ isTrader,
241
+ tab,
242
+ becomeAnAffiliateUrl,
243
+ learnAffiliateUrl,
244
+ referralLinkUrl,
245
+ userVolume,
246
+ dailyVolume,
247
+ chartConfig,
248
+ overwrite,
249
+ isLoading: isLoading || isMultiLevelLoading,
250
+ wrongNetwork,
251
+ disabledConnect,
252
+ setShowHome,
253
+ setTab,
254
+ mutate: memoMutate,
255
+ onBecomeAnAffiliate,
256
+ bindReferralCodeState,
257
+ onLearnAffiliate,
258
+ showReferralPage,
259
+ splashPage,
260
+ volumePrerequisite,
261
+ multiLevelRebateInfo,
262
+ isMultiLevelEnabled,
263
+ isMultiLevelReferralUnlocked,
264
+ multiLevelRebateInfoMutate,
265
+ maxRebateRate
266
+ };
267
+ }, [
268
+ becomeAnAffiliateUrl,
269
+ chartConfig,
270
+ dailyVolume,
271
+ data,
272
+ disabledConnect,
273
+ generateCode,
274
+ isAffiliate,
275
+ isLoading,
276
+ isTrader,
277
+ learnAffiliateUrl,
278
+ overwrite,
279
+ referralLinkUrl,
280
+ showHome,
281
+ tab,
282
+ userVolume,
283
+ wrongNetwork,
284
+ onBecomeAnAffiliate,
285
+ bindReferralCodeState,
286
+ onLearnAffiliate,
287
+ showReferralPage,
288
+ splashPage,
289
+ memoMutate,
290
+ volumePrerequisite,
291
+ multiLevelRebateInfo,
292
+ isMultiLevelEnabled,
293
+ isMultiLevelReferralUnlocked,
294
+ multiLevelRebateInfoMutate,
295
+ maxRebateRate,
296
+ isMultiLevelLoading
297
+ ]);
298
+ return /* @__PURE__ */ jsxRuntime.jsx(ReferralContext.Provider, { value: memoizedValue, children });
299
+ };
300
+ var Faq = () => {
301
+ const { t } = i18n.useTranslation();
302
+ const faqItemsData = react.useMemo(() => {
303
+ return [
304
+ {
305
+ id: "faq-1",
306
+ question: t("affiliate.faq.question1"),
307
+ answer: t("affiliate.faq.answer1")
308
+ },
309
+ {
310
+ id: "faq-2",
311
+ question: t("affiliate.faq.question2"),
312
+ answer: t("affiliate.faq.answer2")
313
+ },
314
+ {
315
+ id: "faq-3",
316
+ question: t("affiliate.faq.question3"),
317
+ answer: t("affiliate.faq.answer3")
318
+ },
319
+ {
320
+ id: "faq-4",
321
+ question: t("affiliate.faq.question4"),
322
+ answer: t("affiliate.faq.answer4")
323
+ },
324
+ {
325
+ id: "faq-5",
326
+ question: t("affiliate.faq.question5"),
327
+ answer: t("affiliate.faq.answer5")
328
+ }
329
+ ];
330
+ }, [t]);
331
+ const [expandedItems, setExpandedItems] = react.useState(/* @__PURE__ */ new Set());
332
+ const toggleItem = react.useCallback((id) => {
333
+ setExpandedItems((prev) => {
334
+ const newSet = new Set(prev);
335
+ if (newSet.has(id)) {
336
+ newSet.delete(id);
337
+ } else {
338
+ newSet.add(id);
339
+ }
340
+ return newSet;
341
+ });
342
+ }, []);
343
+ const faqItems = react.useMemo(() => {
344
+ return faqItemsData.map((item) => ({
345
+ ...item,
346
+ expanded: expandedItems.has(item.id)
347
+ }));
348
+ }, [faqItemsData, expandedItems]);
349
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { children: [
350
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "oui-text-[32px]", children: t("affiliate.faq.title") }),
351
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { direction: "column", itemAlign: "stretch", gap: 0, children: faqItems.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
352
+ /* @__PURE__ */ jsxRuntime.jsx(
353
+ ui.Collapsible,
354
+ {
355
+ open: item.expanded,
356
+ onOpenChange: () => toggleItem(item.id),
357
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
358
+ ui.Flex,
359
+ {
360
+ direction: "column",
361
+ className: "oui-cursor-pointer oui-py-4",
362
+ itemAlign: "stretch",
363
+ onClick: () => toggleItem(item.id),
364
+ children: [
365
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { justify: "between", itemAlign: "center", gap: 4, children: [
366
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { gap: 2, itemAlign: "center", className: "oui-flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "2xl", weight: "semibold", children: `${index + 1}. ${item.question}` }) }),
367
+ /* @__PURE__ */ jsxRuntime.jsx(ChevronIcon, { expanded: item.expanded })
368
+ ] }),
369
+ /* @__PURE__ */ jsxRuntime.jsx(ui.CollapsibleContent, { children: /* @__PURE__ */ jsxRuntime.jsx(
370
+ ui.Box,
371
+ {
372
+ className: "oui-pt-3 oui-text-base-contrast-54",
373
+ dangerouslySetInnerHTML: { __html: item.answer }
374
+ }
375
+ ) })
376
+ ]
377
+ }
378
+ )
379
+ }
380
+ ),
381
+ index < faqItems.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-my-4 oui-h-px oui-bg-line-6" })
382
+ ] }, item.id)) })
383
+ ] });
384
+ };
385
+ var ChevronIcon = ({ expanded }) => /* @__PURE__ */ jsxRuntime.jsx(
386
+ "svg",
387
+ {
388
+ width: "24",
389
+ height: "24",
390
+ viewBox: "0 0 16 16",
391
+ fill: "none",
392
+ xmlns: "http://www.w3.org/2000/svg",
393
+ className: `oui-transition-transform oui-duration-200 ${expanded ? "oui-rotate-180" : ""}`,
394
+ children: /* @__PURE__ */ jsxRuntime.jsx(
395
+ "path",
396
+ {
397
+ d: "M4 6L8 10L12 6",
398
+ stroke: "currentColor",
399
+ strokeWidth: "2",
400
+ strokeLinecap: "round",
401
+ strokeLinejoin: "round",
402
+ className: "oui-text-base-contrast-54"
403
+ }
404
+ )
405
+ }
406
+ );
407
+ var useReferralCode = () => {
408
+ const [doCreateReferralCode, { isMutating: isCreateMutating }] = hooks.useMutation(
409
+ "/v1/referral/multi_level/claim_code"
410
+ );
411
+ const [doEditReferralCode, { isMutating: isEditMutating }] = hooks.useMutation(
412
+ "/v1/referral/edit_referral_code"
413
+ );
414
+ const [doUpdateRebateRate, { isMutating: isUpdateRebateRateMutating }] = hooks.useMutation("/v1/referral/multi_level/rebate_rate/update");
415
+ const [doResetRebateRate, { isMutating: isResetRebateRateMutating }] = hooks.useMutation("/v1/referral/multi_level/rebate_rate/set_default");
416
+ const createReferralCode = async (params) => {
417
+ return doCreateReferralCode(params);
418
+ };
419
+ const editReferralCode = async (params) => {
420
+ return doEditReferralCode(params);
421
+ };
422
+ const updateRebateRate = async (params) => {
423
+ return doUpdateRebateRate(params);
424
+ };
425
+ const resetRebateRate = async (params) => {
426
+ return doResetRebateRate(params);
427
+ };
428
+ const isMutating = isCreateMutating || isEditMutating || isUpdateRebateRateMutating || isResetRebateRateMutating;
429
+ return {
430
+ createReferralCode,
431
+ editReferralCode,
432
+ updateRebateRate,
433
+ resetRebateRate,
434
+ isMutating
435
+ };
436
+ };
437
+
438
+ // src/pages/multiLevel/affiliate/referralCodeForm/referralCodeForm.script.ts
439
+ var useReferralCodeFormScript = (options) => {
440
+ const { type, referralCode, maxRebateRate, referrerRebateRate, accountId } = options;
441
+ const { t } = i18n.useTranslation();
442
+ const [newCode, setNewCode] = react.useState(referralCode || "");
443
+ const [isReview, setIsReview] = react.useState(false);
444
+ const maxRebatePercentage = react.useMemo(() => {
445
+ return new utils.Decimal(maxRebateRate).mul(100).toNumber();
446
+ }, [maxRebateRate]);
447
+ const [referrerRebatePercentage, setReferrerRebatePercentage] = react.useState(
448
+ () => {
449
+ if (type === "create" /* Create */) {
450
+ return Math.ceil(maxRebatePercentage / 2);
451
+ }
452
+ if (referrerRebateRate) {
453
+ return new utils.Decimal(referrerRebateRate).mul(100).toNumber();
454
+ }
455
+ return 0;
456
+ }
457
+ );
458
+ const {
459
+ createReferralCode,
460
+ editReferralCode,
461
+ updateRebateRate,
462
+ resetRebateRate,
463
+ isMutating
464
+ } = useReferralCode();
465
+ const refereeRebatePercentage = react.useMemo(() => {
466
+ return Math.max(
467
+ 0,
468
+ new utils.Decimal(maxRebatePercentage).sub(referrerRebatePercentage).toNumber()
469
+ );
470
+ }, [referrerRebatePercentage]);
471
+ const codeChanged = react.useMemo(() => {
472
+ return newCode !== referralCode;
473
+ }, [newCode, referralCode]);
474
+ const rateChanged = react.useMemo(() => {
475
+ return new utils.Decimal(referrerRebatePercentage).toNumber() !== new utils.Decimal(referrerRebateRate || 0).mul(100).toNumber();
476
+ }, [referrerRebatePercentage, referrerRebateRate, newCode]);
477
+ const handleError = (err) => {
478
+ ui.toast.error(err?.message || t("common.somethingWentWrong"));
479
+ };
480
+ const handleResult = (res) => {
481
+ if (res.success) {
482
+ options.onSuccess?.();
483
+ ui.toast.success(t("affiliate.confirmChanges.success"));
484
+ options.close?.();
485
+ } else {
486
+ ui.toast.error(res.message);
487
+ }
488
+ };
489
+ const onEdit = async () => {
490
+ const editReferralCodeParams = {
491
+ current_referral_code: referralCode,
492
+ new_referral_code: newCode
493
+ };
494
+ const updateRebateRateParams = {
495
+ referee_rebate_rate: new utils.Decimal(refereeRebatePercentage).div(100).toNumber(),
496
+ account_ids: accountId ? [accountId] : void 0
497
+ };
498
+ try {
499
+ if (codeChanged && rateChanged) {
500
+ const codeRes = await editReferralCode(editReferralCodeParams);
501
+ if (!codeRes.success) {
502
+ ui.toast.error(codeRes.message);
503
+ return;
504
+ }
505
+ const rateRes = await updateRebateRate(updateRebateRateParams);
506
+ handleResult(rateRes);
507
+ } else if (codeChanged) {
508
+ const res = await editReferralCode(editReferralCodeParams);
509
+ handleResult(res);
510
+ } else if (rateChanged) {
511
+ const res = await updateRebateRate(updateRebateRateParams);
512
+ handleResult(res);
513
+ }
514
+ } catch (err) {
515
+ handleError(err);
516
+ }
517
+ };
518
+ const onCreate = async () => {
519
+ try {
520
+ const referee_rebate_rate = new utils.Decimal(refereeRebatePercentage).div(100).toNumber();
521
+ const res = await createReferralCode({ referee_rebate_rate });
522
+ if (res.success) {
523
+ ui.toast.success(t("affiliate.referralCode.create.success"));
524
+ options.onSuccess?.();
525
+ options.close?.();
526
+ } else {
527
+ ui.toast.error(res.message);
528
+ }
529
+ } catch (err) {
530
+ handleError(err);
531
+ }
532
+ };
533
+ const onReset = async () => {
534
+ try {
535
+ const res = await resetRebateRate({ account_ids: [accountId] });
536
+ handleResult(res);
537
+ } catch (err) {
538
+ handleError(err);
539
+ }
540
+ };
541
+ const onClick = () => {
542
+ switch (type) {
543
+ case "create" /* Create */:
544
+ onCreate();
545
+ break;
546
+ case "edit" /* Edit */:
547
+ if (isReview) {
548
+ onEdit();
549
+ } else {
550
+ setIsReview(true);
551
+ }
552
+ break;
553
+ case "reset" /* Reset */:
554
+ onReset();
555
+ break;
556
+ }
557
+ };
558
+ const buttonDisabled = type === "edit" /* Edit */ && !codeChanged && !rateChanged;
559
+ return {
560
+ onClick,
561
+ maxRebatePercentage,
562
+ referrerRebatePercentage,
563
+ setReferrerRebatePercentage,
564
+ refereeRebatePercentage,
565
+ isMutating,
566
+ newCode,
567
+ setNewCode,
568
+ isReview,
569
+ buttonDisabled,
570
+ onReset
571
+ };
572
+ };
573
+ var GiftIcon = (props) => {
574
+ const { size = 16, className, ...rest } = props;
575
+ return /* @__PURE__ */ jsxRuntime.jsx(
576
+ "svg",
577
+ {
578
+ width: size,
579
+ height: size,
580
+ viewBox: "0 0 16 16",
581
+ fill: "none",
582
+ xmlns: "http://www.w3.org/2000/svg",
583
+ className,
584
+ ...rest,
585
+ children: /* @__PURE__ */ jsxRuntime.jsx(
586
+ "path",
587
+ {
588
+ d: "M5.99902 1.99377C4.52636 1.99377 3.33236 3.18777 3.33236 4.66044H2.66569C2.29769 4.66044 1.99902 4.9591 1.99902 5.3271C1.99902 5.66044 1.99902 7.66043 1.99902 7.99377C1.99902 8.36177 2.29769 8.66043 2.66569 8.66043V11.3271C2.66569 12.7998 3.85969 13.9938 5.33236 13.9938H10.6657C12.1384 13.9938 13.3324 12.7998 13.3324 11.3271V8.66043C13.7004 8.66043 13.999 8.36177 13.999 7.99377V5.3271C13.999 4.9591 13.7004 4.66044 13.3324 4.66044H12.6657C12.6657 3.18777 11.4717 1.99377 9.99902 1.99377C9.19169 1.99377 8.48836 2.36444 7.99902 2.93111C7.50969 2.36444 6.80636 1.99377 5.99902 1.99377ZM5.99902 3.32711C6.73569 3.32711 7.33236 3.92377 7.33236 4.66044H4.66569C4.66569 3.92377 5.26236 3.32711 5.99902 3.32711ZM9.99902 3.32711C10.7357 3.32711 11.3324 3.92377 11.3324 4.66044H8.66569C8.66569 3.92377 9.26236 3.32711 9.99902 3.32711ZM3.33236 5.99377H12.6657V7.3271H3.33236C3.33236 6.84777 3.33236 6.4731 3.33236 5.99377ZM3.99902 8.66043H7.33236V12.6604H5.33236C4.59569 12.6604 3.99902 12.0638 3.99902 11.3271V8.66043ZM8.66569 8.66043H11.999V11.3271C11.999 12.0638 11.4024 12.6604 10.6657 12.6604H8.66569V8.66043Z",
589
+ fill: "currentColor"
590
+ }
591
+ )
592
+ }
593
+ );
594
+ };
595
+ var ReferralCodeForm = (props) => {
596
+ const { type, isReview } = props;
597
+ const { t } = i18n.useTranslation();
598
+ const isReset = type === "reset" /* Reset */;
599
+ const hasBoundReferee = !!props.directInvites && props.directInvites > 0;
600
+ const isEditingRefereeRebateRate = !!props.accountId;
601
+ const noCommissionAvailable = props.maxRebateRate === 0;
602
+ const { title, description, buttonText } = react.useMemo(() => {
603
+ switch (type) {
604
+ case "create" /* Create */:
605
+ return {
606
+ title: t("affiliate.referralCode.create.modal.title"),
607
+ description: t("affiliate.referralCode.create.warning"),
608
+ buttonText: t("affiliate.confirmAndGenerate")
609
+ };
610
+ case "edit" /* Edit */:
611
+ return {
612
+ title: isEditingRefereeRebateRate ? t("affiliate.refereeRebateRate.modal.title", {
613
+ accountId: ui.formatAddress(props.accountId)
614
+ }) : t("affiliate.referralCode.edit.modal.title"),
615
+ description: isEditingRefereeRebateRate ? isReview ? t("affiliate.refereeRebateRate.review.warning") : t("affiliate.refereeRebateRate.edit.warning") : isReview ? t("affiliate.rebateRate.review.warning") : t("affiliate.rebateRate.edit.warning"),
616
+ buttonText: isReview ? t("affiliate.confirmChanges") : t("affiliate.review")
617
+ };
618
+ case "reset" /* Reset */:
619
+ return {
620
+ title: t("affiliate.resetRebateRate.modal.title"),
621
+ description: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "2xs", intensity: 54, children: t("affiliate.resetRebateRate.modal.description", {
622
+ accountId: ui.formatAddress(props.accountId)
623
+ }) }),
624
+ buttonText: t("common.reset")
625
+ };
626
+ default:
627
+ return {
628
+ title: "",
629
+ description: "",
630
+ buttonText: ""
631
+ };
632
+ }
633
+ }, [t, type, isEditingRefereeRebateRate, isReview, props.accountId]);
634
+ const titleView = /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "100%", direction: "column", itemAlign: "start", gap: 3, children: [
635
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "base", intensity: 98, children: title }),
636
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { intensity: 8, className: "oui-w-full" })
637
+ ] });
638
+ const descriptionView = /* @__PURE__ */ jsxRuntime.jsx(WarningBox, { children: description });
639
+ const referralCodeInput = /* @__PURE__ */ jsxRuntime.jsx(
640
+ ReferralCodeInput,
641
+ {
642
+ value: props.newCode,
643
+ onChange: props.setNewCode,
644
+ autoFocus: props.focusField === "referralCode" /* ReferralCode */,
645
+ disabled: isReview || hasBoundReferee
646
+ }
647
+ );
648
+ const commissionConfiguration = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
649
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "2xs", intensity: 54, children: t("affiliate.commissionConfiguration") }),
650
+ !isReview && /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "2xs", intensity: 54, children: [
651
+ t("affiliate.totalCommissionAvailable"),
652
+ ":",
653
+ " ",
654
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "oui-text-warning", children: [
655
+ props.maxRebatePercentage,
656
+ "%"
657
+ ] })
658
+ ] })
659
+ ] });
660
+ const rebateRateSlider = /* @__PURE__ */ jsxRuntime.jsx(
661
+ RebateRateSlider,
662
+ {
663
+ value: props.referrerRebatePercentage,
664
+ restValue: props.refereeRebatePercentage,
665
+ onChange: props.setReferrerRebatePercentage,
666
+ max: props.maxRebatePercentage,
667
+ disabled: noCommissionAvailable || isReview || isReset,
668
+ disabledIncrease: hasBoundReferee,
669
+ directBonusRebateRate: props.directBonusRebateRate,
670
+ noCommissionAvailable
671
+ }
672
+ );
673
+ const refereeInfo = /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "100%", justify: "between", gap: 2, children: [
674
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "2xs", intensity: 54, children: t("affiliate.referees") }),
675
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text.formatted, { rule: "address", size: "2xs", intensity: 98, children: props.accountId })
676
+ ] });
677
+ const noCommissionAvailableWarning = noCommissionAvailable && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "2xs", className: "oui-text-warning", children: isEditingRefereeRebateRate ? t("affiliate.rebateRate.noCommissionRate") : t("affiliate.rebateRate.noCommissionAvailable") });
678
+ const resetRebateRateLabel = /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "2xs", intensity: 98, className: "oui-text-start", children: [
679
+ t("affiliate.resetRebateRate.rateAfterReset"),
680
+ ":"
681
+ ] });
682
+ const buttons = /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "row", gap: 2, width: "100%", mt: 0, pt: 5, children: [
683
+ /* @__PURE__ */ jsxRuntime.jsx(
684
+ ui.Button,
685
+ {
686
+ variant: "contained",
687
+ color: "gray",
688
+ fullWidth: true,
689
+ onClick: props.close,
690
+ size: "md",
691
+ children: t("common.cancel")
692
+ }
693
+ ),
694
+ /* @__PURE__ */ jsxRuntime.jsx(
695
+ ui.Button,
696
+ {
697
+ fullWidth: true,
698
+ onClick: props.onClick,
699
+ disabled: props.buttonDisabled || props.isMutating,
700
+ loading: props.isMutating,
701
+ size: "md",
702
+ children: buttonText
703
+ }
704
+ )
705
+ ] });
706
+ const renderContent = () => {
707
+ switch (type) {
708
+ case "create" /* Create */:
709
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "100%", direction: "column", itemAlign: "start", gap: 2, children: [
710
+ commissionConfiguration,
711
+ rebateRateSlider,
712
+ noCommissionAvailableWarning,
713
+ buttons
714
+ ] });
715
+ case "edit" /* Edit */:
716
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
717
+ isEditingRefereeRebateRate ? refereeInfo : referralCodeInput,
718
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "100%", direction: "column", itemAlign: "start", gap: 2, children: [
719
+ commissionConfiguration,
720
+ rebateRateSlider,
721
+ noCommissionAvailableWarning,
722
+ buttons
723
+ ] })
724
+ ] });
725
+ case "reset" /* Reset */:
726
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "100%", direction: "column", itemAlign: "start", gap: 2, children: [
727
+ resetRebateRateLabel,
728
+ rebateRateSlider,
729
+ buttons
730
+ ] });
731
+ default:
732
+ return null;
733
+ }
734
+ };
735
+ return /* @__PURE__ */ jsxRuntime.jsxs(
736
+ ui.Flex,
737
+ {
738
+ direction: "column",
739
+ itemAlign: "start",
740
+ gap: 6,
741
+ className: "oui-font-semibold",
742
+ children: [
743
+ titleView,
744
+ descriptionView,
745
+ renderContent()
746
+ ]
747
+ }
748
+ );
749
+ };
750
+ var NoCommissionCard = (props) => {
751
+ const { t } = i18n.useTranslation();
752
+ const amount = props.directBonusRebateRate;
753
+ return /* @__PURE__ */ jsxRuntime.jsxs(
754
+ ui.Flex,
755
+ {
756
+ direction: "column",
757
+ gap: 2,
758
+ mt: 2,
759
+ width: "100%",
760
+ p: 4,
761
+ r: "lg",
762
+ className: "oui-border oui-border-base-contrast/[0.08] oui-tracking-[0.03em]",
763
+ children: [
764
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { justify: "between", width: "100%", itemAlign: "center", children: [
765
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", itemAlign: "start", gap: 1, children: [
766
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "2xs", intensity: 54, children: t("affiliate.noCommissionCard.title") }),
767
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "lg", className: "oui-text-primary-light oui-font-semibold", children: [
768
+ "+ ",
769
+ amount,
770
+ "%"
771
+ ] })
772
+ ] }),
773
+ /* @__PURE__ */ jsxRuntime.jsx(GiftIcon, { size: 24, className: "oui-shrink-0 oui-text-primary-light" })
774
+ ] }),
775
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "2xs", intensity: 98, className: "oui-leading-[15px]", children: t("affiliate.noCommissionCard.content", { amount }) })
776
+ ]
777
+ }
778
+ );
779
+ };
780
+ var RebateRateSlider = (props) => {
781
+ const { t } = i18n.useTranslation();
782
+ const [maxValue] = react.useState(props.value);
783
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
784
+ !props.disabled && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { width: "100%", my: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
785
+ ui.Slider,
786
+ {
787
+ min: 0,
788
+ max: props.max,
789
+ step: 1,
790
+ value: [props.value],
791
+ onValueChange: (value) => {
792
+ const newValue = value[0];
793
+ props.onChange(
794
+ props.disabledIncrease ? Math.min(newValue, maxValue) : newValue
795
+ );
796
+ },
797
+ classNames: {
798
+ range: "oui-bg-success-darken oui-h-2 oui-top-[0px]",
799
+ trackInner: "oui-bg-success-darken/30 oui-h-2 oui-top-[0px]",
800
+ thumb: "oui-border-[#d9d9d9] oui-bg-[#d9d9d9] oui-size-4"
801
+ }
802
+ }
803
+ ) }),
804
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-w-full", children: [
805
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { justify: "between", width: "100%", children: [
806
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", intensity: 54, children: t("affiliate.youKeep") }),
807
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", intensity: 54, children: t("affiliate.refereesGet") })
808
+ ] }),
809
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { justify: "between", width: "100%", children: [
810
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text.formatted, { size: "lg", className: "oui-text-success-darken", children: [
811
+ props.value,
812
+ "%"
813
+ ] }),
814
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text.formatted, { size: "lg", className: "oui-text-success-darken/50", children: [
815
+ props.restValue,
816
+ "%"
817
+ ] })
818
+ ] }),
819
+ props.noCommissionAvailable ? /* @__PURE__ */ jsxRuntime.jsx(
820
+ NoCommissionCard,
821
+ {
822
+ directBonusRebateRate: props.directBonusRebateRate
823
+ }
824
+ ) : props.directBonusRebateRate != null && props.directBonusRebateRate > 0 && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, mt: 2, width: "100%", children: [
825
+ /* @__PURE__ */ jsxRuntime.jsx(
826
+ GiftIcon,
827
+ {
828
+ size: 16,
829
+ className: "oui-text-base-contrast oui-mt-[1px]"
830
+ }
831
+ ),
832
+ /* @__PURE__ */ jsxRuntime.jsx(
833
+ ui.Text,
834
+ {
835
+ size: "base",
836
+ intensity: 54,
837
+ as: "span",
838
+ className: "oui-inline-flex oui-items-center oui-gap-1 oui-tracking-[0.03em]",
839
+ children: /* @__PURE__ */ jsxRuntime.jsx(
840
+ i18n.Trans,
841
+ {
842
+ i18nKey: "affiliate.extraBonusOnDirectReferrals",
843
+ values: { amount: props.directBonusRebateRate },
844
+ components: [/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { as: "span", color: "primaryLight" }, "0")]
845
+ }
846
+ )
847
+ }
848
+ )
849
+ ] })
850
+ ] })
851
+ ] });
852
+ };
853
+ var ReferralCodeInput = (props) => {
854
+ const { t } = i18n.useTranslation();
855
+ const hasSetCursorToEnd = react.useRef(false);
856
+ return /* @__PURE__ */ jsxRuntime.jsx(
857
+ ui.TextField,
858
+ {
859
+ type: "text",
860
+ fullWidth: true,
861
+ label: t("affiliate.referralCode.editCodeModal.label"),
862
+ value: props.value,
863
+ onChange: (e) => {
864
+ props.onChange(e.target.value);
865
+ },
866
+ onFocus: (e) => {
867
+ if (props.autoFocus && !hasSetCursorToEnd.current) {
868
+ hasSetCursorToEnd.current = true;
869
+ const input = e.target;
870
+ const len = input.value.length;
871
+ requestAnimationFrame(() => {
872
+ input.setSelectionRange(len, len);
873
+ });
874
+ }
875
+ },
876
+ formatters: [
877
+ ui.inputFormatter.createRegexInputFormatter((value) => {
878
+ return String(value).replace(
879
+ /[a-z]/g,
880
+ (char) => char.toUpperCase()
881
+ );
882
+ }),
883
+ ui.inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)
884
+ ],
885
+ className: "oui-w-full",
886
+ classNames: {
887
+ label: "oui-text-base-contrast-54 oui-text-xs",
888
+ input: "placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm"
889
+ },
890
+ maxLength: 10,
891
+ minLength: 4,
892
+ autoComplete: "off",
893
+ disabled: props.disabled,
894
+ autoFocus: props.autoFocus
895
+ }
896
+ );
897
+ };
898
+ var WarningBox = (props) => {
899
+ const { children } = props;
900
+ if (typeof children === "string") {
901
+ return /* @__PURE__ */ jsxRuntime.jsxs(
902
+ ui.Flex,
903
+ {
904
+ className: "oui-bg-warning/10",
905
+ justify: "start",
906
+ itemAlign: "start",
907
+ gap: 1,
908
+ r: "lg",
909
+ p: 3,
910
+ children: [
911
+ /* @__PURE__ */ jsxRuntime.jsx(ui.WarningIcon, { className: "oui-shrink-0 oui-text-warning" }),
912
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "2xs", intensity: 54, className: "oui-text-warning", children })
913
+ ]
914
+ }
915
+ );
916
+ }
917
+ return children;
918
+ };
919
+ var ReferralCodeFormWidget = (props) => {
920
+ const state = useReferralCodeFormScript(props);
921
+ return /* @__PURE__ */ jsxRuntime.jsx(ReferralCodeForm, { ...state, ...props });
922
+ };
923
+
924
+ // src/pages/multiLevel/affiliate/referralCodeForm/modal.ts
925
+ var ReferralCodeFormDialogId = "ReferralCodeFormDialogId";
926
+ var ReferralCodeFormSheetId = "ReferralCodeFormSheetId";
927
+ ui.registerSimpleDialog(ReferralCodeFormDialogId, ReferralCodeFormWidget, {
928
+ size: "sm",
929
+ classNames: {
930
+ content: "oui-border oui-border-line-6",
931
+ body: "!oui-pt-3"
932
+ }
933
+ });
934
+ ui.registerSimpleSheet(ReferralCodeFormSheetId, ReferralCodeFormWidget);
935
+ var TradingVolumeProgress = (props) => {
936
+ const { t } = i18n.useTranslation();
937
+ const { classNames } = props;
938
+ const { volumePrerequisite } = useReferralContext();
939
+ const { routerAdapter } = uiScaffold.useScaffoldContext();
940
+ const { current_volume = 0, required_volume = 0 } = volumePrerequisite || {};
941
+ const progressPercentage = react.useMemo(() => {
942
+ if (required_volume === 0) return 0;
943
+ const percentage = new utils.Decimal(current_volume).div(required_volume).mul(100).toNumber();
944
+ return Math.min(percentage, 100);
945
+ }, [current_volume, required_volume]);
946
+ const formatRequiredVolume = react.useMemo(() => {
947
+ return ui.parseNumber(required_volume, {
948
+ rule: "price",
949
+ dp: 0
950
+ });
951
+ }, [required_volume]);
952
+ const gotoTrade = () => {
953
+ routerAdapter?.onRouteChange?.({
954
+ href: "/perp",
955
+ name: "Perp"
956
+ });
957
+ };
958
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "100%", direction: "column", gap: 4, className: classNames?.root, children: [
959
+ /* @__PURE__ */ jsxRuntime.jsx(
960
+ ui.Text,
961
+ {
962
+ size: "sm",
963
+ intensity: 54,
964
+ className: ui.cn("oui-text-center", classNames?.description),
965
+ children: t("affiliate.newReferralProgram.tradeUnlock.description", {
966
+ volume: formatRequiredVolume
967
+ })
968
+ }
969
+ ),
970
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "100%", direction: "column", gap: 2, children: [
971
+ /* @__PURE__ */ jsxRuntime.jsxs(
972
+ ui.Flex,
973
+ {
974
+ width: "100%",
975
+ justify: "between",
976
+ className: "oui-text-2xs oui-text-base-contrast",
977
+ children: [
978
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: t("common.current") }),
979
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 1, children: [
980
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text.numeral, { rule: "price", dp: 0, children: current_volume }),
981
+ /* @__PURE__ */ jsxRuntime.jsx(
982
+ ui.Text.numeral,
983
+ {
984
+ intensity: 54,
985
+ rule: "price",
986
+ dp: 0,
987
+ prefix: "/ ",
988
+ suffix: " USDC",
989
+ children: required_volume
990
+ }
991
+ )
992
+ ] })
993
+ ]
994
+ }
995
+ ),
996
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-h-[8px] oui-w-full oui-rounded-full oui-bg-base-contrast-4", children: /* @__PURE__ */ jsxRuntime.jsx(
997
+ "div",
998
+ {
999
+ style: {
1000
+ width: `${progressPercentage}%`
1001
+ },
1002
+ className: ui.cn(
1003
+ "oui-h-full oui-rounded-l-full oui-bg-primary-light",
1004
+ progressPercentage === 100 && "oui-rounded-r-full"
1005
+ )
1006
+ }
1007
+ ) })
1008
+ ] }),
1009
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "md", onClick: gotoTrade, ...props.buttonProps, children: t("affiliate.newReferralProgram.tradeUnlock") })
1010
+ ] });
1011
+ };
1012
+ var Hero = () => {
1013
+ const { t } = i18n.useTranslation();
1014
+ const { state } = hooks.useAccount();
1015
+ const { wrongNetwork } = reactApp.useAppContext();
1016
+ const status = state.status;
1017
+ const {
1018
+ isMultiLevelReferralUnlocked,
1019
+ isMultiLevelEnabled,
1020
+ multiLevelRebateInfo,
1021
+ multiLevelRebateInfoMutate,
1022
+ maxRebateRate
1023
+ } = useReferralContext();
1024
+ const onCreateReferralCode = () => {
1025
+ ui.modal.show(ReferralCodeFormDialogId, {
1026
+ type: "create" /* Create */,
1027
+ maxRebateRate,
1028
+ directBonusRebateRate: 10,
1029
+ // Hardcoded value before API is ready
1030
+ onSuccess: () => {
1031
+ multiLevelRebateInfoMutate();
1032
+ }
1033
+ });
1034
+ };
1035
+ const description = react.useMemo(() => {
1036
+ if (wrongNetwork) {
1037
+ return t("affiliate.wrongNetwork.description");
1038
+ }
1039
+ if (status === types.AccountStatusEnum.NotConnected) {
1040
+ return t("affiliate.newReferralProgram.description");
1041
+ }
1042
+ if (status > types.AccountStatusEnum.Connected && status < types.AccountStatusEnum.EnableTrading) {
1043
+ return t("affiliate.setUpAccount.description");
1044
+ }
1045
+ if (!isMultiLevelReferralUnlocked) {
1046
+ return "";
1047
+ }
1048
+ return t("affiliate.newReferralProgram.description");
1049
+ }, [t, wrongNetwork, status]);
1050
+ const renderContent = () => {
1051
+ if (!isMultiLevelReferralUnlocked) {
1052
+ return /* @__PURE__ */ jsxRuntime.jsx(
1053
+ TradingVolumeProgress,
1054
+ {
1055
+ classNames: {
1056
+ root: "oui-items-start",
1057
+ description: "!oui-text-start"
1058
+ },
1059
+ buttonProps: {
1060
+ size: "xl"
1061
+ }
1062
+ }
1063
+ );
1064
+ }
1065
+ if (isMultiLevelEnabled && !multiLevelRebateInfo?.referral_code) {
1066
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "lg", className: "oui-px-4", onClick: onCreateReferralCode, children: t("affiliate.referralCode.create") });
1067
+ }
1068
+ return "";
1069
+ };
1070
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1071
+ ui.Flex,
1072
+ {
1073
+ gap: 8,
1074
+ className: "oui-flex-col-reverse md:oui-flex-row",
1075
+ id: "oui-affiliate-landing-hero",
1076
+ itemAlign: "center",
1077
+ children: [
1078
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", itemAlign: "start", gap: 6, className: "oui-flex-1", children: [
1079
+ /* @__PURE__ */ jsxRuntime.jsx(
1080
+ ui.Flex,
1081
+ {
1082
+ direction: "column",
1083
+ gap: 3,
1084
+ itemAlign: "start",
1085
+ id: "oui-affiliate-landing-hero-title",
1086
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1087
+ ui.Text,
1088
+ {
1089
+ weight: "semibold",
1090
+ className: "oui-text-[32px] oui-leading-tight md:oui-text-[48px]",
1091
+ children: t("affiliate.landing.title")
1092
+ }
1093
+ )
1094
+ }
1095
+ ),
1096
+ description && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", intensity: 54, children: description }),
1097
+ /* @__PURE__ */ jsxRuntime.jsx(
1098
+ uiConnector.AuthGuard,
1099
+ {
1100
+ labels: {
1101
+ connectWallet: t("affiliate.connectWallet"),
1102
+ signin: t("affiliate.setUpAccount"),
1103
+ enableTrading: t("affiliate.setUpAccount")
1104
+ },
1105
+ children: renderContent()
1106
+ }
1107
+ )
1108
+ ] }),
1109
+ /* @__PURE__ */ jsxRuntime.jsx(
1110
+ "img",
1111
+ {
1112
+ src: "https://oss.orderly.network/static/sdk/referral/network-diagram.png",
1113
+ alt: "Network diagram",
1114
+ className: "oui-size-[335px] oui-object-cover md:oui-size-[480px]",
1115
+ id: "oui-affiliate-landing-network-diagram"
1116
+ }
1117
+ )
1118
+ ]
1119
+ }
1120
+ );
1121
+ };
1122
+ var StepCard = (props) => {
1123
+ const { step, icon, title, description } = props;
1124
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1125
+ ui.Flex,
1126
+ {
1127
+ direction: "column",
1128
+ gap: 3,
1129
+ r: "2xl",
1130
+ p: 5,
1131
+ itemAlign: "start",
1132
+ className: "oui-bg-base-9",
1133
+ children: [
1134
+ /* @__PURE__ */ jsxRuntime.jsx(
1135
+ ui.Flex,
1136
+ {
1137
+ justify: "center",
1138
+ className: "oui-rounded-full oui-bg-base-7 lg:oui-justify-start",
1139
+ p: 3,
1140
+ width: 48,
1141
+ height: 48,
1142
+ itemAlign: "center",
1143
+ children: renderIcon(icon)
1144
+ }
1145
+ ),
1146
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xl", weight: "semibold", children: `${step}. ${title}` }),
1147
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { intensity: 54, size: "sm", children: description })
1148
+ ]
1149
+ }
1150
+ );
1151
+ };
1152
+ var renderIcon = (iconType) => {
1153
+ switch (iconType) {
1154
+ case "wallet":
1155
+ return /* @__PURE__ */ jsxRuntime.jsx(WalletIcon, {});
1156
+ case "settings":
1157
+ return /* @__PURE__ */ jsxRuntime.jsx(SettingsIcon, {});
1158
+ case "rocket":
1159
+ return /* @__PURE__ */ jsxRuntime.jsx(RocketIcon, {});
1160
+ default:
1161
+ return null;
1162
+ }
1163
+ };
1164
+ var WalletIcon = () => /* @__PURE__ */ jsxRuntime.jsx(
1165
+ "svg",
1166
+ {
1167
+ width: "24",
1168
+ height: "24",
1169
+ viewBox: "0 0 24 24",
1170
+ fill: "none",
1171
+ xmlns: "http://www.w3.org/2000/svg",
1172
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1173
+ "path",
1174
+ {
1175
+ d: "M7.006 2.93a4 4 0 0 0-4 4v10a4 4 0 0 0 4 4h10c1.552 0 3-1.448 3-3l-.004-1.163a3.025 3.025 0 0 0 2.004-2.837v-4c0-1.268-.822-2.428-1.994-2.815l-.006-1.185c0-1.553-1.448-3-3-3zm0 2h10c.448 0 1 .552 1 1v1h-3a3 3 0 0 0-3 3v4a3 3 0 0 0 3 3h3v1c0 .447-.552 1-1 1h-10a2 2 0 0 1-2-2v-10a2 2 0 0 1 2-2m8 4h4a1 1 0 0 1 1 1v4a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1v-4a1 1 0 0 1 1-1m2 2a1 1 0 1 0 0 2 1 1 0 0 0 0-2",
1176
+ fill: "#fff",
1177
+ fillOpacity: ".54"
1178
+ }
1179
+ )
1180
+ }
1181
+ );
1182
+ var SettingsIcon = () => /* @__PURE__ */ jsxRuntime.jsx(
1183
+ "svg",
1184
+ {
1185
+ width: "24",
1186
+ height: "24",
1187
+ viewBox: "0 0 24 24",
1188
+ fill: "none",
1189
+ xmlns: "http://www.w3.org/2000/svg",
1190
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1191
+ "path",
1192
+ {
1193
+ d: "M14.99 2.93c-1.267 0-2.45.832-2.818 2.002L3.99 4.93a1 1 0 0 0 0 2l8.18-.001c.449 1.225 1.552 2 2.82 2s2.382-.777 2.838-2.008l2.162.009a1 1 0 0 0 0-2h-2.17c-.482-1.22-1.562-2-2.83-2m0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2m-6 4c-1.317 0-2.42.82-2.823 2.002-.14.009-2.176-.002-2.176-.002a1 1 0 0 0 0 2s2.052-.021 2.18-.008a2.95 2.95 0 0 0 2.82 2.008c1.268 0 2.354-.777 2.83-1.997l8.17-.003a1 1 0 0 0 0-2l-8.176-.01A3.01 3.01 0 0 0 8.99 8.93m0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2m6 4c-1.267 0-2.427.835-2.819 1.99l-8.18.01a1 1 0 0 0 0 2h8.165a3.02 3.02 0 0 0 2.835 2c1.268 0 2.36-.793 2.842-2h2.158a1 1 0 0 0 0-2l-2.167-.006a3.03 3.03 0 0 0-2.833-1.994m0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2",
1194
+ fill: "#fff",
1195
+ fillOpacity: ".54"
1196
+ }
1197
+ )
1198
+ }
1199
+ );
1200
+ var RocketIcon = () => /* @__PURE__ */ jsxRuntime.jsx(
1201
+ "svg",
1202
+ {
1203
+ width: "24",
1204
+ height: "24",
1205
+ viewBox: "0 0 24 24",
1206
+ fill: "none",
1207
+ xmlns: "http://www.w3.org/2000/svg",
1208
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1209
+ "path",
1210
+ {
1211
+ d: "M18.527 13.88c-.423.424-.884.808-1.345 1.154a.63.63 0 0 0-.269.423 9.2 9.2 0 0 1-2.459 4.346 10 10 0 0 1-1.883 1.462c-.576.346-1.268-.231-1.037-.885.384-1 .538-2.076.538-3.192-.077 0-.192.039-.27.039a39 39 0 0 1-2.612-2.423 51 51 0 0 1-2.42-2.615c0-.077.038-.193.038-.27-1.115 0-2.19.193-3.19.539-.614.23-1.23-.462-.883-1.039a10 10 0 0 1 1.46-1.884 9.2 9.2 0 0 1 4.342-2.461c.153-.039.307-.154.422-.27.346-.5.73-.923 1.153-1.346 2.997-3 7.185-4.038 11.066-3.153a.76.76 0 0 1 .538.538c.845 3.846-.192 8.038-3.189 11.038m-1.69-6.73a2.41 2.41 0 0 0-3.382 0 2.416 2.416 0 0 0 0 3.385 2.41 2.41 0 0 0 3.381 0c.96-.962.96-2.462 0-3.385M8.266 18.92c-.73.73-5.225 3.807-6.109 2.923-.884-.885 2.19-5.385 2.92-6.115s2.037-.616 2.92.269c.884.885 1 2.192.27 2.923",
1212
+ fill: "#fff",
1213
+ fillOpacity: ".54"
1214
+ }
1215
+ )
1216
+ }
1217
+ );
1218
+ var HowItWorks = () => {
1219
+ const { t } = i18n.useTranslation();
1220
+ const steps = react.useMemo(() => {
1221
+ return [
1222
+ {
1223
+ step: 1,
1224
+ icon: "wallet",
1225
+ title: t("affiliate.howItWorks.step1.title"),
1226
+ description: t("affiliate.howItWorks.step1.description")
1227
+ },
1228
+ {
1229
+ step: 2,
1230
+ icon: "settings",
1231
+ title: t("affiliate.howItWorks.step2.title"),
1232
+ description: t("affiliate.howItWorks.step2.description")
1233
+ },
1234
+ {
1235
+ step: 3,
1236
+ icon: "rocket",
1237
+ title: t("affiliate.howItWorks.step3.title"),
1238
+ description: t("affiliate.howItWorks.step3.description")
1239
+ }
1240
+ ];
1241
+ }, [t]);
1242
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { id: "oui-affiliate-landing-how-it-works", children: [
1243
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", itemAlign: "start", children: [
1244
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "semibold", className: "oui-text-[32px]", children: t("affiliate.howItWorks.title") }),
1245
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { py: 4, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { intensity: 54, children: t("affiliate.howItWorks.description") }) })
1246
+ ] }),
1247
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Grid, { className: "oui-grid-cols-1 md:oui-grid-cols-3", gap: 6, children: steps.map((step) => /* @__PURE__ */ jsxRuntime.jsx(
1248
+ StepCard,
1249
+ {
1250
+ step: step.step,
1251
+ icon: step.icon,
1252
+ title: step.title,
1253
+ description: step.description
1254
+ },
1255
+ step.step
1256
+ )) })
1257
+ ] });
1258
+ };
1259
+ var LandingPage = () => {
1260
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1261
+ ui.Flex,
1262
+ {
1263
+ id: "oui-affiliate-landing-page",
1264
+ direction: "column",
1265
+ gap: 10,
1266
+ itemAlign: "stretch",
1267
+ className: "oui-mx-auto oui-w-full oui-p-5 md:oui-w-[1040px] md:oui-py-12",
1268
+ children: [
1269
+ /* @__PURE__ */ jsxRuntime.jsx(Hero, {}),
1270
+ /* @__PURE__ */ jsxRuntime.jsx(HowItWorks, {}),
1271
+ /* @__PURE__ */ jsxRuntime.jsx(Faq, {})
1272
+ ]
1273
+ }
1274
+ );
1275
+ };
1276
+ var CommissionChart = (props) => {
1277
+ const { t } = i18n.useTranslation();
1278
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1279
+ ui.Flex,
1280
+ {
1281
+ id: "oui-affiliate-affiliate-titleStatistic",
1282
+ r: "2xl",
1283
+ p: 6,
1284
+ width: "100%",
1285
+ gap: 4,
1286
+ direction: "column",
1287
+ className: "oui-border oui-border-line-6 oui-bg-base-9",
1288
+ children: [
1289
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { justify: "between", width: "100%", children: [
1290
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "lg", children: `${t("affiliate.commission")} (USDC)` }),
1291
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
1292
+ ui.Select.options,
1293
+ {
1294
+ size: "xs",
1295
+ value: props.period,
1296
+ onValueChange: props.onPeriodChange,
1297
+ options: props.periodTypes
1298
+ }
1299
+ ) })
1300
+ ] }),
1301
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { className: "oui-flex oui-h-[170px] oui-w-full oui-flex-row oui-items-stretch 2xl:oui-h-[196px]", children: /* @__PURE__ */ jsxRuntime.jsx(
1302
+ chart.VolBarChart,
1303
+ {
1304
+ data: props.dataSource,
1305
+ colors: { fill: "rgba(0, 180, 158, 1)" },
1306
+ className: "oui-w-full oui-flex-1",
1307
+ tooltip: {
1308
+ rm: utils.Decimal.ROUND_DOWN,
1309
+ dp: 2
1310
+ }
1311
+ }
1312
+ ) })
1313
+ ]
1314
+ }
1315
+ );
1316
+ };
1317
+ function fillData(days, origin) {
1318
+ const now = Date();
1319
+ const result = new Array(days).fill(0).map((_, index) => {
1320
+ return {
1321
+ date: dateFns.format(dateFns.subDays(now, index + 1), "yyyy-MM-dd"),
1322
+ volume: 0,
1323
+ opacity: 0
1324
+ };
1325
+ }).reverse();
1326
+ const dataObject = origin?.reduce(
1327
+ (acc, curr) => {
1328
+ acc[curr.date] = curr;
1329
+ return acc;
1330
+ },
1331
+ {}
1332
+ );
1333
+ for (let index = 0; index < result.length; index++) {
1334
+ const element = result[index];
1335
+ const originData = dataObject?.[element.date];
1336
+ if (originData) {
1337
+ result[index] = { ...originData, opacity: originData.volume > 0 ? 1 : 0 };
1338
+ }
1339
+ }
1340
+ return result;
1341
+ }
1342
+
1343
+ // src/pages/multiLevel/affiliate/commissionChart/commissionChart.script.tsx
1344
+ var useCommissionChartScript = () => {
1345
+ const { t } = i18n.useTranslation();
1346
+ const [period, setPeriod] = react.useState("90");
1347
+ const periodTypes = react.useMemo(() => {
1348
+ return [
1349
+ { label: t("common.select.7d"), value: "7" },
1350
+ { label: t("common.select.30d"), value: "30" },
1351
+ { label: t("common.select.90d"), value: "90" }
1352
+ ];
1353
+ }, [t]);
1354
+ const onPeriodChange = (item) => {
1355
+ setPeriod(item);
1356
+ };
1357
+ const dateRange = react.useMemo(() => {
1358
+ const days = Number(period) || 7;
1359
+ const now = /* @__PURE__ */ new Date();
1360
+ return {
1361
+ startDate: dateFns.subDays(now, days),
1362
+ endDate: dateFns.subDays(now, 1)
1363
+ };
1364
+ }, [period]);
1365
+ const [rebateSummary] = hooks.useReferralRebateSummary({
1366
+ startDate: dateFns.format(dateRange.startDate, "yyyy-MM-dd"),
1367
+ endDate: dateFns.format(dateRange.endDate, "yyyy-MM-dd"),
1368
+ size: Number(period)
1369
+ });
1370
+ const dataSource = react.useMemo(() => {
1371
+ const data = (rebateSummary || [])?.map(
1372
+ (item) => ({
1373
+ date: item.date,
1374
+ volume: item.direct_rebate + item.indirect_rebate + item.direct_bonus_rebate
1375
+ })
1376
+ ) || [];
1377
+ data.reverse();
1378
+ return fillData(Number(period), data);
1379
+ }, [rebateSummary, period]);
1380
+ return {
1381
+ period,
1382
+ periodTypes,
1383
+ onPeriodChange,
1384
+ dataSource
1385
+ };
1386
+ };
1387
+ var CommissionChartWidget = () => {
1388
+ const state = useCommissionChartScript();
1389
+ return /* @__PURE__ */ jsxRuntime.jsx(CommissionChart, { ...state });
1390
+ };
1391
+ var MultiLevelReferral = (props) => {
1392
+ const { isMultiLevelReferralUnlocked } = props;
1393
+ const { t } = i18n.useTranslation();
1394
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1395
+ ui.Flex,
1396
+ {
1397
+ r: "2xl",
1398
+ width: "100%",
1399
+ height: "100%",
1400
+ gap: 4,
1401
+ p: 5,
1402
+ direction: "column",
1403
+ intensity: 900,
1404
+ className: "oui-border oui-border-line-6",
1405
+ children: [
1406
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "lg", className: "oui-w-full oui-text-start", children: t("affiliate.referral") }),
1407
+ /* @__PURE__ */ jsxRuntime.jsxs(
1408
+ ui.Flex,
1409
+ {
1410
+ width: "100%",
1411
+ height: "100%",
1412
+ direction: "column",
1413
+ itemAlign: "center",
1414
+ justify: "center",
1415
+ gap: 4,
1416
+ children: [
1417
+ /* @__PURE__ */ jsxRuntime.jsx(MultiLevelReferralIcon, { className: "oui-text-primary-light" }),
1418
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "base", intensity: 98, children: t("affiliate.newReferralProgram.title") }),
1419
+ isMultiLevelReferralUnlocked ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1420
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", intensity: 54, className: "oui-text-center", children: t("affiliate.newReferralProgram.description") }),
1421
+ /* @__PURE__ */ jsxRuntime.jsx(
1422
+ ui.Button,
1423
+ {
1424
+ size: "md",
1425
+ className: "oui-px-16",
1426
+ onClick: props.createReferralCode,
1427
+ children: t("affiliate.referralCode.create")
1428
+ }
1429
+ )
1430
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(
1431
+ TradingVolumeProgress,
1432
+ {
1433
+ buttonProps: {
1434
+ className: "oui-px-16"
1435
+ }
1436
+ }
1437
+ )
1438
+ ]
1439
+ }
1440
+ )
1441
+ ]
1442
+ }
1443
+ );
1444
+ };
1445
+ var MultiLevelReferralIcon = (props) => /* @__PURE__ */ jsxRuntime.jsxs(
1446
+ "svg",
1447
+ {
1448
+ width: 64,
1449
+ height: 64,
1450
+ viewBox: "0 0 64 64",
1451
+ fill: "currentColor",
1452
+ xmlns: "http://www.w3.org/2000/svg",
1453
+ ...props,
1454
+ children: [
1455
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { width: 64, height: 64, rx: 32, fill: "rgb(var(--oui-color-base-8))" }),
1456
+ /* @__PURE__ */ jsxRuntime.jsx(
1457
+ "path",
1458
+ {
1459
+ fillRule: "evenodd",
1460
+ clipRule: "evenodd",
1461
+ d: "M28.822 23.24a.86.86 0 0 1 .607-.24h5.142c.228 0 .446.086.607.24a.8.8 0 0 1 .25.579v3.28a.8.8 0 0 1-.25.578.88.88 0 0 1-.607.24h-1.719v3.259h7.714c.228 0 .446.086.606.24a.8.8 0 0 1 .251.578v4.094h1.72c.227 0 .445.086.606.24a.8.8 0 0 1 .251.578v3.275a.8.8 0 0 1-.251.58.88.88 0 0 1-.606.239H38a.88.88 0 0 1-.606-.24.8.8 0 0 1-.251-.579v-3.274a.8.8 0 0 1 .25-.58.88.88 0 0 1 .607-.24h1.71v-3.274h-6.858v3.275h1.72c.227 0 .445.086.605.24a.8.8 0 0 1 .252.578v3.275a.8.8 0 0 1-.252.58.88.88 0 0 1-.606.239H29.43a.88.88 0 0 1-.606-.24.8.8 0 0 1-.252-.579v-3.274a.8.8 0 0 1 .252-.58.88.88 0 0 1 .606-.24h1.709v-3.274H24.28v3.275H26c.227 0 .445.086.606.24a.8.8 0 0 1 .251.578v3.275a.8.8 0 0 1-.25.58A.88.88 0 0 1 26 41h-5.143a.88.88 0 0 1-.606-.24.8.8 0 0 1-.251-.579v-3.274a.8.8 0 0 1 .251-.58.88.88 0 0 1 .606-.24h1.71v-4.093a.8.8 0 0 1 .25-.579.88.88 0 0 1 .606-.24h7.715v-3.258h-1.71a.88.88 0 0 1-.605-.24.8.8 0 0 1-.252-.579V23.82q0-.163.065-.313a.8.8 0 0 1 .186-.268"
1462
+ }
1463
+ )
1464
+ ]
1465
+ }
1466
+ );
1467
+ var useMultiLevelReferralScript = () => {
1468
+ const {
1469
+ isMultiLevelReferralUnlocked,
1470
+ maxRebateRate,
1471
+ multiLevelRebateInfoMutate
1472
+ } = useReferralContext();
1473
+ const createReferralCode = () => {
1474
+ ui.modal.show(ReferralCodeFormDialogId, {
1475
+ type: "create" /* Create */,
1476
+ maxRebateRate,
1477
+ directBonusRebateRate: 10,
1478
+ // Hardcoded value before API is ready
1479
+ onSuccess: () => {
1480
+ multiLevelRebateInfoMutate();
1481
+ }
1482
+ });
1483
+ };
1484
+ return {
1485
+ isMultiLevelReferralUnlocked,
1486
+ createReferralCode
1487
+ };
1488
+ };
1489
+ var MultiLevelReferralWidget = () => {
1490
+ const state = useMultiLevelReferralScript();
1491
+ return /* @__PURE__ */ jsxRuntime.jsx(MultiLevelReferral, { ...state });
1492
+ };
1493
+ var ReferralInfo = (props) => {
1494
+ const { t } = i18n.useTranslation();
1495
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1496
+ ui.Flex,
1497
+ {
1498
+ id: "oui-affiliate-affiliate-referralLink",
1499
+ r: "2xl",
1500
+ width: "100%",
1501
+ height: "100%",
1502
+ gap: 4,
1503
+ p: 5,
1504
+ direction: "column",
1505
+ intensity: 900,
1506
+ className: "oui-border oui-border-line-6",
1507
+ children: [
1508
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "row", justify: "between", width: "100%", children: [
1509
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "lg", children: t("affiliate.referral") }),
1510
+ /* @__PURE__ */ jsxRuntime.jsx(
1511
+ ui.Button,
1512
+ {
1513
+ size: "xs",
1514
+ color: "secondary",
1515
+ onClick: () => props.onEdit("referralCode" /* ReferralCode */),
1516
+ children: t("affiliate.configure")
1517
+ }
1518
+ )
1519
+ ] }),
1520
+ /* @__PURE__ */ jsxRuntime.jsxs(Container, { className: "oui-flex-col oui-items-start oui-gap-4 oui-p-5", children: [
1521
+ /* @__PURE__ */ jsxRuntime.jsx(
1522
+ ui.Flex,
1523
+ {
1524
+ r: "full",
1525
+ px: 2,
1526
+ height: 20,
1527
+ justify: "center",
1528
+ itemAlign: "center",
1529
+ className: "oui-border oui-border-primary-light",
1530
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { intensity: 98, className: "oui-text-[10px] oui-leading-[10px]", children: t("affiliate.multiLevel") })
1531
+ }
1532
+ ),
1533
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "row", justify: "between", width: "100%", children: [
1534
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "lg", color: "primaryLight", children: props.referralCode }),
1535
+ /* @__PURE__ */ jsxRuntime.jsx(CopyButton, { value: props.referralCode })
1536
+ ] })
1537
+ ] }),
1538
+ /* @__PURE__ */ jsxRuntime.jsxs(Container, { className: "oui-p-5", children: [
1539
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "lg", color: "primaryLight", children: props.referralLink }),
1540
+ /* @__PURE__ */ jsxRuntime.jsx(CopyButton, { value: props.referralLink })
1541
+ ] }),
1542
+ /* @__PURE__ */ jsxRuntime.jsxs(
1543
+ ui.Box,
1544
+ {
1545
+ width: "100%",
1546
+ r: "2xl",
1547
+ className: "oui-bg-base-contrast-4 oui-p-5 md:oui-py-7",
1548
+ children: [
1549
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "row", justify: "between", width: "100%", children: [
1550
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", children: t("affiliate.revenueSplitStrategy") }),
1551
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "xs", color: "secondary", onClick: () => props.onEdit(), children: t("common.edit") })
1552
+ ] }),
1553
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { justify: "between", width: "100%", mt: 4, children: [
1554
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", intensity: 54, children: t("affiliate.youKeep") }),
1555
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", intensity: 54, children: t("affiliate.refereesGet") })
1556
+ ] }),
1557
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { justify: "between", width: "100%", mt: 2, children: [
1558
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text.formatted, { size: "3xl", intensity: 80, children: [
1559
+ props.referrerRebateRate,
1560
+ "%"
1561
+ ] }),
1562
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text.formatted, { size: "3xl", intensity: 36, children: [
1563
+ props.refereeRebateRate,
1564
+ "%"
1565
+ ] })
1566
+ ] }),
1567
+ props.directBonusRebateRate > 0 && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, mt: 4, width: "100%", className: "oui-items-center", children: [
1568
+ /* @__PURE__ */ jsxRuntime.jsx(
1569
+ GiftIcon,
1570
+ {
1571
+ size: 16,
1572
+ className: "oui-shrink-0 oui-text-base-contrast oui-mt-[1px]"
1573
+ }
1574
+ ),
1575
+ /* @__PURE__ */ jsxRuntime.jsx(
1576
+ ui.Text,
1577
+ {
1578
+ intensity: 54,
1579
+ as: "span",
1580
+ className: "oui-flex-1 oui-min-w-0 oui-tracking-[0.03em]",
1581
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1582
+ i18n.Trans,
1583
+ {
1584
+ i18nKey: "affiliate.extraBonusOnDirectReferrals",
1585
+ values: { amount: props.directBonusRebateRate },
1586
+ components: [/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { as: "span", color: "primaryLight" }, "0")]
1587
+ }
1588
+ )
1589
+ }
1590
+ )
1591
+ ] })
1592
+ ]
1593
+ }
1594
+ )
1595
+ ]
1596
+ }
1597
+ );
1598
+ };
1599
+ var Container = (props) => {
1600
+ return /* @__PURE__ */ jsxRuntime.jsx(
1601
+ ui.Flex,
1602
+ {
1603
+ width: "100%",
1604
+ justify: "between",
1605
+ px: 5,
1606
+ r: "2xl",
1607
+ className: ui.cn("oui-bg-base-contrast-4", props.className),
1608
+ children: props.children
1609
+ }
1610
+ );
1611
+ };
1612
+ var CopyButton = (props) => {
1613
+ const { t } = i18n.useTranslation();
1614
+ const onCopy = () => {
1615
+ if (!props.value) return;
1616
+ navigator.clipboard.writeText(props.value);
1617
+ ui.toast.success(t("common.copy.copied"));
1618
+ };
1619
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "xs", color: "secondary", onClick: onCopy, children: t("common.copy") });
1620
+ };
1621
+ function generateReferralLink(referralLinkUrl, code) {
1622
+ return `${referralLinkUrl || window?.location?.origin}?ref=${code}`;
1623
+ }
1624
+ async function copyText(content) {
1625
+ try {
1626
+ await navigator.clipboard.writeText(content);
1627
+ ui.toast.success(i18n.i18n.t("common.copy.copied"));
1628
+ } catch (error) {
1629
+ ui.toast.success(i18n.i18n.t("common.copy.failed"));
1630
+ }
1631
+ }
1632
+ function formatDateTimeToUTC(input) {
1633
+ if (input === void 0) {
1634
+ return "";
1635
+ }
1636
+ const date = dateFns.toDate(input);
1637
+ const utcDate = toUTCDate(date);
1638
+ return dateFns.format(utcDate, "yyyy-MM-dd HH:mm:ss 'UTC'");
1639
+ }
1640
+ function formatYMDTime(time) {
1641
+ if (time === void 0) {
1642
+ return void 0;
1643
+ }
1644
+ const date = dateFns.toDate(time);
1645
+ const utcDate = toUTCDate(date);
1646
+ return dateFns.format(utcDate, "yyyy-MM-dd");
1647
+ }
1648
+ function compareDate(d1, d2) {
1649
+ const isEqual = d1 && d2 && d1.toISOString().substring(0, 10) === d2.toISOString().substring(0, 10);
1650
+ return isEqual;
1651
+ }
1652
+ function toUTCDate(date) {
1653
+ return new Date(date.toUTCString());
1654
+ }
1655
+
1656
+ // src/pages/multiLevel/affiliate/referralInfo/referralInfo.script.tsx
1657
+ var useReferralInfoScript = () => {
1658
+ const {
1659
+ referralLinkUrl,
1660
+ multiLevelRebateInfo,
1661
+ multiLevelRebateInfoMutate,
1662
+ maxRebateRate
1663
+ } = useReferralContext();
1664
+ const referralCode = multiLevelRebateInfo?.referral_code;
1665
+ const referralLink = react.useMemo(() => {
1666
+ if (!referralCode) return "";
1667
+ return generateReferralLink(referralLinkUrl, referralCode);
1668
+ }, [referralCode]);
1669
+ const referrerRebateRate = react.useMemo(() => {
1670
+ return new utils.Decimal(multiLevelRebateInfo?.referrer_rebate_rate || 0).mul(100).toNumber();
1671
+ }, [multiLevelRebateInfo]);
1672
+ const refereeRebateRate = react.useMemo(() => {
1673
+ return new utils.Decimal(multiLevelRebateInfo?.referee_rebate_rate || 0).mul(100).toNumber();
1674
+ }, [multiLevelRebateInfo]);
1675
+ const directBonusRebateRate = react.useMemo(() => {
1676
+ return new utils.Decimal(multiLevelRebateInfo?.direct_bonus_rebate_rate ?? 0).mul(100).toNumber();
1677
+ }, [multiLevelRebateInfo]);
1678
+ const onEdit = (focusField) => {
1679
+ ui.modal.show(ReferralCodeFormDialogId, {
1680
+ type: "edit" /* Edit */,
1681
+ focusField,
1682
+ referralCode: multiLevelRebateInfo?.referral_code,
1683
+ maxRebateRate,
1684
+ referrerRebateRate: multiLevelRebateInfo?.referrer_rebate_rate,
1685
+ directInvites: multiLevelRebateInfo?.direct_invites,
1686
+ directBonusRebateRate,
1687
+ onSuccess: () => {
1688
+ multiLevelRebateInfoMutate();
1689
+ }
1690
+ });
1691
+ };
1692
+ return {
1693
+ onEdit,
1694
+ referralCode,
1695
+ referralLink,
1696
+ multiLevelRebateInfo,
1697
+ referrerRebateRate,
1698
+ refereeRebateRate,
1699
+ directBonusRebateRate
1700
+ };
1701
+ };
1702
+ var ReferralInfoWidget = () => {
1703
+ const state = useReferralInfoScript();
1704
+ return /* @__PURE__ */ jsxRuntime.jsx(ReferralInfo, { ...state });
1705
+ };
1706
+ var useReferrerTableScript = () => {
1707
+ const [activeTab, _setActiveTab] = react.useState("commission");
1708
+ const setActiveTab = (tab) => _setActiveTab(tab);
1709
+ return {
1710
+ activeTab,
1711
+ setActiveTab
1712
+ };
1713
+ };
1714
+ var useReferralHistory = (params) => {
1715
+ const { size, startDate, endDate, page, fetchAll, enabled = true } = params;
1716
+ const query = react.useMemo(() => {
1717
+ if (!enabled) return null;
1718
+ const search = new URLSearchParams({
1719
+ ...startDate ? { start_date: startDate } : {},
1720
+ ...endDate ? { end_date: endDate } : {},
1721
+ ...!fetchAll && page !== void 0 ? { page: String(page) } : {},
1722
+ ...!fetchAll && size !== void 0 ? { size: String(size) } : {}
1723
+ });
1724
+ const qs = search.toString();
1725
+ return qs ? `/v1/referral/referral_history?${qs}` : "/v1/referral/referral_history";
1726
+ }, [enabled, endDate, fetchAll, page, size, startDate]);
1727
+ const response = hooks.usePrivateQuery(query, {
1728
+ formatter: (data) => data,
1729
+ revalidateOnFocus: false
1730
+ });
1731
+ const loadMore = () => {
1732
+ };
1733
+ const meta = react.useMemo(() => {
1734
+ const payload = response.data?.data ?? response.data;
1735
+ if (payload?.meta) return payload.meta;
1736
+ if (!payload?.rows) return void 0;
1737
+ return {
1738
+ total: payload.rows.length,
1739
+ records_per_page: payload.rows.length,
1740
+ current_page: 1
1741
+ };
1742
+ }, [response.data]);
1743
+ const total = react.useMemo(() => {
1744
+ if (typeof meta?.total === "number") return meta.total;
1745
+ return 0;
1746
+ }, [meta]);
1747
+ const flattenRows = react.useMemo(() => {
1748
+ if (!response.data) return null;
1749
+ const payload = response.data?.data ?? response.data;
1750
+ return payload?.rows ?? null;
1751
+ }, [response.data]);
1752
+ return [
1753
+ flattenRows,
1754
+ {
1755
+ total,
1756
+ isLoading: response.isLoading,
1757
+ refresh: response.mutate,
1758
+ loadMore,
1759
+ meta
1760
+ }
1761
+ ];
1762
+ };
1763
+
1764
+ // src/pages/multiLevel/affiliate/referrerTable/commissionTable/commissionTable.script.tsx
1765
+ var useCommissionTableScript = (props = {}) => {
1766
+ const { enabled = true } = props;
1767
+ const { isMobile } = ui.useScreen();
1768
+ const { state } = hooks.useAccount();
1769
+ const [dateRange, setDateRange] = react.useState({
1770
+ from: dateFns.subDays(/* @__PURE__ */ new Date(), 30),
1771
+ to: /* @__PURE__ */ new Date()
1772
+ });
1773
+ const { page, pageSize, parsePagination } = ui.usePagination();
1774
+ const [sort, setSort] = react.useState(null);
1775
+ const [data, { meta, isLoading: isDataLoading }] = useReferralHistory({
1776
+ enabled: enabled && state.status >= types.AccountStatusEnum.EnableTrading,
1777
+ startDate: dateRange.from ? dateFns.format(dateRange.from, "yyyy-MM-dd") : void 0,
1778
+ endDate: dateRange.to ? dateFns.format(dateRange.to, "yyyy-MM-dd") : void 0,
1779
+ page: isMobile ? void 0 : page,
1780
+ size: isMobile ? void 0 : pageSize,
1781
+ fetchAll: isMobile
1782
+ });
1783
+ const pagination = react.useMemo(() => {
1784
+ return parsePagination(meta);
1785
+ }, [meta, parsePagination]);
1786
+ const commissionData = react.useMemo(() => {
1787
+ if (!data) return [];
1788
+ const rows = data.map((row) => ({
1789
+ date: row.date,
1790
+ code: row.referral_code,
1791
+ volume: row.volume,
1792
+ commission: row.referral_rebate,
1793
+ directBonusRebate: row.direct_bonus_rebate,
1794
+ address: row.user_address
1795
+ }));
1796
+ if (!sort) return rows;
1797
+ rows.sort((a, b) => {
1798
+ const valA = a[sort.key];
1799
+ const valB = b[sort.key];
1800
+ if (valA < valB) return sort.order === "asc" ? -1 : 1;
1801
+ if (valA > valB) return sort.order === "asc" ? 1 : -1;
1802
+ return 0;
1803
+ });
1804
+ return rows;
1805
+ }, [data, sort]);
1806
+ const onSort = (sort2) => {
1807
+ if (!sort2) {
1808
+ setSort(null);
1809
+ return;
1810
+ }
1811
+ const sortKey = sort2.sortKey;
1812
+ if (sortKey && (sortKey === "volume" || sortKey === "commission")) {
1813
+ setSort({
1814
+ key: sortKey,
1815
+ order: sort2.sort === "asc" ? "asc" : "desc"
1816
+ });
1817
+ }
1818
+ };
1819
+ return {
1820
+ commissionData,
1821
+ dateRange,
1822
+ setDateRange,
1823
+ pagination,
1824
+ onSort,
1825
+ isLoading: state.status < types.AccountStatusEnum.EnableTrading || !enabled || isDataLoading
1826
+ };
1827
+ };
1828
+ var dashedUnderline = "oui-cursor-pointer oui-underline oui-decoration-dashed oui-underline-offset-4 oui-decoration-base-contrast-36 oui-tracking-[0.03em]";
1829
+ var useMobileTooltipModal = (content, title) => {
1830
+ const { isMobile } = ui.useScreen();
1831
+ return react.useCallback(
1832
+ (e) => {
1833
+ if (!isMobile) return;
1834
+ e.preventDefault();
1835
+ e.stopPropagation();
1836
+ ui.modal.dialog({
1837
+ title,
1838
+ closable: true,
1839
+ size: "sm",
1840
+ content: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-text-sm oui-leading-5 oui-text-base-contrast", children: content })
1841
+ });
1842
+ },
1843
+ [isMobile, content, title]
1844
+ );
1845
+ };
1846
+ var AddressCell = ({ address, title }) => {
1847
+ const onClick = useMobileTooltipModal(address, title);
1848
+ const { isMobile } = ui.useScreen();
1849
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: address, open: isMobile ? false : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: dashedUnderline, onClick, children: ui.formatAddress(address) }) });
1850
+ };
1851
+ var TooltipCell = ({ text, tooltip, title }) => {
1852
+ const onClick = useMobileTooltipModal(tooltip, title);
1853
+ const { isMobile } = ui.useScreen();
1854
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: tooltip, open: isMobile ? false : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: dashedUnderline, onClick, children: text }) });
1855
+ };
1856
+ var BreakdownCell = ({ total, direct, indirect, directBonus, prefix, fix = 0, title }) => {
1857
+ const { t } = i18n.useTranslation();
1858
+ const format9 = (val) => utils.commifyOptional(val, {
1859
+ fix,
1860
+ fallback: "0",
1861
+ padEnd: true,
1862
+ prefix
1863
+ });
1864
+ const directLine = directBonus ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1865
+ "\u2022 ",
1866
+ t("affiliate.direct"),
1867
+ ": ",
1868
+ format9(direct + directBonus),
1869
+ " ",
1870
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "oui-text-base-contrast-54", children: [
1871
+ "(",
1872
+ t("affiliate.directInclBonus", { amount: format9(directBonus) }),
1873
+ ")"
1874
+ ] })
1875
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1876
+ "\u2022 ",
1877
+ t("affiliate.direct"),
1878
+ ": ",
1879
+ format9(direct)
1880
+ ] });
1881
+ const tooltipContent = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-flex oui-flex-col oui-gap-1", children: [
1882
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: directLine }),
1883
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1884
+ "\u2022 ",
1885
+ t("affiliate.indirect"),
1886
+ ": ",
1887
+ format9(indirect)
1888
+ ] })
1889
+ ] });
1890
+ const onClick = useMobileTooltipModal(tooltipContent, title);
1891
+ const { isMobile } = ui.useScreen();
1892
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: tooltipContent, open: isMobile ? false : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: dashedUnderline, onClick, children: format9(total) }) });
1893
+ };
1894
+ var MobileCell = ({ label, children, align = "start", className }) => {
1895
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1896
+ ui.Flex,
1897
+ {
1898
+ direction: "column",
1899
+ itemAlign: align,
1900
+ className: ui.cn(
1901
+ "oui-gap-1.5 oui-font-medium oui-tracking-[0.01em]",
1902
+ className
1903
+ ),
1904
+ children: [
1905
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { intensity: 36, size: "2xs", className: "oui-leading-[15px]", children: label }),
1906
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-text-sm oui-leading-[20px]", children })
1907
+ ]
1908
+ }
1909
+ );
1910
+ };
1911
+ var MobileCard = ({ children, className }) => {
1912
+ return /* @__PURE__ */ jsxRuntime.jsx(
1913
+ ui.Grid,
1914
+ {
1915
+ cols: 3,
1916
+ py: 3,
1917
+ r: "xl",
1918
+ width: "100%",
1919
+ className: ui.cn("oui-bg-base-9 oui-gap-x-[6px] oui-gap-y-3", className),
1920
+ children
1921
+ }
1922
+ );
1923
+ };
1924
+ var formatCommissionAmt = (v) => utils.commifyOptional(v, {
1925
+ fix: 6,
1926
+ fallback: "0",
1927
+ padEnd: true,
1928
+ prefix: "$"
1929
+ });
1930
+ var CommissionCell = ({ item }) => {
1931
+ const { t } = i18n.useTranslation();
1932
+ const totalCommission = item.commission + item.directBonusRebate;
1933
+ const tooltip = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1934
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1935
+ "\u2022 ",
1936
+ t("affiliate.base"),
1937
+ ": ",
1938
+ formatCommissionAmt(item.commission)
1939
+ ] }),
1940
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1941
+ "\u2022 ",
1942
+ t("affiliate.directBonus"),
1943
+ ":",
1944
+ " ",
1945
+ formatCommissionAmt(item.directBonusRebate)
1946
+ ] })
1947
+ ] });
1948
+ return /* @__PURE__ */ jsxRuntime.jsx(
1949
+ TooltipCell,
1950
+ {
1951
+ text: formatCommissionAmt(totalCommission),
1952
+ tooltip,
1953
+ title: t("affiliate.commission")
1954
+ }
1955
+ );
1956
+ };
1957
+ var MobileCommissionItem = ({ item }) => {
1958
+ const { t } = i18n.useTranslation();
1959
+ return /* @__PURE__ */ jsxRuntime.jsxs(MobileCard, { children: [
1960
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("common.date"), children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: formatYMDTime(item.date) }) }),
1961
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("common.code"), children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: item.code }) }),
1962
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("common.volume"), align: "end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: utils.commifyOptional(item.volume, {
1963
+ fix: 2,
1964
+ fallback: "0",
1965
+ padEnd: true,
1966
+ prefix: "$"
1967
+ }) }) }),
1968
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("affiliate.commission"), children: /* @__PURE__ */ jsxRuntime.jsx(CommissionCell, { item }) }),
1969
+ /* @__PURE__ */ jsxRuntime.jsx(
1970
+ MobileCell,
1971
+ {
1972
+ label: t("common.address"),
1973
+ align: "end",
1974
+ className: "oui-col-start-3",
1975
+ children: /* @__PURE__ */ jsxRuntime.jsx(AddressCell, { address: item.address, title: t("common.address") })
1976
+ }
1977
+ )
1978
+ ] });
1979
+ };
1980
+ var CommissionTableUI = (props) => {
1981
+ const { t } = i18n.useTranslation();
1982
+ const { isMobile } = ui.useScreen();
1983
+ const showPagination = (props.pagination?.count ?? 0) >= 10;
1984
+ const columns = react.useMemo(() => {
1985
+ return [
1986
+ {
1987
+ title: t("common.date"),
1988
+ dataIndex: "date",
1989
+ render: (value) => formatYMDTime(value)
1990
+ },
1991
+ {
1992
+ title: t("common.code"),
1993
+ dataIndex: "code"
1994
+ },
1995
+ {
1996
+ title: t("common.volume"),
1997
+ dataIndex: "volume",
1998
+ render: (value) => /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: utils.commifyOptional(value, {
1999
+ fix: 2,
2000
+ fallback: "0",
2001
+ padEnd: true,
2002
+ prefix: "$"
2003
+ }) }),
2004
+ onSort: true
2005
+ },
2006
+ {
2007
+ title: t("affiliate.commission"),
2008
+ dataIndex: "commission",
2009
+ render: (_value, record) => /* @__PURE__ */ jsxRuntime.jsx(CommissionCell, { item: record }),
2010
+ onSort: true
2011
+ },
2012
+ {
2013
+ title: t("common.address"),
2014
+ dataIndex: "address",
2015
+ render: (value) => /* @__PURE__ */ jsxRuntime.jsx(AddressCell, { address: value, title: t("common.address") })
2016
+ }
2017
+ ];
2018
+ }, [t]);
2019
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-flex oui-w-full oui-flex-col", children: [
2020
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { width: "100%", height: 49, className: "oui-border-b oui-border-line-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-px-3", children: /* @__PURE__ */ jsxRuntime.jsx(
2021
+ ui.DatePicker.range,
2022
+ {
2023
+ size: "xs",
2024
+ value: props.dateRange,
2025
+ onChange: props.setDateRange,
2026
+ max: 90,
2027
+ disabled: { after: /* @__PURE__ */ new Date() }
2028
+ }
2029
+ ) }) }),
2030
+ isMobile ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-flex oui-flex-col oui-px-4", children: /* @__PURE__ */ jsxRuntime.jsx(
2031
+ ui.ListView,
2032
+ {
2033
+ dataSource: props.commissionData,
2034
+ contentClassName: "!oui-space-y-0 oui-pb-3",
2035
+ renderItem: (item, index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2036
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCommissionItem, { item }),
2037
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { intensity: 8 })
2038
+ ] }, index)
2039
+ }
2040
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: `oui-px-3 ${showPagination ? "" : "oui-pb-3"}`, children: /* @__PURE__ */ jsxRuntime.jsx(
2041
+ uiConnector.AuthGuardDataTable,
2042
+ {
2043
+ bordered: true,
2044
+ columns,
2045
+ dataSource: props.commissionData,
2046
+ loading: props.isLoading,
2047
+ pagination: showPagination ? props.pagination : void 0,
2048
+ onSort: props.onSort,
2049
+ onRow: () => ({ className: "oui-h-12" }),
2050
+ className: "[&_.oui-h-10.oui-w-full]:!oui-mx-0 [&_.oui-table-pagination]:!oui-justify-end [&_th]:!oui-tracking-[0.03em] [&_th]:!oui-px-3 [&_td]:!oui-px-3"
2051
+ }
2052
+ ) })
2053
+ ] });
2054
+ };
2055
+ var CommissionTableWidget = (props) => {
2056
+ const state = useCommissionTableScript(props);
2057
+ return /* @__PURE__ */ jsxRuntime.jsx(CommissionTableUI, { ...state });
2058
+ };
2059
+ var useMultiLevelReferees = (params = {}) => {
2060
+ const { enabled = true, fetchAll = false, page, pageSize } = params;
2061
+ const { state } = hooks.useAccount();
2062
+ const canQuery = enabled && state.status >= types.AccountStatusEnum.EnableTrading;
2063
+ const queryKey = react.useMemo(() => {
2064
+ if (!canQuery) return null;
2065
+ if (fetchAll) return "/v1/referral/multi_level/referee_list";
2066
+ if (page !== void 0 && pageSize !== void 0) {
2067
+ return `/v1/referral/multi_level/referee_list?page=${page}&size=${pageSize}`;
2068
+ }
2069
+ return "/v1/referral/multi_level/referee_list";
2070
+ }, [canQuery, fetchAll, page, pageSize]);
2071
+ const response = hooks.usePrivateQuery(queryKey, {
2072
+ formatter: (payload) => {
2073
+ const rows = payload.rows ?? payload.data?.rows ?? [];
2074
+ const meta = payload.meta ?? payload.data?.meta;
2075
+ return {
2076
+ ...payload,
2077
+ meta,
2078
+ rows: rows.map((row) => ({
2079
+ ...row,
2080
+ network_size: row.direct_invites + row.indirect_invites,
2081
+ volume: row.direct_volume + row.indirect_volume,
2082
+ commission: row.direct_rebate + row.indirect_rebate + row.direct_bonus_rebate
2083
+ }))
2084
+ };
2085
+ },
2086
+ revalidateOnFocus: false
2087
+ });
2088
+ return {
2089
+ ...response,
2090
+ isLoading: state.status < types.AccountStatusEnum.EnableTrading || !enabled || response.isLoading,
2091
+ rows: response.data?.rows ?? [],
2092
+ meta: response.data?.meta
2093
+ };
2094
+ };
2095
+
2096
+ // src/pages/multiLevel/affiliate/referrerTable/refereesTable/refereesTable.script.tsx
2097
+ var useRefereesTableScript = (props = {}) => {
2098
+ const { enabled = true } = props;
2099
+ const { isMobile } = ui.useScreen();
2100
+ const refereesPaginationUtils = ui.usePagination();
2101
+ const [refereesSort, setRefereesSort] = react.useState(null);
2102
+ const {
2103
+ isLoading: isRefereesLoading,
2104
+ mutate: refereesMutate,
2105
+ rows: refereesRows,
2106
+ meta: refereesMeta
2107
+ } = useMultiLevelReferees({
2108
+ enabled,
2109
+ fetchAll: isMobile,
2110
+ page: refereesPaginationUtils.page,
2111
+ pageSize: refereesPaginationUtils.pageSize
2112
+ });
2113
+ const refereesPagination = react.useMemo(() => {
2114
+ return refereesPaginationUtils.parsePagination(refereesMeta);
2115
+ }, [refereesMeta, refereesPaginationUtils]);
2116
+ const { multiLevelRebateInfo, maxRebateRate, multiLevelRebateInfoMutate } = useReferralContext();
2117
+ const onEditReferee = react.useCallback(
2118
+ (type, item) => {
2119
+ const referrerRebateRate = type === "reset" /* Reset */ ? multiLevelRebateInfo?.referrer_rebate_rate : item.referral_rebate_rate;
2120
+ ui.modal.show(ReferralCodeFormDialogId, {
2121
+ type,
2122
+ referralCode: multiLevelRebateInfo?.referral_code,
2123
+ maxRebateRate,
2124
+ referrerRebateRate,
2125
+ onSuccess: () => {
2126
+ multiLevelRebateInfoMutate();
2127
+ refereesMutate();
2128
+ },
2129
+ accountId: item.account_id,
2130
+ multiLevelRebateInfo,
2131
+ directInvites: multiLevelRebateInfo?.direct_invites,
2132
+ directBonusRebateRate: new utils.Decimal(
2133
+ multiLevelRebateInfo?.direct_bonus_rebate_rate ?? 0
2134
+ ).mul(100).toNumber()
2135
+ });
2136
+ },
2137
+ [
2138
+ maxRebateRate,
2139
+ multiLevelRebateInfo?.referral_code,
2140
+ multiLevelRebateInfo?.referrer_rebate_rate,
2141
+ multiLevelRebateInfoMutate,
2142
+ refereesMutate
2143
+ ]
2144
+ );
2145
+ const refereesData = react.useMemo(() => {
2146
+ const rows = refereesRows ?? [];
2147
+ if (!refereesSort) return rows;
2148
+ const sortableRows = rows.map((row, index) => ({
2149
+ row,
2150
+ index
2151
+ }));
2152
+ sortableRows.sort((a, b) => {
2153
+ const valA = Number(a.row[refereesSort.key] ?? 0);
2154
+ const valB = Number(b.row[refereesSort.key] ?? 0);
2155
+ if (valA < valB) return refereesSort.order === "asc" ? -1 : 1;
2156
+ if (valA > valB) return refereesSort.order === "asc" ? 1 : -1;
2157
+ return a.index - b.index;
2158
+ });
2159
+ return sortableRows.map((item) => item.row);
2160
+ }, [refereesRows, refereesSort]);
2161
+ const onRefereesSort = (sort) => {
2162
+ if (!sort) {
2163
+ setRefereesSort(null);
2164
+ return;
2165
+ }
2166
+ const sortKey = sort.sortKey;
2167
+ if (sortKey && (sortKey === "referee_rebate_rate" || sortKey === "network_size" || sortKey === "volume" || sortKey === "commission")) {
2168
+ setRefereesSort({
2169
+ key: sortKey,
2170
+ order: sort.sort === "asc" ? "asc" : "desc"
2171
+ });
2172
+ }
2173
+ };
2174
+ return {
2175
+ refereesData,
2176
+ refereesPagination,
2177
+ isRefereesLoading,
2178
+ onEditReferee,
2179
+ onRefereesSort
2180
+ };
2181
+ };
2182
+ var getRebateRateText = (rate) => {
2183
+ return (rate * 100).toFixed(0) + "%";
2184
+ };
2185
+ var getRefereeType = (bindType) => {
2186
+ const { t } = i18n.useTranslation();
2187
+ if (bindType === "legacy") {
2188
+ return {
2189
+ text: t("affiliate.singleLevelLegacy"),
2190
+ tooltip: t("affiliate.singleLevelLegacy.tooltip")
2191
+ };
2192
+ }
2193
+ return {
2194
+ text: t("affiliate.multiLevel"),
2195
+ tooltip: t("affiliate.multiLevel.tooltip")
2196
+ };
2197
+ };
2198
+ var MobileRefereeItem = ({ item, onEditReferee }) => {
2199
+ const { t } = i18n.useTranslation();
2200
+ const typeInfo = getRefereeType(item.bind_type);
2201
+ return /* @__PURE__ */ jsxRuntime.jsxs(MobileCard, { children: [
2202
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("common.address"), children: /* @__PURE__ */ jsxRuntime.jsx(AddressCell, { address: item.address, title: t("common.address") }) }),
2203
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("common.type"), children: /* @__PURE__ */ jsxRuntime.jsx(
2204
+ TooltipCell,
2205
+ {
2206
+ text: typeInfo.text,
2207
+ tooltip: typeInfo.tooltip,
2208
+ title: t("common.type")
2209
+ }
2210
+ ) }),
2211
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("affiliate.boundAt"), align: "end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", children: formatYMDTime(item.code_binding_time) }) }),
2212
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("affiliate.referralCodes"), children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", children: item.bind_code }) }),
2213
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("affiliate.referralCodes.column.you&Referee"), children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "sm", children: [
2214
+ getRebateRateText(item.referral_rebate_rate) + "/",
2215
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "oui-text-base-contrast-54", children: [
2216
+ getRebateRateText(item.referee_rebate_rate),
2217
+ " "
2218
+ ] }),
2219
+ !item.is_default_rate && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "oui-text-primary-light", children: `(${t("affiliate.customized")})` })
2220
+ ] }) }),
2221
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("affiliate.networkSize"), align: "end", children: /* @__PURE__ */ jsxRuntime.jsx(
2222
+ BreakdownCell,
2223
+ {
2224
+ total: item.network_size,
2225
+ direct: item.direct_invites,
2226
+ indirect: item.indirect_invites,
2227
+ title: t("affiliate.networkSize")
2228
+ }
2229
+ ) }),
2230
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("common.volume"), children: /* @__PURE__ */ jsxRuntime.jsx(
2231
+ BreakdownCell,
2232
+ {
2233
+ total: item.volume,
2234
+ direct: item.direct_volume,
2235
+ indirect: item.indirect_volume,
2236
+ prefix: "$",
2237
+ fix: 2,
2238
+ title: t("common.volume")
2239
+ }
2240
+ ) }),
2241
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("affiliate.commission"), children: /* @__PURE__ */ jsxRuntime.jsx(
2242
+ BreakdownCell,
2243
+ {
2244
+ total: item.commission,
2245
+ direct: item.direct_rebate,
2246
+ indirect: item.indirect_rebate,
2247
+ directBonus: item.direct_bonus_rebate,
2248
+ prefix: "$",
2249
+ fix: 6,
2250
+ title: t("affiliate.commission")
2251
+ }
2252
+ ) }),
2253
+ /* @__PURE__ */ jsxRuntime.jsx(
2254
+ MobileCell,
2255
+ {
2256
+ label: t("common.action"),
2257
+ align: "end",
2258
+ className: "oui-col-start-3",
2259
+ children: item.bind_type !== "legacy" && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, children: [
2260
+ /* @__PURE__ */ jsxRuntime.jsx(
2261
+ ui.Text,
2262
+ {
2263
+ className: "oui-cursor-pointer oui-text-primary-light",
2264
+ onClick: () => onEditReferee("edit" /* Edit */, item),
2265
+ children: t("common.edit")
2266
+ }
2267
+ ),
2268
+ !item.is_default_rate && /* @__PURE__ */ jsxRuntime.jsx(
2269
+ ui.Text,
2270
+ {
2271
+ className: "oui-cursor-pointer oui-text-primary-light",
2272
+ onClick: () => onEditReferee("reset" /* Reset */, item),
2273
+ children: t("common.reset")
2274
+ }
2275
+ )
2276
+ ] })
2277
+ }
2278
+ )
2279
+ ] });
2280
+ };
2281
+ var RefereesTableUI = (props) => {
2282
+ const { t } = i18n.useTranslation();
2283
+ const { isMobile } = ui.useScreen();
2284
+ const showPagination = (props.refereesPagination?.count ?? 0) >= 10;
2285
+ const refereeColumns = react.useMemo(() => {
2286
+ return [
2287
+ {
2288
+ title: t("common.address"),
2289
+ dataIndex: "address",
2290
+ render: (value) => /* @__PURE__ */ jsxRuntime.jsx(AddressCell, { address: value, title: t("common.address") })
2291
+ },
2292
+ {
2293
+ title: t("common.type"),
2294
+ dataIndex: "bind_type",
2295
+ render: (_, record) => {
2296
+ const typeInfo = getRefereeType(record.bind_type);
2297
+ return /* @__PURE__ */ jsxRuntime.jsx(
2298
+ TooltipCell,
2299
+ {
2300
+ text: typeInfo.text,
2301
+ tooltip: typeInfo.tooltip,
2302
+ title: t("common.type")
2303
+ }
2304
+ );
2305
+ }
2306
+ },
2307
+ {
2308
+ title: t("affiliate.boundAt"),
2309
+ dataIndex: "code_binding_time",
2310
+ render: (value) => /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: formatYMDTime(value) })
2311
+ },
2312
+ {
2313
+ title: t("affiliate.referralCodes"),
2314
+ dataIndex: "bind_code",
2315
+ render: (value) => /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: value })
2316
+ },
2317
+ {
2318
+ title: t("affiliate.referralCodes.column.you&Referee"),
2319
+ dataIndex: "referee_rebate_rate",
2320
+ render: (_, record) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { children: [
2321
+ getRebateRateText(record.referral_rebate_rate) + "/",
2322
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "oui-text-base-contrast-54", children: [
2323
+ getRebateRateText(record.referee_rebate_rate),
2324
+ " "
2325
+ ] }),
2326
+ !record.is_default_rate && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "oui-text-primary-light", children: `(${t("affiliate.customized")})` })
2327
+ ] }),
2328
+ onSort: true
2329
+ },
2330
+ {
2331
+ title: t("affiliate.networkSize"),
2332
+ dataIndex: "network_size",
2333
+ render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(
2334
+ BreakdownCell,
2335
+ {
2336
+ total: record.network_size,
2337
+ direct: record.direct_invites,
2338
+ indirect: record.indirect_invites,
2339
+ title: t("affiliate.networkSize")
2340
+ }
2341
+ ),
2342
+ onSort: true
2343
+ },
2344
+ {
2345
+ title: t("common.volume"),
2346
+ dataIndex: "volume",
2347
+ render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(
2348
+ BreakdownCell,
2349
+ {
2350
+ total: record.volume,
2351
+ direct: record.direct_volume,
2352
+ indirect: record.indirect_volume,
2353
+ prefix: "$",
2354
+ fix: 2,
2355
+ title: t("common.volume")
2356
+ }
2357
+ ),
2358
+ onSort: true
2359
+ },
2360
+ {
2361
+ title: t("affiliate.commission"),
2362
+ dataIndex: "commission",
2363
+ render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(
2364
+ BreakdownCell,
2365
+ {
2366
+ total: record.commission,
2367
+ direct: record.direct_rebate,
2368
+ indirect: record.indirect_rebate,
2369
+ directBonus: record.direct_bonus_rebate,
2370
+ prefix: "$",
2371
+ fix: 6,
2372
+ title: t("affiliate.commission")
2373
+ }
2374
+ ),
2375
+ onSort: true
2376
+ },
2377
+ {
2378
+ title: t("common.action"),
2379
+ dataIndex: "action",
2380
+ render: (_, record) => record.bind_type !== "legacy" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2381
+ /* @__PURE__ */ jsxRuntime.jsx(
2382
+ ui.Text,
2383
+ {
2384
+ className: "oui-cursor-pointer oui-text-primary-light",
2385
+ onClick: () => props.onEditReferee("edit" /* Edit */, record),
2386
+ children: t("common.edit")
2387
+ }
2388
+ ),
2389
+ !record.is_default_rate && /* @__PURE__ */ jsxRuntime.jsx(
2390
+ ui.Text,
2391
+ {
2392
+ className: "oui-ml-2 oui-cursor-pointer oui-text-primary-light",
2393
+ onClick: () => props.onEditReferee("reset" /* Reset */, record),
2394
+ children: t("common.reset")
2395
+ }
2396
+ )
2397
+ ] }) : null
2398
+ }
2399
+ ];
2400
+ }, [t, props.onEditReferee]);
2401
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: isMobile ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-flex oui-flex-col oui-px-4", children: /* @__PURE__ */ jsxRuntime.jsx(
2402
+ ui.ListView,
2403
+ {
2404
+ dataSource: props.refereesData,
2405
+ contentClassName: "!oui-space-y-0 oui-pb-3",
2406
+ renderItem: (item, index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2407
+ /* @__PURE__ */ jsxRuntime.jsx(
2408
+ MobileRefereeItem,
2409
+ {
2410
+ item,
2411
+ onEditReferee: props.onEditReferee
2412
+ }
2413
+ ),
2414
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { intensity: 8 })
2415
+ ] }, index)
2416
+ }
2417
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: `oui-px-3 ${showPagination ? "" : "oui-pb-3"}`, children: /* @__PURE__ */ jsxRuntime.jsx(
2418
+ uiConnector.AuthGuardDataTable,
2419
+ {
2420
+ bordered: true,
2421
+ columns: refereeColumns,
2422
+ dataSource: props.refereesData,
2423
+ loading: props.isRefereesLoading,
2424
+ pagination: showPagination ? props.refereesPagination : void 0,
2425
+ onSort: props.onRefereesSort,
2426
+ onRow: () => ({ className: "oui-h-12" }),
2427
+ className: "[&_.oui-h-10.oui-w-full]:!oui-mx-0 [&_.oui-table-pagination]:!oui-justify-end [&_th]:!oui-tracking-[0.03em] [&_th]:!oui-px-3 [&_td]:!oui-px-3"
2428
+ }
2429
+ ) }) });
2430
+ };
2431
+ var RefereesTableWidget = (props) => {
2432
+ const state = useRefereesTableScript(props);
2433
+ return /* @__PURE__ */ jsxRuntime.jsx(RefereesTableUI, { ...state });
2434
+ };
2435
+ var useMultiLevelReferralCodes = () => {
2436
+ const { referralInfo } = useReferralContext();
2437
+ const { data: multiLevelRebateInfo } = useMultiLevelRebateInfo();
2438
+ const [refereesData] = hooks.useRefereeInfo({});
2439
+ const copyCode = (code) => {
2440
+ copyText(code);
2441
+ };
2442
+ const singleLevelTotals = react.useMemo(() => {
2443
+ const totalsMap = /* @__PURE__ */ new Map();
2444
+ if (refereesData) {
2445
+ refereesData.forEach((referee) => {
2446
+ const code = referee?.referral_code;
2447
+ if (!code) return;
2448
+ const existing = totalsMap.get(code) || { volume: 0, commission: 0 };
2449
+ totalsMap.set(code, {
2450
+ volume: existing.volume + (referee?.volume || 0),
2451
+ commission: existing.commission + (referee?.referral_rebate || 0)
2452
+ });
2453
+ });
2454
+ }
2455
+ return totalsMap;
2456
+ }, [refereesData]);
2457
+ const codes = react.useMemo(() => {
2458
+ const allCodes = [];
2459
+ const multiLevelReferralCode = multiLevelRebateInfo?.referral_code;
2460
+ if (multiLevelRebateInfo?.referral_code) {
2461
+ const maxRebateRate = multiLevelRebateInfo.max_rebate_rate ?? 0;
2462
+ const defaultRefereeRebateRate = multiLevelRebateInfo.default_referee_rebate_rate ?? 0;
2463
+ const referrerRebateRate = Math.max(
2464
+ 0,
2465
+ maxRebateRate - defaultRefereeRebateRate
2466
+ );
2467
+ const directInvites = multiLevelRebateInfo?.direct_invites ?? 0;
2468
+ const indirectInvites = multiLevelRebateInfo?.indirect_invites ?? 0;
2469
+ const directVolume = multiLevelRebateInfo?.direct_volume ?? 0;
2470
+ const indirectVolume = multiLevelRebateInfo?.indirect_volume ?? 0;
2471
+ const directRebate = multiLevelRebateInfo?.direct_rebate ?? 0;
2472
+ const indirectRebate = multiLevelRebateInfo?.indirect_rebate ?? 0;
2473
+ const directBonusRebate = multiLevelRebateInfo?.direct_bonus_rebate ?? 0;
2474
+ const multiLevelCode = {
2475
+ code: multiLevelRebateInfo.referral_code ?? "",
2476
+ direct_invites: directInvites,
2477
+ indirect_invites: indirectInvites,
2478
+ direct_volume: directVolume,
2479
+ indirect_volume: indirectVolume,
2480
+ direct_rebate: directRebate,
2481
+ indirect_rebate: indirectRebate,
2482
+ direct_bonus_rebate: directBonusRebate,
2483
+ max_rebate_rate: maxRebateRate,
2484
+ referee_rebate_rate: defaultRefereeRebateRate,
2485
+ referrer_rebate_rate: referrerRebateRate,
2486
+ total_invites: directInvites + indirectInvites,
2487
+ total_volume: directVolume + indirectVolume,
2488
+ total_rebate: directRebate + indirectRebate + directBonusRebate,
2489
+ referral_type: "multi"
2490
+ };
2491
+ allCodes.push(multiLevelCode);
2492
+ }
2493
+ if (referralInfo?.referrer_info?.referral_codes) {
2494
+ allCodes.push(
2495
+ ...referralInfo.referrer_info.referral_codes.filter(
2496
+ (item) => multiLevelReferralCode ? item.code !== multiLevelReferralCode : true
2497
+ ).map((item) => {
2498
+ const totals = singleLevelTotals.get(item.code);
2499
+ const totalVolume = totals?.volume ?? item.total_volume ?? 0;
2500
+ const totalRebate = totals?.commission ?? item.total_rebate ?? 0;
2501
+ const totalInvites = item.total_invites ?? 0;
2502
+ const row = {
2503
+ code: item.code,
2504
+ referral_type: "single",
2505
+ direct_invites: totalInvites,
2506
+ indirect_invites: 0,
2507
+ direct_volume: totalVolume,
2508
+ indirect_volume: 0,
2509
+ direct_rebate: totalRebate,
2510
+ indirect_rebate: 0,
2511
+ max_rebate_rate: item.max_rebate_rate ?? 0,
2512
+ referee_rebate_rate: item.referee_rebate_rate ?? 0,
2513
+ referrer_rebate_rate: item.referrer_rebate_rate ?? 0,
2514
+ total_invites: totalInvites,
2515
+ total_volume: totalVolume,
2516
+ total_rebate: totalRebate
2517
+ };
2518
+ return row;
2519
+ })
2520
+ );
2521
+ }
2522
+ if (allCodes.length === 0) return void 0;
2523
+ return allCodes;
2524
+ }, [
2525
+ referralInfo?.referrer_info?.referral_codes,
2526
+ multiLevelRebateInfo,
2527
+ singleLevelTotals
2528
+ ]);
2529
+ return {
2530
+ codes,
2531
+ copyCode
2532
+ };
2533
+ };
2534
+
2535
+ // src/pages/multiLevel/affiliate/referrerTable/referralCodesTable/referralCodesTable.script.ts
2536
+ var useReferralCodesTableScript = (props = {}) => {
2537
+ const { enabled = true } = props;
2538
+ const { codes, copyCode } = useMultiLevelReferralCodes();
2539
+ const [sort, setSort] = react.useState(null);
2540
+ const sortedCodes = react.useMemo(() => {
2541
+ if (!enabled) return void 0;
2542
+ if (!codes || !sort) return codes;
2543
+ const sortableCodes = codes.map((code, index) => ({
2544
+ code,
2545
+ index
2546
+ }));
2547
+ sortableCodes.sort((a, b) => {
2548
+ const valA = Number(a.code[sort.key] ?? 0);
2549
+ const valB = Number(b.code[sort.key] ?? 0);
2550
+ if (valA < valB) return sort.order === "asc" ? -1 : 1;
2551
+ if (valA > valB) return sort.order === "asc" ? 1 : -1;
2552
+ return a.index - b.index;
2553
+ });
2554
+ return sortableCodes.map((item) => item.code);
2555
+ }, [codes, enabled, sort]);
2556
+ const onSort = (sort2) => {
2557
+ if (!sort2) {
2558
+ setSort(null);
2559
+ return;
2560
+ }
2561
+ const sortKey = sort2.sortKey;
2562
+ if (sortKey && (sortKey === "total_invites" || sortKey === "total_volume" || sortKey === "total_rebate")) {
2563
+ setSort({
2564
+ key: sortKey,
2565
+ order: sort2.sort === "asc" ? "asc" : "desc"
2566
+ });
2567
+ }
2568
+ };
2569
+ return {
2570
+ codes,
2571
+ sortedCodes,
2572
+ copyCode,
2573
+ onSort,
2574
+ isLoading: enabled && !codes
2575
+ };
2576
+ };
2577
+ var getReferralCodeType = (referralType) => {
2578
+ const { t } = i18n.useTranslation();
2579
+ if (referralType === "multi") {
2580
+ return {
2581
+ text: t("affiliate.multiLevel"),
2582
+ tooltip: t("affiliate.multiLevel.tooltip")
2583
+ };
2584
+ }
2585
+ return {
2586
+ text: t("affiliate.singleLevelLegacy"),
2587
+ tooltip: t("affiliate.singleLevelLegacy.tooltip")
2588
+ };
2589
+ };
2590
+ var MobileReferralCodeItem = ({ item, copyCode }) => {
2591
+ const { t } = i18n.useTranslation();
2592
+ const referrerRate = new utils.Decimal(item.referrer_rebate_rate ?? 0).mul(100).toFixed(0);
2593
+ const refereeRate = new utils.Decimal(item.referee_rebate_rate ?? 0).mul(100).toFixed(0);
2594
+ const typeInfo = getReferralCodeType(item.referral_type);
2595
+ return /* @__PURE__ */ jsxRuntime.jsxs(MobileCard, { children: [
2596
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("affiliate.referralCode"), children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: item.code || "" }) }),
2597
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("common.type"), children: /* @__PURE__ */ jsxRuntime.jsx(
2598
+ TooltipCell,
2599
+ {
2600
+ text: typeInfo.text,
2601
+ tooltip: typeInfo.tooltip,
2602
+ title: t("common.type")
2603
+ }
2604
+ ) }),
2605
+ /* @__PURE__ */ jsxRuntime.jsx(
2606
+ MobileCell,
2607
+ {
2608
+ label: t("affiliate.referralCodes.column.you&Referee"),
2609
+ align: "end",
2610
+ children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { children: [
2611
+ referrerRate,
2612
+ "%/",
2613
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "oui-text-base-contrast-54", children: [
2614
+ refereeRate,
2615
+ "%"
2616
+ ] })
2617
+ ] })
2618
+ }
2619
+ ),
2620
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("affiliate.networkSize"), children: /* @__PURE__ */ jsxRuntime.jsx(
2621
+ BreakdownCell,
2622
+ {
2623
+ total: item.total_invites ?? 0,
2624
+ direct: item.direct_invites ?? 0,
2625
+ indirect: item.indirect_invites ?? 0,
2626
+ title: t("affiliate.networkSize")
2627
+ }
2628
+ ) }),
2629
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("common.volume"), children: /* @__PURE__ */ jsxRuntime.jsx(
2630
+ BreakdownCell,
2631
+ {
2632
+ total: item.total_volume ?? 0,
2633
+ direct: item.direct_volume ?? 0,
2634
+ indirect: item.indirect_volume ?? 0,
2635
+ prefix: "$",
2636
+ fix: 2,
2637
+ title: t("common.volume")
2638
+ }
2639
+ ) }),
2640
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("affiliate.commission"), align: "end", children: /* @__PURE__ */ jsxRuntime.jsx(
2641
+ BreakdownCell,
2642
+ {
2643
+ total: item.total_rebate ?? 0,
2644
+ direct: item.direct_rebate ?? 0,
2645
+ indirect: item.indirect_rebate ?? 0,
2646
+ directBonus: item.direct_bonus_rebate,
2647
+ prefix: "$",
2648
+ fix: 6,
2649
+ title: t("affiliate.commission")
2650
+ }
2651
+ ) }),
2652
+ /* @__PURE__ */ jsxRuntime.jsx(MobileCell, { label: t("common.action"), children: /* @__PURE__ */ jsxRuntime.jsx(
2653
+ ui.Text,
2654
+ {
2655
+ className: "oui-cursor-pointer oui-text-primary-light",
2656
+ onClick: (e) => {
2657
+ e.stopPropagation();
2658
+ copyCode(item.code);
2659
+ },
2660
+ children: t("common.copy")
2661
+ }
2662
+ ) })
2663
+ ] });
2664
+ };
2665
+ var ReferralCodesTableUI = (props) => {
2666
+ const { t } = i18n.useTranslation();
2667
+ const { isMobile } = ui.useScreen();
2668
+ const columns = react.useMemo(() => {
2669
+ return [
2670
+ {
2671
+ title: t("affiliate.referralCode"),
2672
+ dataIndex: "code",
2673
+ render: (value) => /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: value || "" })
2674
+ },
2675
+ {
2676
+ title: t("common.type"),
2677
+ dataIndex: "referral_type",
2678
+ render: (_, record) => {
2679
+ const typeInfo = getReferralCodeType(record.referral_type);
2680
+ return /* @__PURE__ */ jsxRuntime.jsx(
2681
+ TooltipCell,
2682
+ {
2683
+ text: typeInfo.text,
2684
+ tooltip: typeInfo.tooltip,
2685
+ title: t("common.type")
2686
+ }
2687
+ );
2688
+ }
2689
+ },
2690
+ {
2691
+ title: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { children: [
2692
+ t("affiliate.referralCodes.column.defaultSplit"),
2693
+ /* @__PURE__ */ jsxRuntime.jsx("br", {}),
2694
+ "(",
2695
+ t("affiliate.referralCodes.column.you&Referee"),
2696
+ ")"
2697
+ ] }),
2698
+ dataIndex: "rate",
2699
+ render: (_, record) => {
2700
+ const referrerRate = new utils.Decimal(record.referrer_rebate_rate ?? 0).mul(100).toFixed(0);
2701
+ const refereeRate = new utils.Decimal(record.referee_rebate_rate ?? 0).mul(100).toFixed(0);
2702
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { children: [
2703
+ referrerRate,
2704
+ "%",
2705
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "oui-text-base-contrast-54", children: [
2706
+ "/",
2707
+ refereeRate,
2708
+ "%"
2709
+ ] })
2710
+ ] });
2711
+ }
2712
+ },
2713
+ {
2714
+ title: t("affiliate.networkSize"),
2715
+ dataIndex: "total_invites",
2716
+ render: (_, record) => {
2717
+ return /* @__PURE__ */ jsxRuntime.jsx(
2718
+ BreakdownCell,
2719
+ {
2720
+ total: record.total_invites ?? 0,
2721
+ direct: record.direct_invites ?? 0,
2722
+ indirect: record.indirect_invites ?? 0,
2723
+ title: t("affiliate.networkSize")
2724
+ }
2725
+ );
2726
+ },
2727
+ onSort: true
2728
+ },
2729
+ {
2730
+ title: t("common.volume"),
2731
+ dataIndex: "total_volume",
2732
+ render: (_, record) => {
2733
+ return /* @__PURE__ */ jsxRuntime.jsx(
2734
+ BreakdownCell,
2735
+ {
2736
+ total: record.total_volume ?? 0,
2737
+ direct: record.direct_volume ?? 0,
2738
+ indirect: record.indirect_volume ?? 0,
2739
+ prefix: "$",
2740
+ fix: 2,
2741
+ title: t("common.volume")
2742
+ }
2743
+ );
2744
+ },
2745
+ onSort: true
2746
+ },
2747
+ {
2748
+ title: t("affiliate.commission"),
2749
+ dataIndex: "total_rebate",
2750
+ render: (_, record) => {
2751
+ return /* @__PURE__ */ jsxRuntime.jsx(
2752
+ BreakdownCell,
2753
+ {
2754
+ total: record.total_rebate ?? 0,
2755
+ direct: record.direct_rebate ?? 0,
2756
+ indirect: record.indirect_rebate ?? 0,
2757
+ directBonus: record.direct_bonus_rebate,
2758
+ prefix: "$",
2759
+ fix: 6,
2760
+ title: t("affiliate.commission")
2761
+ }
2762
+ );
2763
+ },
2764
+ onSort: true
2765
+ },
2766
+ {
2767
+ title: t("common.action"),
2768
+ dataIndex: "action",
2769
+ render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(
2770
+ ui.Text,
2771
+ {
2772
+ className: "oui-cursor-pointer oui-text-primary-light",
2773
+ onClick: (e) => {
2774
+ e.stopPropagation();
2775
+ props.copyCode(record.code);
2776
+ },
2777
+ children: t("common.copy")
2778
+ }
2779
+ )
2780
+ }
2781
+ ];
2782
+ }, [t, props.copyCode]);
2783
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: isMobile ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-flex oui-flex-col oui-px-4", children: /* @__PURE__ */ jsxRuntime.jsx(
2784
+ ui.ListView,
2785
+ {
2786
+ dataSource: props.sortedCodes,
2787
+ contentClassName: "!oui-space-y-0 oui-pb-3",
2788
+ renderItem: (item, index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2789
+ /* @__PURE__ */ jsxRuntime.jsx(MobileReferralCodeItem, { item, copyCode: props.copyCode }),
2790
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { intensity: 8 })
2791
+ ] }, index)
2792
+ }
2793
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-px-3", children: /* @__PURE__ */ jsxRuntime.jsx(
2794
+ uiConnector.AuthGuardDataTable,
2795
+ {
2796
+ bordered: true,
2797
+ columns,
2798
+ dataSource: props.sortedCodes,
2799
+ loading: props.isLoading,
2800
+ onSort: props.onSort,
2801
+ onRow: () => ({ className: "oui-h-12" }),
2802
+ className: "oui-pb-3 [&_.oui-h-10.oui-w-full]:!oui-mx-0 [&_.oui-table-pagination]:!oui-justify-end [&_th]:!oui-tracking-[0.03em] [&_th]:!oui-px-3 [&_td]:!oui-px-3"
2803
+ }
2804
+ ) }) });
2805
+ };
2806
+ var ReferralCodesTableWidget = (props) => {
2807
+ const state = useReferralCodesTableScript(props);
2808
+ return /* @__PURE__ */ jsxRuntime.jsx(ReferralCodesTableUI, { ...state });
2809
+ };
2810
+ var ReferrerTableUI = (props) => {
2811
+ const { t } = i18n.useTranslation();
2812
+ return /* @__PURE__ */ jsxRuntime.jsx(
2813
+ ui.Flex,
2814
+ {
2815
+ direction: "column",
2816
+ className: "oui-rounded-2xl oui-bg-base-9 [&_td]:oui-font-medium [&_td]:oui-tracking-[0.03em] [&_th]:oui-font-semibold",
2817
+ px: 3,
2818
+ pt: 4,
2819
+ gap: 4,
2820
+ width: "100%",
2821
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
2822
+ ui.Tabs,
2823
+ {
2824
+ value: props.activeTab,
2825
+ onValueChange: (value) => props.setActiveTab(value),
2826
+ className: "oui-w-full oui-text-base",
2827
+ variant: "text",
2828
+ classNames: {
2829
+ tabsListContainer: "oui-px-3",
2830
+ trigger: "oui-pb-[9px] oui-tracking-[0.01em]",
2831
+ scrollIndicator: "[&_.oui-scroll-indicator-leading]:oui-hidden [&_.oui-scroll-indicator-tailing]:oui-hidden"
2832
+ },
2833
+ showScrollIndicator: true,
2834
+ children: [
2835
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TabPanel, { value: "commission", title: t("affiliate.commission"), children: /* @__PURE__ */ jsxRuntime.jsx(CommissionTableWidget, { enabled: props.activeTab === "commission" }) }),
2836
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TabPanel, { value: "referees", title: t("affiliate.referees"), children: /* @__PURE__ */ jsxRuntime.jsx(RefereesTableWidget, { enabled: props.activeTab === "referees" }) }),
2837
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TabPanel, { value: "codes", title: t("affiliate.referralCodes"), children: /* @__PURE__ */ jsxRuntime.jsx(ReferralCodesTableWidget, { enabled: props.activeTab === "codes" }) })
2838
+ ]
2839
+ }
2840
+ )
2841
+ }
2842
+ );
2843
+ };
2844
+ var ReferrerTableWidget = () => {
2845
+ const state = useReferrerTableScript();
2846
+ return /* @__PURE__ */ jsxRuntime.jsx(ReferrerTableUI, { ...state });
2847
+ };
2848
+ var Summary = (props) => {
2849
+ const { statistics } = props;
2850
+ const { t } = i18n.useTranslation();
2851
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2852
+ ui.Flex,
2853
+ {
2854
+ id: "oui-affiliate-affiliate-summary",
2855
+ r: "2xl",
2856
+ p: 5,
2857
+ width: "100%",
2858
+ height: "100%",
2859
+ gap: 6,
2860
+ direction: "column",
2861
+ intensity: 900,
2862
+ className: "oui-border oui-border-line-6",
2863
+ children: [
2864
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "row", justify: "between", width: "100%", children: [
2865
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "oui-text-lg", children: t("affiliate.summary") }),
2866
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-min-w-14", children: /* @__PURE__ */ jsxRuntime.jsx(
2867
+ ui.Select.options,
2868
+ {
2869
+ size: "xs",
2870
+ value: props.period,
2871
+ onValueChange: props.onPeriodChange,
2872
+ options: props.periodTypes
2873
+ }
2874
+ ) })
2875
+ ] }),
2876
+ /* @__PURE__ */ jsxRuntime.jsx(
2877
+ SummaryItem,
2878
+ {
2879
+ prefix: "$",
2880
+ rule: "human",
2881
+ label: `${t("affiliate.commission")} (USDC)`,
2882
+ value: statistics.total_rebate,
2883
+ direct: statistics.direct_rebate + statistics.direct_bonus_rebate,
2884
+ indirect: statistics.indirect_rebate,
2885
+ classNames: {
2886
+ root: "!oui-py-12",
2887
+ value: "oui-text-trade-profit",
2888
+ direct: "oui-text-trade-profit",
2889
+ indirect: "oui-text-trade-profit"
2890
+ }
2891
+ }
2892
+ ),
2893
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "100%", gap: 6, className: "oui-flex-col md:oui-flex-row", children: [
2894
+ /* @__PURE__ */ jsxRuntime.jsx(
2895
+ SummaryItem,
2896
+ {
2897
+ prefix: "$",
2898
+ rule: "human",
2899
+ label: `${t("affiliate.referralVol")} (USDC)`,
2900
+ value: statistics.total_volume,
2901
+ direct: statistics.direct_volume,
2902
+ indirect: statistics.indirect_volume,
2903
+ classNames: {
2904
+ root: "oui-w-full md:oui-w-1/2"
2905
+ }
2906
+ }
2907
+ ),
2908
+ /* @__PURE__ */ jsxRuntime.jsx(
2909
+ SummaryItem,
2910
+ {
2911
+ dp: 0,
2912
+ label: t("affiliate.referrals"),
2913
+ value: statistics.total_invites,
2914
+ direct: statistics.direct_invites,
2915
+ indirect: statistics.indirect_invites,
2916
+ classNames: {
2917
+ root: "oui-w-full md:oui-w-1/2"
2918
+ }
2919
+ }
2920
+ )
2921
+ ] })
2922
+ ]
2923
+ }
2924
+ );
2925
+ };
2926
+ var SummaryItem = (props) => {
2927
+ const { t } = i18n.useTranslation();
2928
+ const { rule, dp = 2 } = props;
2929
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2930
+ ui.Flex,
2931
+ {
2932
+ r: "2xl",
2933
+ width: "100%",
2934
+ direction: "column",
2935
+ itemAlign: "start",
2936
+ gap: 2,
2937
+ className: ui.cn(
2938
+ "oui-bg-base-contrast-4 oui-p-5 md:oui-py-[38px]",
2939
+ "oui-text-sm oui-text-base-contrast-54",
2940
+ props.classNames?.root
2941
+ ),
2942
+ children: [
2943
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: props.label }),
2944
+ /* @__PURE__ */ jsxRuntime.jsx(
2945
+ ui.Text.numeral,
2946
+ {
2947
+ rule,
2948
+ dp: props.dp,
2949
+ size: "3xl",
2950
+ prefix: props.prefix,
2951
+ placeholder: "--",
2952
+ intensity: 98,
2953
+ className: props.classNames?.value,
2954
+ children: props.value
2955
+ }
2956
+ ),
2957
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { className: "oui-flex-wrap oui-text-base-contrast-54", children: [
2958
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 1, children: [
2959
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { children: [
2960
+ t("affiliate.direct"),
2961
+ ":"
2962
+ ] }),
2963
+ /* @__PURE__ */ jsxRuntime.jsx(
2964
+ ui.Text.numeral,
2965
+ {
2966
+ rule,
2967
+ dp: props.dp,
2968
+ prefix: props.prefix,
2969
+ intensity: 54,
2970
+ className: props.classNames?.direct,
2971
+ children: props.direct
2972
+ }
2973
+ )
2974
+ ] }),
2975
+ "/",
2976
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 1, children: [
2977
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { children: [
2978
+ t("affiliate.indirect"),
2979
+ ":"
2980
+ ] }),
2981
+ /* @__PURE__ */ jsxRuntime.jsx(
2982
+ ui.Text.numeral,
2983
+ {
2984
+ rule,
2985
+ dp: props.dp,
2986
+ prefix: props.prefix,
2987
+ intensity: 54,
2988
+ className: props.classNames?.indirect,
2989
+ children: props.indirect
2990
+ }
2991
+ )
2992
+ ] })
2993
+ ] })
2994
+ ]
2995
+ }
2996
+ );
2997
+ };
2998
+ var useSummaryScript = () => {
2999
+ const { t } = i18n.useTranslation();
3000
+ const [period, setPeriod] = react.useState("all_time" /* All */);
3001
+ const { data } = useMultiLevelStatistics(period);
3002
+ const periodTypes = [
3003
+ { label: t("common.all"), value: "all_time" /* All */ },
3004
+ { label: t("common.select.1d"), value: "1d" /* 1d */ },
3005
+ { label: t("common.select.7d"), value: "7d" /* 7d */ },
3006
+ { label: t("common.select.30d"), value: "30d" /* 30d */ }
3007
+ ];
3008
+ const onPeriodChange = (item) => {
3009
+ setPeriod(item);
3010
+ };
3011
+ const statistics = react.useMemo(() => {
3012
+ const {
3013
+ direct_invites = 0,
3014
+ indirect_invites = 0,
3015
+ direct_traded = 0,
3016
+ indirect_traded = 0,
3017
+ direct_volume = 0,
3018
+ indirect_volume = 0,
3019
+ direct_rebate = 0,
3020
+ indirect_rebate = 0,
3021
+ direct_bonus_rebate = 0
3022
+ } = data || {};
217
3023
  return {
218
- generateCode,
219
- showHome,
220
- referralInfo: data,
221
- isAffiliate,
222
- isTrader,
223
- tab,
224
- becomeAnAffiliateUrl,
225
- learnAffiliateUrl,
226
- referralLinkUrl,
227
- userVolume,
228
- dailyVolume,
229
- chartConfig,
230
- overwrite,
231
- isLoading,
232
- wrongNetwork,
233
- disabledConnect,
234
- setShowHome,
235
- setTab,
236
- mutate: memoMutate,
237
- onBecomeAnAffiliate,
238
- bindReferralCodeState,
239
- onLearnAffiliate,
240
- showReferralPage,
241
- splashPage
3024
+ direct_invites,
3025
+ indirect_invites,
3026
+ total_invites: direct_invites + indirect_invites,
3027
+ direct_traded,
3028
+ indirect_traded,
3029
+ total_traded: direct_traded + indirect_traded,
3030
+ direct_volume,
3031
+ indirect_volume,
3032
+ total_volume: direct_volume + indirect_volume,
3033
+ direct_rebate,
3034
+ indirect_rebate,
3035
+ direct_bonus_rebate,
3036
+ total_rebate: direct_rebate + indirect_rebate + direct_bonus_rebate
242
3037
  };
243
- }, [
244
- becomeAnAffiliateUrl,
245
- chartConfig,
246
- dailyVolume,
247
- data,
248
- disabledConnect,
249
- generateCode,
250
- isAffiliate,
251
- isLoading,
252
- isTrader,
253
- learnAffiliateUrl,
254
- overwrite,
255
- referralLinkUrl,
256
- showHome,
257
- tab,
258
- userVolume,
259
- wrongNetwork,
260
- onBecomeAnAffiliate,
261
- bindReferralCodeState,
262
- onLearnAffiliate,
263
- showReferralPage,
264
- splashPage,
265
- memoMutate
266
- ]);
267
- return /* @__PURE__ */ jsxRuntime.jsx(ReferralContext.Provider, { value: memoizedValue, children });
3038
+ }, [data]);
3039
+ return {
3040
+ period,
3041
+ periodTypes,
3042
+ onPeriodChange,
3043
+ statistics
3044
+ };
3045
+ };
3046
+ var SummaryWidget = () => {
3047
+ const state = useSummaryScript();
3048
+ return /* @__PURE__ */ jsxRuntime.jsx(Summary, { ...state });
3049
+ };
3050
+ var MultiLevelAffiliatePage = () => {
3051
+ const { t } = i18n.useTranslation();
3052
+ const { multiLevelRebateInfo } = useReferralContext();
3053
+ return /* @__PURE__ */ jsxRuntime.jsx(
3054
+ ui.Flex,
3055
+ {
3056
+ id: "oui-affiliate-affiliate-page",
3057
+ className: ui.cn("oui-h-lvw", "oui-font-semibold", "oui-pb-24 oui-pt-16"),
3058
+ direction: "column",
3059
+ gap: 4,
3060
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-w-full oui-px-5 md:oui-mx-auto md:oui-max-w-[1040px]", children: /* @__PURE__ */ jsxRuntime.jsxs(
3061
+ ui.Flex,
3062
+ {
3063
+ width: "100%",
3064
+ direction: "column",
3065
+ className: "oui-gap-8 md:oui-gap-10",
3066
+ children: [
3067
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "100%", direction: "column", itemAlign: "start", gap: 4, children: [
3068
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "oui-text-[32px] oui-leading-[40px] md:oui-text-6xl md:oui-leading-[72px]", children: t("affiliate.earnReferralCommissions") }),
3069
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", intensity: 54, children: t("affiliate.earnReferralCommissions.description") })
3070
+ ] }),
3071
+ /* @__PURE__ */ jsxRuntime.jsxs(
3072
+ ui.Grid,
3073
+ {
3074
+ width: "100%",
3075
+ height: "100%",
3076
+ gap: 6,
3077
+ cols: 1,
3078
+ rows: 1,
3079
+ className: "md:oui-grid-cols-2",
3080
+ children: [
3081
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-order-2 md:oui-order-1", children: /* @__PURE__ */ jsxRuntime.jsx(SummaryWidget, {}) }),
3082
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-order-1 md:oui-order-2", children: multiLevelRebateInfo?.referral_code ? /* @__PURE__ */ jsxRuntime.jsx(ReferralInfoWidget, {}) : /* @__PURE__ */ jsxRuntime.jsx(MultiLevelReferralWidget, {}) })
3083
+ ]
3084
+ }
3085
+ ),
3086
+ /* @__PURE__ */ jsxRuntime.jsx(CommissionChartWidget, {}),
3087
+ /* @__PURE__ */ jsxRuntime.jsx(ReferrerTableWidget, {})
3088
+ ]
3089
+ }
3090
+ ) })
3091
+ }
3092
+ );
3093
+ };
3094
+ var AffiliateIcon = (props) => {
3095
+ const { size = 16, className, ...rest } = props;
3096
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3097
+ "svg",
3098
+ {
3099
+ width: size,
3100
+ height: size,
3101
+ viewBox: "0 0 16 16",
3102
+ fill: "#fff",
3103
+ fillOpacity: ".98",
3104
+ xmlns: "http://www.w3.org/2000/svg",
3105
+ className: props.className,
3106
+ ...rest,
3107
+ children: [
3108
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8 1.302c-3.683 0-6.655 2.985-6.667 6.667-.013 3.676 2.987 6.68 6.666 6.687s6.674-3.037 6.667-6.687c-.007-3.682-2.985-6.667-6.667-6.667m0 1.333a5.333 5.333 0 0 1 5.333 5.334c0 1.5-.625 2.852-1.622 3.821-.49-1.062-1.545-1.821-2.753-1.821H7.04c-1.207 0-2.259.75-2.75 1.812A5.3 5.3 0 0 1 2.666 7.97a5.333 5.333 0 0 1 5.333-5.334M8 3.97a2.667 2.667 0 1 0 0 5.333A2.667 2.667 0 0 0 8 3.97" }),
3109
+ /* @__PURE__ */ jsxRuntime.jsx(
3110
+ "path",
3111
+ {
3112
+ d: "M16 12.667a3.333 3.333 0 1 1-6.667 0 3.333 3.333 0 0 1 6.667 0",
3113
+ fill: "#1828C3"
3114
+ }
3115
+ ),
3116
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M11.917 11.433a.917.917 0 0 0-.917.917c0 .53.302 1.031.802 1.49a4.6 4.6 0 0 0 .713.53l.068.043c.05.027.117.027.167 0l.068-.042q.08-.05.177-.115c.182-.123.366-.26.536-.416.5-.459.802-.96.802-1.49a.917.917 0 0 0-.917-.917.97.97 0 0 0-.744.386.95.95 0 0 0-.756-.386" })
3117
+ ]
3118
+ }
3119
+ );
3120
+ };
3121
+ var TraderIcon = (props) => {
3122
+ const { size = 16, className, ...rest } = props;
3123
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3124
+ "svg",
3125
+ {
3126
+ width: size,
3127
+ height: size,
3128
+ viewBox: "0 0 16 16",
3129
+ fill: "white",
3130
+ fillOpacity: "0.36",
3131
+ xmlns: "http://www.w3.org/2000/svg",
3132
+ className: props.className,
3133
+ ...rest,
3134
+ children: [
3135
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M7.99929 1.30212C4.31735 1.30212 1.34509 4.28679 1.33262 7.96878C1.32015 11.6454 4.32042 14.6488 7.99929 14.6561C11.6782 14.6634 14.6726 11.6194 14.666 7.96878C14.6593 4.28679 11.6812 1.30212 7.99929 1.30212ZM7.99929 2.63546C10.9448 2.63546 13.3326 5.02345 13.3326 7.96878C13.3326 9.46878 12.7078 10.8208 11.7112 11.7901C11.2202 10.7281 10.1656 9.96878 8.95762 9.96878C8.71802 9.96878 7.28042 9.96878 7.04095 9.96878C5.83369 9.96878 4.78215 10.7188 4.29095 11.7814C3.29429 10.8121 2.66595 9.46878 2.66595 7.96878C2.66595 5.02345 5.05375 2.63546 7.99929 2.63546ZM7.99929 3.96879C6.52649 3.96879 5.33255 5.16279 5.33262 6.63545C5.33262 8.10812 6.52649 9.30212 7.99929 9.30212C9.47202 9.30212 10.666 8.10812 10.666 6.63545C10.666 5.16279 9.47202 3.96879 7.99929 3.96879Z" }),
3136
+ /* @__PURE__ */ jsxRuntime.jsx(
3137
+ "path",
3138
+ {
3139
+ d: "M16 12.6667C16 14.5076 14.5076 16 12.6666 16C10.8257 16 9.33331 14.5076 9.33331 12.6667C9.33331 10.8257 10.8257 9.33333 12.6666 9.33333C14.5076 9.33333 16 10.8257 16 12.6667Z",
3140
+ fill: "#005A4F"
3141
+ }
3142
+ ),
3143
+ /* @__PURE__ */ jsxRuntime.jsx(
3144
+ "path",
3145
+ {
3146
+ d: "M14.3325 13.3345C14.3325 13.2918 14.3182 13.2473 14.2857 13.2147L13.6658 12.6002L13.4315 12.8345L13.7595 13.1678H11.3325C11.2405 13.1678 11.1658 13.2425 11.1658 13.3345C11.1658 13.4265 11.2405 13.5012 11.3325 13.5012H13.7595L13.4315 13.8345L13.6658 14.0688L14.2857 13.4543C14.3182 13.4217 14.3325 13.3772 14.3325 13.3345ZM14.1658 12.0012C14.1658 11.9092 14.0912 11.8345 13.9992 11.8345H11.572L11.9002 11.5012L11.6658 11.2668L11.046 11.8813C10.981 11.9465 10.981 12.0558 11.046 12.121L11.6658 12.7355L11.9002 12.5012L11.572 12.1678H13.9992C14.0912 12.1678 14.1658 12.0932 14.1658 12.0012Z",
3147
+ fill: "white",
3148
+ fillOpacity: "0.98"
3149
+ }
3150
+ )
3151
+ ]
3152
+ }
3153
+ );
268
3154
  };
269
3155
  var USDCIcon = (props) => {
270
3156
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -307,7 +3193,7 @@ var USDCIcon = (props) => {
307
3193
  }
308
3194
  );
309
3195
  };
310
- var Summary = (props) => {
3196
+ var Summary2 = (props) => {
311
3197
  const { t } = i18n.useTranslation();
312
3198
  return /* @__PURE__ */ jsxRuntime.jsxs(
313
3199
  ui.Flex,
@@ -417,7 +3303,7 @@ var Row = (props) => {
417
3303
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "oui-text-xs md:oui-text-sm xl:oui-text-base", children: utils.commifyOptional(props.value, { fix: props.dp, fallback: "0" }) })
418
3304
  ] });
419
3305
  };
420
- var useSummaryScript = () => {
3306
+ var useSummaryScript2 = () => {
421
3307
  const { t } = i18n.useTranslation();
422
3308
  const [period, setPeriod] = react.useState("All");
423
3309
  const periodTypes = [
@@ -500,9 +3386,9 @@ var useSummaryScript = () => {
500
3386
  refereesTades
501
3387
  };
502
3388
  };
503
- var SummaryWidget = () => {
504
- const state = useSummaryScript();
505
- return /* @__PURE__ */ jsxRuntime.jsx(Summary, { ...state });
3389
+ var SummaryWidget2 = () => {
3390
+ const state = useSummaryScript2();
3391
+ return /* @__PURE__ */ jsxRuntime.jsx(Summary2, { ...state });
506
3392
  };
507
3393
  var AutoHideText = (props) => {
508
3394
  const { text, visibleCount } = props;
@@ -695,7 +3581,7 @@ var Subtitle = (props) => {
695
3581
  value: props.share || "-",
696
3582
  brokerName: props.brokerName
697
3583
  },
698
- components: [/* @__PURE__ */ jsxRuntime.jsx(ui.Text.gradient, { color: "brand" })]
3584
+ components: [/* @__PURE__ */ jsxRuntime.jsx(ui.Text.gradient, { color: "brand" }, "0")]
699
3585
  }
700
3586
  )
701
3587
  )
@@ -772,42 +3658,6 @@ var Alert = (props) => {
772
3658
  }
773
3659
  ) });
774
3660
  };
775
- function generateReferralLink(referralLinkUrl, code) {
776
- return `${referralLinkUrl || window?.location?.origin}?ref=${code}`;
777
- }
778
- async function copyText(content) {
779
- try {
780
- await navigator.clipboard.writeText(content);
781
- ui.toast.success(i18n.i18n.t("common.copy.copied"));
782
- } catch (error) {
783
- ui.toast.success(i18n.i18n.t("common.copy.failed"));
784
- }
785
- }
786
- function formatDateTimeToUTC(input) {
787
- if (input === void 0) {
788
- return "";
789
- }
790
- const date = dateFns.toDate(input);
791
- const utcDate = toUTCDate(date);
792
- return dateFns.format(utcDate, "yyyy-MM-dd HH:mm:ss 'UTC'");
793
- }
794
- function formatYMDTime(time) {
795
- if (time === void 0) {
796
- return void 0;
797
- }
798
- const date = dateFns.toDate(time);
799
- const utcDate = toUTCDate(date);
800
- return dateFns.format(utcDate, "yyyy-MM-dd");
801
- }
802
- function compareDate(d1, d2) {
803
- const isEqual = d1 && d2 && d1.toISOString().substring(0, 10) === d2.toISOString().substring(0, 10);
804
- return isEqual;
805
- }
806
- function toUTCDate(date) {
807
- return new Date(date.toUTCString());
808
- }
809
-
810
- // src/pages/affiliate/referralLink/referralLink.script.tsx
811
3661
  var useReferralLinkScript = () => {
812
3662
  const { t } = i18n.useTranslation();
813
3663
  const onCopy = (value) => {
@@ -922,31 +3772,6 @@ var Title3 = (props) => {
922
3772
  ] })
923
3773
  ] });
924
3774
  };
925
- function fillData(days, origin) {
926
- const now = Date();
927
- const result = new Array(days).fill(0).map((_, index) => {
928
- return {
929
- date: dateFns.format(dateFns.subDays(now, index + 1), "yyyy-MM-dd"),
930
- volume: 0,
931
- opacity: 0
932
- };
933
- }).reverse();
934
- const dataObject = origin?.reduce(
935
- (acc, curr) => {
936
- acc[curr.date] = curr;
937
- return acc;
938
- },
939
- {}
940
- );
941
- for (let index = 0; index < result.length; index++) {
942
- const element = result[index];
943
- const originData = dataObject?.[element.date];
944
- if (originData) {
945
- result[index] = { ...originData, opacity: originData.volume > 0 ? 1 : 0 };
946
- }
947
- }
948
- return result;
949
- }
950
3775
  var useTitleStatisticScript = () => {
951
3776
  const { t } = i18n.useTranslation();
952
3777
  const [period, setPeriod] = react.useState("7");
@@ -1138,7 +3963,7 @@ var MobileLayout = (props) => {
1138
3963
  renderItem: (e, index) => {
1139
3964
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", children: [
1140
3965
  /* @__PURE__ */ jsxRuntime.jsx(
1141
- MobileCell,
3966
+ MobileCell2,
1142
3967
  {
1143
3968
  data: e,
1144
3969
  editRate: props.editRate,
@@ -1189,7 +4014,7 @@ var MobileCellItem = (props) => {
1189
4014
  }
1190
4015
  );
1191
4016
  };
1192
- var MobileCell = (props) => {
4017
+ var MobileCell2 = (props) => {
1193
4018
  const { data, setPinCode, copyLink, editRate, editCode } = props;
1194
4019
  const { t } = i18n.useTranslation();
1195
4020
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 3, direction: "column", className: "oui-w-full", children: [
@@ -1760,25 +4585,33 @@ var useReferralCodesScript = () => {
1760
4585
  setPinCodes([...pinCodes]);
1761
4586
  };
1762
4587
  const codes = react.useMemo(() => {
1763
- if (!referralInfo?.referrer_info?.referral_codes) {
1764
- return void 0;
1765
- }
1766
- const referralCodes = referralInfo?.referrer_info?.referral_codes?.map((item) => {
1767
- if (generateCode && generateCode.code === item.code) {
1768
- item.isAutoGenerated = true;
4588
+ if (referralInfo?.referrer_info?.referral_codes) {
4589
+ const referralCodes = referralInfo.referrer_info.referral_codes.map((item) => {
4590
+ const code = {
4591
+ ...item
4592
+ };
4593
+ if (generateCode && generateCode.code === item.code) {
4594
+ code.isAutoGenerated = true;
4595
+ }
4596
+ return code;
4597
+ });
4598
+ const pinedItems = [];
4599
+ const unpinedItems = [...referralCodes];
4600
+ for (let i = 0; i < pinCodes.length; i++) {
4601
+ const code = pinCodes[i];
4602
+ const index = unpinedItems.findIndex((item) => item.code === code);
4603
+ if (index !== -1) {
4604
+ pinedItems.push({ ...unpinedItems[index], isPined: true });
4605
+ unpinedItems.splice(index, 1);
4606
+ }
1769
4607
  }
1770
- return item;
1771
- });
1772
- const pinedItems = [];
1773
- for (let i = 0; i < pinCodes.length; i++) {
1774
- const code = pinCodes[i];
1775
- const index = referralCodes.findIndex((item) => item.code === code);
1776
- if (index !== -1) {
1777
- pinedItems.push({ ...referralCodes[index], isPined: true });
1778
- referralCodes.splice(index, 1);
4608
+ const allCodes = [...pinedItems, ...unpinedItems];
4609
+ if (allCodes.length === 0) {
4610
+ return void 0;
1779
4611
  }
4612
+ return allCodes;
1780
4613
  }
1781
- return [...pinedItems, ...referralCodes];
4614
+ return void 0;
1782
4615
  }, [referralInfo?.referrer_info?.referral_codes, pinCodes, generateCode]);
1783
4616
  return {
1784
4617
  copyCode,
@@ -2252,7 +5085,7 @@ var Layout = () => {
2252
5085
  var Layout1024 = () => {
2253
5086
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2254
5087
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-flex oui-flex-col xl:oui-flex-row oui-gap-4 oui-w-full", children: [
2255
- /* @__PURE__ */ jsxRuntime.jsx(SummaryWidget, {}),
5088
+ /* @__PURE__ */ jsxRuntime.jsx(SummaryWidget2, {}),
2256
5089
  /* @__PURE__ */ jsxRuntime.jsx(ReferralLinkWidget, {})
2257
5090
  ] }),
2258
5091
  /* @__PURE__ */ jsxRuntime.jsx(TitleStatisticWidget, {}),
@@ -2262,7 +5095,7 @@ var Layout1024 = () => {
2262
5095
  var Layout1280 = () => {
2263
5096
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "row", itemAlign: "stretch", gap: 4, children: [
2264
5097
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", gap: 4, className: "oui-flex-1 oui-w-1/2", children: [
2265
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-flex-1 oui-h-full oui-w-full", children: /* @__PURE__ */ jsxRuntime.jsx(SummaryWidget, {}) }),
5098
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-flex-1 oui-h-full oui-w-full", children: /* @__PURE__ */ jsxRuntime.jsx(SummaryWidget2, {}) }),
2266
5099
  /* @__PURE__ */ jsxRuntime.jsx(TitleStatisticWidget, {})
2267
5100
  ] }),
2268
5101
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", gap: 4, className: "oui-w-1/2", children: [
@@ -2948,7 +5781,7 @@ var useAsTraderScript = () => {
2948
5781
  [uiConnector.AuthStatusEnum.WrongNetwork]: t("connector.wrongNetwork.tooltip")
2949
5782
  };
2950
5783
  return message[authStatus];
2951
- }, [authStatus]);
5784
+ }, [t, authStatus]);
2952
5785
  return {
2953
5786
  isTrader,
2954
5787
  isLoading,
@@ -3217,7 +6050,7 @@ var HomePage = () => {
3217
6050
  }
3218
6051
  );
3219
6052
  };
3220
- var Summary2 = (props) => {
6053
+ var Summary3 = (props) => {
3221
6054
  const { t } = i18n.useTranslation();
3222
6055
  return /* @__PURE__ */ jsxRuntime.jsxs(
3223
6056
  ui.Flex,
@@ -3346,7 +6179,7 @@ var Row2 = (props) => {
3346
6179
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "oui-text-xs md:oui-text-sm xl:oui-text-base", children: utils.commifyOptional(props.vol, { fix: 2, fallback: "0" }) })
3347
6180
  ] });
3348
6181
  };
3349
- var useSummaryScript2 = () => {
6182
+ var useSummaryScript3 = () => {
3350
6183
  const { t } = i18n.useTranslation();
3351
6184
  const [period, setPeriod] = react.useState("All");
3352
6185
  const periodTypes = [
@@ -3403,9 +6236,9 @@ var useSummaryScript2 = () => {
3403
6236
  code
3404
6237
  };
3405
6238
  };
3406
- var SummaryWidget2 = () => {
3407
- const state = useSummaryScript2();
3408
- return /* @__PURE__ */ jsxRuntime.jsx(Summary2, { ...state });
6239
+ var SummaryWidget3 = () => {
6240
+ const state = useSummaryScript3();
6241
+ return /* @__PURE__ */ jsxRuntime.jsx(Summary3, { ...state });
3409
6242
  };
3410
6243
  var TitleStatistic2 = (props) => {
3411
6244
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -3768,7 +6601,7 @@ var TraderPage = () => {
3768
6601
  gap: 4,
3769
6602
  className: "oui-flex oui-flex-col xl:oui-flex-row xl:oui-items-stretch",
3770
6603
  children: [
3771
- /* @__PURE__ */ jsxRuntime.jsx(SummaryWidget2, {}),
6604
+ /* @__PURE__ */ jsxRuntime.jsx(SummaryWidget3, {}),
3772
6605
  /* @__PURE__ */ jsxRuntime.jsx(TitleStatisticWidget2, {})
3773
6606
  ]
3774
6607
  }
@@ -3961,9 +6794,39 @@ var TabWidget = (props) => {
3961
6794
  return /* @__PURE__ */ jsxRuntime.jsx(Tab, { classNames: props.classNames, ...state });
3962
6795
  };
3963
6796
  var DashboardPage = (props) => {
3964
- const { classNames = {} } = props;
3965
- const { root, ...rest } = classNames;
3966
- return /* @__PURE__ */ jsxRuntime.jsx("div", { id: "oui-affiliate-dashboard-page", className: ui.cn("oui-w-full oui-tracking-tight", root), children: /* @__PURE__ */ jsxRuntime.jsx(TabWidget, { classNames: rest }) });
6797
+ const { root, ...rest } = props.classNames || {};
6798
+ const { state } = hooks.useAccount();
6799
+ const { wrongNetwork, disabledConnect, initialized } = reactApp.useAppContext();
6800
+ const { isMultiLevelEnabled, multiLevelRebateInfo, isAffiliate, isLoading } = useReferralContext();
6801
+ const loadingView = /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { justify: "center", itemAlign: "center", height: "100vh", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {}) });
6802
+ const [delay, setDelay] = react.useState(!initialized);
6803
+ react.useEffect(() => {
6804
+ const timer = setTimeout(() => setDelay(false), 500);
6805
+ return () => clearTimeout(timer);
6806
+ }, []);
6807
+ if (state.validating || delay) {
6808
+ return loadingView;
6809
+ }
6810
+ if (wrongNetwork || disabledConnect || state.status < types.AccountStatusEnum.EnableTrading && state.status !== types.AccountStatusEnum.EnableTradingWithoutConnected) {
6811
+ return /* @__PURE__ */ jsxRuntime.jsx(LandingPage, {});
6812
+ }
6813
+ if (isLoading) {
6814
+ return loadingView;
6815
+ }
6816
+ if (isMultiLevelEnabled) {
6817
+ if (multiLevelRebateInfo?.referral_code || isAffiliate) {
6818
+ return /* @__PURE__ */ jsxRuntime.jsx(MultiLevelAffiliatePage, {});
6819
+ }
6820
+ return /* @__PURE__ */ jsxRuntime.jsx(LandingPage, {});
6821
+ }
6822
+ return /* @__PURE__ */ jsxRuntime.jsx(
6823
+ "div",
6824
+ {
6825
+ id: "oui-affiliate-dashboard-page",
6826
+ className: ui.cn("oui-w-full oui-tracking-tight", root),
6827
+ children: /* @__PURE__ */ jsxRuntime.jsx(TabWidget, { classNames: rest })
6828
+ }
6829
+ );
3967
6830
  };
3968
6831
  var AffiliateLayout = (props) => {
3969
6832
  const { ...rest } = props;
@@ -4066,6 +6929,8 @@ var AffiliateLayoutWidget = (props) => {
4066
6929
 
4067
6930
  exports.AffiliateLayoutWidget = AffiliateLayoutWidget;
4068
6931
  exports.Dashboard = dashboard_exports;
6932
+ exports.LandingPage = LandingPage;
6933
+ exports.MultiLevelAffiliatePage = MultiLevelAffiliatePage;
4069
6934
  exports.ReferralContext = ReferralContext;
4070
6935
  exports.ReferralProvider = ReferralProvider;
4071
6936
  exports.TabTypes = TabTypes;