@orderly.network/affiliate 3.0.0-beta.0 → 3.0.0-beta.10
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.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +407 -106
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +409 -108
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createContext, useState, useEffect, useRef, useMemo, useContext, useCallback, Fragment as Fragment$1 } from 'react';
|
|
2
|
-
import { useMutation, cleanStringStyle, useAccount, usePrivateQuery, noCacheConfig, useDaily, useMemoizedFn, useMediaQuery, useReferralRebateSummary, useLocalStorage, useRefereeRebateSummary, useRefereeInfo
|
|
2
|
+
import { useMutation, cleanStringStyle, useCheckReferralCode, useAccount, usePrivateQuery, noCacheConfig, useDaily, useMemoizedFn, useMediaQuery, useReferralRebateSummary, useLocalStorage, useRefereeRebateSummary, useRefereeInfo } from '@orderly.network/hooks';
|
|
3
3
|
import { useAppContext } from '@orderly.network/react-app';
|
|
4
4
|
import { AccountStatusEnum, EMPTY_LIST } from '@orderly.network/types';
|
|
5
|
-
import { registerSimpleDialog, registerSimpleSheet, modal, useModal, SimpleDialog, TextField, inputFormatter, Flex, Text, cn, toast, Dialog, DialogContent, DialogTitle, Divider, Input as Input$1, Button, formatAddress, Box, Slider, WarningIcon, Grid, Spinner, Collapsible, CollapsibleContent, Select, Tabs, TabPanel, usePagination, DatePicker, TabsBase, TabsList, TabsTrigger, TabsContent, parseNumber, ListView, CopyIcon, DataTable, useScreen, Statistic, Tooltip, DialogTrigger, DialogHeader, DialogBody } from '@orderly.network/ui';
|
|
5
|
+
import { registerSimpleDialog, registerSimpleSheet, modal, useModal, SimpleDialog, TextField, inputFormatter, Flex, Text, cn, toast, Dialog, DialogContent, DialogTitle, Divider, Input as Input$1, Button, formatAddress, Checkbox, Box, Slider, WarningIcon, Grid, Spinner, Collapsible, CollapsibleContent, Select, Tabs, TabPanel, usePagination, DatePicker, TabsBase, TabsList, TabsTrigger, TabsContent, parseNumber, ListView, CopyIcon, DataTable, useScreen, Statistic, Tooltip, DialogTrigger, DialogHeader, DialogBody } from '@orderly.network/ui';
|
|
6
6
|
import { subDays, format, toDate } from 'date-fns';
|
|
7
7
|
import { Decimal, commify, commifyOptional } from '@orderly.network/utils';
|
|
8
8
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
@@ -76,7 +76,11 @@ var useMultiLevelStatistics = (time_range) => {
|
|
|
76
76
|
// src/hooks/useMultiLevelReferralData.ts
|
|
77
77
|
var useMultiLevelReferralData = () => {
|
|
78
78
|
const { data: volumePrerequisite, isLoading: volumePrerequisiteLoading } = useVolumePrerequisite();
|
|
79
|
-
const {
|
|
79
|
+
const {
|
|
80
|
+
data: maxRebateRateRes,
|
|
81
|
+
mutate: maxRebateRateMutate,
|
|
82
|
+
isLoading: maxRebateRateLoading
|
|
83
|
+
} = useMaxRebateRate();
|
|
80
84
|
const {
|
|
81
85
|
data: multiLevelRebateInfoRes,
|
|
82
86
|
mutate: multiLevelRebateInfoMutate,
|
|
@@ -106,6 +110,7 @@ var useMultiLevelReferralData = () => {
|
|
|
106
110
|
isMultiLevelEnabled,
|
|
107
111
|
isMultiLevelReferralUnlocked,
|
|
108
112
|
multiLevelRebateInfoMutate,
|
|
113
|
+
maxRebateRateMutate,
|
|
109
114
|
isLoading
|
|
110
115
|
};
|
|
111
116
|
};
|
|
@@ -154,6 +159,7 @@ var ReferralProvider = (props) => {
|
|
|
154
159
|
isMultiLevelReferralUnlocked,
|
|
155
160
|
multiLevelRebateInfoMutate,
|
|
156
161
|
maxRebateRate,
|
|
162
|
+
maxRebateRateMutate,
|
|
157
163
|
isLoading: isMultiLevelLoading
|
|
158
164
|
} = useMultiLevelReferralData();
|
|
159
165
|
const [showHome, setShowHome] = useState(isLoading);
|
|
@@ -197,10 +203,12 @@ var ReferralProvider = (props) => {
|
|
|
197
203
|
}
|
|
198
204
|
}, [isAffiliate, isTrader]);
|
|
199
205
|
const memoMutate = useMemoizedFn(() => {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
206
|
+
return Promise.allSettled([
|
|
207
|
+
volumeStatisticsMutate(),
|
|
208
|
+
dailyVolumeMutate(),
|
|
209
|
+
referralInfoMutate(),
|
|
210
|
+
generateCodeMutate()
|
|
211
|
+
]);
|
|
204
212
|
});
|
|
205
213
|
useEffect(() => {
|
|
206
214
|
const searchParams = new URLSearchParams(window.location.search);
|
|
@@ -263,7 +271,8 @@ var ReferralProvider = (props) => {
|
|
|
263
271
|
isMultiLevelEnabled,
|
|
264
272
|
isMultiLevelReferralUnlocked,
|
|
265
273
|
multiLevelRebateInfoMutate,
|
|
266
|
-
maxRebateRate
|
|
274
|
+
maxRebateRate,
|
|
275
|
+
maxRebateRateMutate
|
|
267
276
|
};
|
|
268
277
|
}, [
|
|
269
278
|
becomeAnAffiliateUrl,
|
|
@@ -294,7 +303,8 @@ var ReferralProvider = (props) => {
|
|
|
294
303
|
isMultiLevelReferralUnlocked,
|
|
295
304
|
multiLevelRebateInfoMutate,
|
|
296
305
|
maxRebateRate,
|
|
297
|
-
isMultiLevelLoading
|
|
306
|
+
isMultiLevelLoading,
|
|
307
|
+
maxRebateRateMutate
|
|
298
308
|
]);
|
|
299
309
|
return /* @__PURE__ */ jsx(ReferralContext.Provider, { value: memoizedValue, children });
|
|
300
310
|
};
|
|
@@ -415,6 +425,7 @@ var ChevronIcon = ({ expanded }) => /* @__PURE__ */ jsx(
|
|
|
415
425
|
}
|
|
416
426
|
);
|
|
417
427
|
var useReferralCode = () => {
|
|
428
|
+
const [doBindReferralCode, { isMutating: isBindMutating }] = useMutation("/v1/referral/bind");
|
|
418
429
|
const [doCreateReferralCode, { isMutating: isCreateMutating }] = useMutation(
|
|
419
430
|
"/v1/referral/multi_level/claim_code"
|
|
420
431
|
);
|
|
@@ -426,6 +437,9 @@ var useReferralCode = () => {
|
|
|
426
437
|
const createReferralCode = async (params) => {
|
|
427
438
|
return doCreateReferralCode(params);
|
|
428
439
|
};
|
|
440
|
+
const bindReferralCode = async (params) => {
|
|
441
|
+
return doBindReferralCode(params);
|
|
442
|
+
};
|
|
429
443
|
const editReferralCode = async (params) => {
|
|
430
444
|
return doEditReferralCode(params);
|
|
431
445
|
};
|
|
@@ -435,8 +449,9 @@ var useReferralCode = () => {
|
|
|
435
449
|
const resetRebateRate = async (params) => {
|
|
436
450
|
return doResetRebateRate(params);
|
|
437
451
|
};
|
|
438
|
-
const isMutating = isCreateMutating || isEditMutating || isUpdateRebateRateMutating || isResetRebateRateMutating;
|
|
452
|
+
const isMutating = isBindMutating || isCreateMutating || isEditMutating || isUpdateRebateRateMutating || isResetRebateRateMutating;
|
|
439
453
|
return {
|
|
454
|
+
bindReferralCode,
|
|
440
455
|
createReferralCode,
|
|
441
456
|
editReferralCode,
|
|
442
457
|
updateRebateRate,
|
|
@@ -477,15 +492,22 @@ var useReferralCodeFormScript = (options) => {
|
|
|
477
492
|
0,
|
|
478
493
|
new Decimal(maxRebatePercentage).sub(referrerRebatePercentage).toNumber()
|
|
479
494
|
);
|
|
480
|
-
}, [referrerRebatePercentage]);
|
|
495
|
+
}, [maxRebatePercentage, referrerRebatePercentage]);
|
|
481
496
|
const codeChanged = useMemo(() => {
|
|
482
497
|
return newCode !== referralCode;
|
|
483
498
|
}, [newCode, referralCode]);
|
|
484
499
|
const rateChanged = useMemo(() => {
|
|
485
500
|
return new Decimal(referrerRebatePercentage).toNumber() !== new Decimal(referrerRebateRate || 0).mul(100).toNumber();
|
|
486
501
|
}, [referrerRebatePercentage, referrerRebateRate, newCode]);
|
|
502
|
+
const getErrorMessage = (err) => {
|
|
503
|
+
if (typeof err === "object" && err !== null && "message" in err) {
|
|
504
|
+
const msg = err.message;
|
|
505
|
+
return typeof msg === "string" ? msg : void 0;
|
|
506
|
+
}
|
|
507
|
+
return void 0;
|
|
508
|
+
};
|
|
487
509
|
const handleError = (err) => {
|
|
488
|
-
toast.error(err
|
|
510
|
+
toast.error(getErrorMessage(err) || t("common.somethingWentWrong"));
|
|
489
511
|
};
|
|
490
512
|
const handleResult = (res) => {
|
|
491
513
|
if (res.success) {
|
|
@@ -493,7 +515,7 @@ var useReferralCodeFormScript = (options) => {
|
|
|
493
515
|
toast.success(t("affiliate.confirmChanges.success"));
|
|
494
516
|
options.close?.();
|
|
495
517
|
} else {
|
|
496
|
-
toast.error(res.message);
|
|
518
|
+
toast.error(res.message || t("common.somethingWentWrong"));
|
|
497
519
|
}
|
|
498
520
|
};
|
|
499
521
|
const onEdit = async () => {
|
|
@@ -566,13 +588,15 @@ var useReferralCodeFormScript = (options) => {
|
|
|
566
588
|
}
|
|
567
589
|
};
|
|
568
590
|
const buttonDisabled = type === "edit" /* Edit */ && !codeChanged && !rateChanged;
|
|
591
|
+
const confirmButtonLoading = isMutating;
|
|
569
592
|
return {
|
|
593
|
+
type,
|
|
570
594
|
onClick,
|
|
571
595
|
maxRebatePercentage,
|
|
572
596
|
referrerRebatePercentage,
|
|
573
597
|
setReferrerRebatePercentage,
|
|
574
598
|
refereeRebatePercentage,
|
|
575
|
-
|
|
599
|
+
confirmButtonLoading,
|
|
576
600
|
newCode,
|
|
577
601
|
setNewCode,
|
|
578
602
|
isReview,
|
|
@@ -602,6 +626,68 @@ var GiftIcon = (props) => {
|
|
|
602
626
|
}
|
|
603
627
|
);
|
|
604
628
|
};
|
|
629
|
+
var WarningBox = (props) => /* @__PURE__ */ jsxs(
|
|
630
|
+
Flex,
|
|
631
|
+
{
|
|
632
|
+
className: "oui-bg-warning/10",
|
|
633
|
+
justify: "start",
|
|
634
|
+
itemAlign: "start",
|
|
635
|
+
gap: 1,
|
|
636
|
+
r: "lg",
|
|
637
|
+
p: 3,
|
|
638
|
+
children: [
|
|
639
|
+
/* @__PURE__ */ jsx(WarningIcon, { className: "oui-shrink-0 oui-text-warning" }),
|
|
640
|
+
typeof props.children === "string" ? /* @__PURE__ */ jsx(Text, { size: "2xs", intensity: 54, className: "oui-text-warning", children: props.children }) : props.children
|
|
641
|
+
]
|
|
642
|
+
}
|
|
643
|
+
);
|
|
644
|
+
var ReferralCodeInput = (props) => {
|
|
645
|
+
const hasSetCursorToEnd = useRef(false);
|
|
646
|
+
return /* @__PURE__ */ jsx(
|
|
647
|
+
TextField,
|
|
648
|
+
{
|
|
649
|
+
type: "text",
|
|
650
|
+
fullWidth: true,
|
|
651
|
+
label: props.label ?? "",
|
|
652
|
+
placeholder: props.placeholder,
|
|
653
|
+
value: props.value,
|
|
654
|
+
onChange: (e) => {
|
|
655
|
+
props.onChange(e.target.value);
|
|
656
|
+
},
|
|
657
|
+
onFocus: (e) => {
|
|
658
|
+
if (props.autoFocus && !hasSetCursorToEnd.current) {
|
|
659
|
+
hasSetCursorToEnd.current = true;
|
|
660
|
+
const input = e.target;
|
|
661
|
+
const len = input.value.length;
|
|
662
|
+
requestAnimationFrame(() => {
|
|
663
|
+
input.setSelectionRange(len, len);
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
formatters: [
|
|
668
|
+
inputFormatter.createRegexInputFormatter((value) => {
|
|
669
|
+
return String(value).replace(
|
|
670
|
+
/[a-z]/g,
|
|
671
|
+
(char) => char.toUpperCase()
|
|
672
|
+
);
|
|
673
|
+
}),
|
|
674
|
+
inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)
|
|
675
|
+
],
|
|
676
|
+
className: "oui-w-full",
|
|
677
|
+
classNames: {
|
|
678
|
+
label: "oui-text-base-contrast-54 oui-text-xs",
|
|
679
|
+
input: "placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm"
|
|
680
|
+
},
|
|
681
|
+
helpText: props.helpText,
|
|
682
|
+
color: props.color,
|
|
683
|
+
maxLength: 10,
|
|
684
|
+
minLength: 4,
|
|
685
|
+
autoComplete: "off",
|
|
686
|
+
disabled: props.disabled,
|
|
687
|
+
autoFocus: props.autoFocus
|
|
688
|
+
}
|
|
689
|
+
);
|
|
690
|
+
};
|
|
605
691
|
var ReferralCodeForm = (props) => {
|
|
606
692
|
const { type, isReview } = props;
|
|
607
693
|
const { t } = useTranslation();
|
|
@@ -662,7 +748,8 @@ var ReferralCodeForm = (props) => {
|
|
|
662
748
|
value: props.newCode,
|
|
663
749
|
onChange: props.setNewCode,
|
|
664
750
|
autoFocus: props.focusField === "referralCode" /* ReferralCode */,
|
|
665
|
-
disabled: isReview || hasBoundReferee
|
|
751
|
+
disabled: isReview || hasBoundReferee,
|
|
752
|
+
label: t("affiliate.referralCode.editCodeModal.label")
|
|
666
753
|
}
|
|
667
754
|
);
|
|
668
755
|
const commissionConfiguration = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -717,8 +804,8 @@ var ReferralCodeForm = (props) => {
|
|
|
717
804
|
{
|
|
718
805
|
fullWidth: true,
|
|
719
806
|
onClick: props.onClick,
|
|
720
|
-
disabled: props.buttonDisabled || props.
|
|
721
|
-
loading: props.
|
|
807
|
+
disabled: props.buttonDisabled || props.confirmButtonLoading,
|
|
808
|
+
loading: props.confirmButtonLoading,
|
|
722
809
|
size: "md",
|
|
723
810
|
className: "oui-referralCodeForm-confirm-btn",
|
|
724
811
|
children: buttonText
|
|
@@ -772,6 +859,9 @@ var ReferralCodeForm = (props) => {
|
|
|
772
859
|
var NoCommissionCard = (props) => {
|
|
773
860
|
const { t } = useTranslation();
|
|
774
861
|
const amount = props.directBonusRebateRate;
|
|
862
|
+
if (!amount || amount <= 0) {
|
|
863
|
+
return null;
|
|
864
|
+
}
|
|
775
865
|
return /* @__PURE__ */ jsxs(
|
|
776
866
|
Flex,
|
|
777
867
|
{
|
|
@@ -786,7 +876,7 @@ var NoCommissionCard = (props) => {
|
|
|
786
876
|
/* @__PURE__ */ jsxs(Flex, { justify: "between", width: "100%", itemAlign: "center", children: [
|
|
787
877
|
/* @__PURE__ */ jsxs(Flex, { direction: "column", itemAlign: "start", gap: 1, children: [
|
|
788
878
|
/* @__PURE__ */ jsx(Text, { size: "2xs", intensity: 54, children: t("affiliate.noCommissionCard.title") }),
|
|
789
|
-
/* @__PURE__ */ jsxs(Text, { size: "lg", className: "oui-text-primary-light
|
|
879
|
+
/* @__PURE__ */ jsxs(Text, { size: "lg", className: "oui-font-semibold oui-text-primary-light", children: [
|
|
790
880
|
"+ ",
|
|
791
881
|
amount,
|
|
792
882
|
"%"
|
|
@@ -848,7 +938,7 @@ var RebateRateSlider = (props) => {
|
|
|
848
938
|
GiftIcon,
|
|
849
939
|
{
|
|
850
940
|
size: 16,
|
|
851
|
-
className: "oui-text-base-contrast
|
|
941
|
+
className: "oui-mt-px oui-text-base-contrast"
|
|
852
942
|
}
|
|
853
943
|
),
|
|
854
944
|
/* @__PURE__ */ jsx(
|
|
@@ -872,72 +962,6 @@ var RebateRateSlider = (props) => {
|
|
|
872
962
|
] })
|
|
873
963
|
] });
|
|
874
964
|
};
|
|
875
|
-
var ReferralCodeInput = (props) => {
|
|
876
|
-
const { t } = useTranslation();
|
|
877
|
-
const hasSetCursorToEnd = useRef(false);
|
|
878
|
-
return /* @__PURE__ */ jsx(
|
|
879
|
-
TextField,
|
|
880
|
-
{
|
|
881
|
-
type: "text",
|
|
882
|
-
fullWidth: true,
|
|
883
|
-
label: t("affiliate.referralCode.editCodeModal.label"),
|
|
884
|
-
value: props.value,
|
|
885
|
-
onChange: (e) => {
|
|
886
|
-
props.onChange(e.target.value);
|
|
887
|
-
},
|
|
888
|
-
onFocus: (e) => {
|
|
889
|
-
if (props.autoFocus && !hasSetCursorToEnd.current) {
|
|
890
|
-
hasSetCursorToEnd.current = true;
|
|
891
|
-
const input = e.target;
|
|
892
|
-
const len = input.value.length;
|
|
893
|
-
requestAnimationFrame(() => {
|
|
894
|
-
input.setSelectionRange(len, len);
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
},
|
|
898
|
-
formatters: [
|
|
899
|
-
inputFormatter.createRegexInputFormatter((value) => {
|
|
900
|
-
return String(value).replace(
|
|
901
|
-
/[a-z]/g,
|
|
902
|
-
(char) => char.toUpperCase()
|
|
903
|
-
);
|
|
904
|
-
}),
|
|
905
|
-
inputFormatter.createRegexInputFormatter(/[^A-Z0-9]/g)
|
|
906
|
-
],
|
|
907
|
-
className: "oui-w-full",
|
|
908
|
-
classNames: {
|
|
909
|
-
label: "oui-text-base-contrast-54 oui-text-xs",
|
|
910
|
-
input: "placeholder:oui-text-base-contrast-20 placeholder:oui-text-sm"
|
|
911
|
-
},
|
|
912
|
-
maxLength: 10,
|
|
913
|
-
minLength: 4,
|
|
914
|
-
autoComplete: "off",
|
|
915
|
-
disabled: props.disabled,
|
|
916
|
-
autoFocus: props.autoFocus
|
|
917
|
-
}
|
|
918
|
-
);
|
|
919
|
-
};
|
|
920
|
-
var WarningBox = (props) => {
|
|
921
|
-
const { children } = props;
|
|
922
|
-
if (typeof children === "string") {
|
|
923
|
-
return /* @__PURE__ */ jsxs(
|
|
924
|
-
Flex,
|
|
925
|
-
{
|
|
926
|
-
className: "oui-bg-warning/10",
|
|
927
|
-
justify: "start",
|
|
928
|
-
itemAlign: "start",
|
|
929
|
-
gap: 1,
|
|
930
|
-
r: "lg",
|
|
931
|
-
p: 3,
|
|
932
|
-
children: [
|
|
933
|
-
/* @__PURE__ */ jsx(WarningIcon, { className: "oui-shrink-0 oui-text-warning" }),
|
|
934
|
-
/* @__PURE__ */ jsx(Text, { size: "2xs", intensity: 54, className: "oui-text-warning", children })
|
|
935
|
-
]
|
|
936
|
-
}
|
|
937
|
-
);
|
|
938
|
-
}
|
|
939
|
-
return children;
|
|
940
|
-
};
|
|
941
965
|
var ReferralCodeFormWidget = (props) => {
|
|
942
966
|
const state = useReferralCodeFormScript(props);
|
|
943
967
|
return /* @__PURE__ */ jsx(ReferralCodeForm, { ...state, ...props });
|
|
@@ -954,6 +978,190 @@ registerSimpleDialog(ReferralCodeFormDialogId, ReferralCodeFormWidget, {
|
|
|
954
978
|
}
|
|
955
979
|
});
|
|
956
980
|
registerSimpleSheet(ReferralCodeFormSheetId, ReferralCodeFormWidget);
|
|
981
|
+
function formatReferralCodeInput(raw) {
|
|
982
|
+
return String(raw).replace(/[a-z]/g, (c) => c.toUpperCase()).replace(/[^A-Z0-9]/g, "");
|
|
983
|
+
}
|
|
984
|
+
var useBindReferralCodeScript = (options) => {
|
|
985
|
+
const { t } = useTranslation();
|
|
986
|
+
const [bindCodeInput, setBindCodeInput] = useState("");
|
|
987
|
+
const [skipBinding, setSkipBinding] = useState(false);
|
|
988
|
+
const [isAwaitingPostSuccess, setIsAwaitingPostSuccess] = useState(false);
|
|
989
|
+
const formattedBindCode = useMemo(
|
|
990
|
+
() => formatReferralCodeInput(bindCodeInput),
|
|
991
|
+
[bindCodeInput]
|
|
992
|
+
);
|
|
993
|
+
const { isExist: isBindCodeExist, isLoading: isBindCodeChecking } = useCheckReferralCode(
|
|
994
|
+
formattedBindCode.length >= 4 ? formattedBindCode : void 0
|
|
995
|
+
);
|
|
996
|
+
const { bindReferralCode, isMutating } = useReferralCode();
|
|
997
|
+
const getErrorMessage = (err) => {
|
|
998
|
+
if (typeof err === "object" && err !== null && "message" in err) {
|
|
999
|
+
const msg = err.message;
|
|
1000
|
+
return typeof msg === "string" ? msg : void 0;
|
|
1001
|
+
}
|
|
1002
|
+
return void 0;
|
|
1003
|
+
};
|
|
1004
|
+
const handleError = (err) => {
|
|
1005
|
+
toast.error(getErrorMessage(err) || t("common.somethingWentWrong"));
|
|
1006
|
+
};
|
|
1007
|
+
const runAfterSuccess = async (payload) => {
|
|
1008
|
+
setIsAwaitingPostSuccess(true);
|
|
1009
|
+
try {
|
|
1010
|
+
await Promise.resolve(options.onSuccess?.(payload));
|
|
1011
|
+
} finally {
|
|
1012
|
+
setIsAwaitingPostSuccess(false);
|
|
1013
|
+
}
|
|
1014
|
+
options.close?.();
|
|
1015
|
+
};
|
|
1016
|
+
const onConfirm = async () => {
|
|
1017
|
+
if (skipBinding) {
|
|
1018
|
+
await runAfterSuccess({ skipped: true });
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
if (formattedBindCode.length < 4 || formattedBindCode.length > 10 || isBindCodeChecking || !isBindCodeExist) {
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
try {
|
|
1025
|
+
await bindReferralCode({ referral_code: formattedBindCode });
|
|
1026
|
+
toast.success(t("affiliate.referralCode.bound"));
|
|
1027
|
+
await runAfterSuccess({ skipped: false });
|
|
1028
|
+
} catch (err) {
|
|
1029
|
+
handleError(err);
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
const buttonDisabled = !skipBinding && (formattedBindCode.length < 4 || formattedBindCode.length > 10 || isBindCodeChecking || !isBindCodeExist);
|
|
1033
|
+
const confirmButtonLoading = isMutating || isAwaitingPostSuccess;
|
|
1034
|
+
return {
|
|
1035
|
+
bindCodeInput,
|
|
1036
|
+
setBindCodeInput,
|
|
1037
|
+
skipBinding,
|
|
1038
|
+
setSkipBinding,
|
|
1039
|
+
formattedBindCode,
|
|
1040
|
+
isBindCodeExist,
|
|
1041
|
+
isBindCodeChecking,
|
|
1042
|
+
buttonDisabled,
|
|
1043
|
+
confirmButtonLoading,
|
|
1044
|
+
onConfirm
|
|
1045
|
+
};
|
|
1046
|
+
};
|
|
1047
|
+
var BindReferralCode = (props) => {
|
|
1048
|
+
const { t } = useTranslation();
|
|
1049
|
+
const bindCodeInvalid = !props.skipBinding && props.formattedBindCode.length >= 4 && !props.isBindCodeChecking && props.isBindCodeExist === false;
|
|
1050
|
+
const titleView = /* @__PURE__ */ jsxs(
|
|
1051
|
+
Flex,
|
|
1052
|
+
{
|
|
1053
|
+
width: "100%",
|
|
1054
|
+
direction: "column",
|
|
1055
|
+
itemAlign: "start",
|
|
1056
|
+
gap: 3,
|
|
1057
|
+
className: "oui-bindReferralCode-header",
|
|
1058
|
+
children: [
|
|
1059
|
+
/* @__PURE__ */ jsx(Text, { size: "base", intensity: 98, children: t("affiliate.referralCode.bind.modal.title") }),
|
|
1060
|
+
/* @__PURE__ */ jsx(Divider, { intensity: 8, className: "oui-w-full" })
|
|
1061
|
+
]
|
|
1062
|
+
}
|
|
1063
|
+
);
|
|
1064
|
+
const descriptionView = /* @__PURE__ */ jsx(WarningBox, { children: /* @__PURE__ */ jsx(
|
|
1065
|
+
Text,
|
|
1066
|
+
{
|
|
1067
|
+
size: "2xs",
|
|
1068
|
+
intensity: 54,
|
|
1069
|
+
className: "oui-leading-[18px] oui-text-warning-darken",
|
|
1070
|
+
children: t("affiliate.referralCode.bind.modal.description")
|
|
1071
|
+
}
|
|
1072
|
+
) });
|
|
1073
|
+
return /* @__PURE__ */ jsxs(
|
|
1074
|
+
Flex,
|
|
1075
|
+
{
|
|
1076
|
+
direction: "column",
|
|
1077
|
+
itemAlign: "start",
|
|
1078
|
+
gap: 6,
|
|
1079
|
+
className: "oui-affiliate-bindReferralCode oui-font-semibold",
|
|
1080
|
+
children: [
|
|
1081
|
+
titleView,
|
|
1082
|
+
descriptionView,
|
|
1083
|
+
/* @__PURE__ */ jsxs(Flex, { width: "100%", direction: "column", itemAlign: "start", gap: 4, children: [
|
|
1084
|
+
/* @__PURE__ */ jsx(
|
|
1085
|
+
ReferralCodeInput,
|
|
1086
|
+
{
|
|
1087
|
+
value: props.bindCodeInput,
|
|
1088
|
+
onChange: props.setBindCodeInput,
|
|
1089
|
+
autoFocus: true,
|
|
1090
|
+
disabled: props.skipBinding,
|
|
1091
|
+
placeholder: t("affiliate.referralCode.bind.input.placeholder"),
|
|
1092
|
+
helpText: bindCodeInvalid ? t("affiliate.referralCode.notExist") : void 0,
|
|
1093
|
+
color: bindCodeInvalid ? "danger" : void 0
|
|
1094
|
+
}
|
|
1095
|
+
),
|
|
1096
|
+
/* @__PURE__ */ jsxs(Flex, { className: "oui-gap-[6px]", children: [
|
|
1097
|
+
/* @__PURE__ */ jsx(
|
|
1098
|
+
Checkbox,
|
|
1099
|
+
{
|
|
1100
|
+
color: "white",
|
|
1101
|
+
id: "oui-checkbox-bindReferralCode-skip",
|
|
1102
|
+
checked: props.skipBinding,
|
|
1103
|
+
onCheckedChange: (checked) => {
|
|
1104
|
+
props.setSkipBinding(checked);
|
|
1105
|
+
if (checked) {
|
|
1106
|
+
props.setBindCodeInput("");
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
),
|
|
1111
|
+
/* @__PURE__ */ jsx(
|
|
1112
|
+
"label",
|
|
1113
|
+
{
|
|
1114
|
+
htmlFor: "oui-checkbox-bindReferralCode-skip",
|
|
1115
|
+
className: "oui-text-2xs oui-font-normal oui-text-base-contrast-54",
|
|
1116
|
+
children: t("affiliate.referralCode.bind.skip")
|
|
1117
|
+
}
|
|
1118
|
+
)
|
|
1119
|
+
] }),
|
|
1120
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "row", gap: 2, width: "100%", mt: 0, pt: 5, children: [
|
|
1121
|
+
/* @__PURE__ */ jsx(
|
|
1122
|
+
Button,
|
|
1123
|
+
{
|
|
1124
|
+
variant: "contained",
|
|
1125
|
+
color: "gray",
|
|
1126
|
+
fullWidth: true,
|
|
1127
|
+
onClick: props.close,
|
|
1128
|
+
size: "md",
|
|
1129
|
+
className: "oui-bindReferralCode-cancel-btn",
|
|
1130
|
+
children: t("common.cancel")
|
|
1131
|
+
}
|
|
1132
|
+
),
|
|
1133
|
+
/* @__PURE__ */ jsx(
|
|
1134
|
+
Button,
|
|
1135
|
+
{
|
|
1136
|
+
fullWidth: true,
|
|
1137
|
+
onClick: props.onConfirm,
|
|
1138
|
+
disabled: props.buttonDisabled || props.confirmButtonLoading,
|
|
1139
|
+
loading: props.confirmButtonLoading,
|
|
1140
|
+
size: "md",
|
|
1141
|
+
className: "oui-bindReferralCode-confirm-btn",
|
|
1142
|
+
children: t("common.confirm")
|
|
1143
|
+
}
|
|
1144
|
+
)
|
|
1145
|
+
] })
|
|
1146
|
+
] })
|
|
1147
|
+
]
|
|
1148
|
+
}
|
|
1149
|
+
);
|
|
1150
|
+
};
|
|
1151
|
+
var BindReferralCodeWidget = (props) => {
|
|
1152
|
+
const state = useBindReferralCodeScript(props);
|
|
1153
|
+
return /* @__PURE__ */ jsx(BindReferralCode, { ...state, ...props });
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1156
|
+
// src/pages/multiLevel/components/bindReferralCode/modal.ts
|
|
1157
|
+
var BindReferralCodeDialogId = "BindReferralCodeDialogId";
|
|
1158
|
+
registerSimpleDialog(BindReferralCodeDialogId, BindReferralCodeWidget, {
|
|
1159
|
+
size: "sm",
|
|
1160
|
+
classNames: {
|
|
1161
|
+
content: "oui-border oui-border-line-6",
|
|
1162
|
+
body: "!oui-pt-3"
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
957
1165
|
var TradingVolumeProgress = (props) => {
|
|
958
1166
|
const { t } = useTranslation();
|
|
959
1167
|
const { classNames } = props;
|
|
@@ -1056,6 +1264,11 @@ var TradingVolumeProgress = (props) => {
|
|
|
1056
1264
|
}
|
|
1057
1265
|
);
|
|
1058
1266
|
};
|
|
1267
|
+
function parseMaxRebateRateFromSettled(result) {
|
|
1268
|
+
if (result.status !== "fulfilled") return void 0;
|
|
1269
|
+
const num = result.value?.max_rebate_rate;
|
|
1270
|
+
return typeof num === "number" ? num : void 0;
|
|
1271
|
+
}
|
|
1059
1272
|
var Hero = () => {
|
|
1060
1273
|
const { t } = useTranslation();
|
|
1061
1274
|
const { state } = useAccount();
|
|
@@ -1064,21 +1277,54 @@ var Hero = () => {
|
|
|
1064
1277
|
const {
|
|
1065
1278
|
isMultiLevelReferralUnlocked,
|
|
1066
1279
|
isMultiLevelEnabled,
|
|
1280
|
+
isTrader,
|
|
1067
1281
|
multiLevelRebateInfo,
|
|
1068
1282
|
multiLevelRebateInfoMutate,
|
|
1069
|
-
maxRebateRate
|
|
1283
|
+
maxRebateRate,
|
|
1284
|
+
maxRebateRateMutate,
|
|
1285
|
+
mutate,
|
|
1286
|
+
referralInfo
|
|
1070
1287
|
} = useReferralContext();
|
|
1071
|
-
const
|
|
1288
|
+
const boundReferralCode = referralInfo?.referee_info?.referer_code?.trim() ?? "";
|
|
1289
|
+
const openBindReferralOnlyModal = () => {
|
|
1290
|
+
modal.show(BindReferralCodeDialogId, {
|
|
1291
|
+
onSuccess: async ({ skipped }) => {
|
|
1292
|
+
if (skipped) return;
|
|
1293
|
+
await Promise.allSettled([multiLevelRebateInfoMutate?.(), mutate?.()]);
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
};
|
|
1297
|
+
const showCreateReferralCodeModal = (maxRateOverride) => {
|
|
1072
1298
|
modal.show(ReferralCodeFormDialogId, {
|
|
1073
1299
|
type: "create" /* Create */,
|
|
1074
|
-
maxRebateRate,
|
|
1075
|
-
directBonusRebateRate:
|
|
1076
|
-
// Hardcoded value before API is ready
|
|
1300
|
+
maxRebateRate: maxRateOverride ?? maxRebateRate ?? 0,
|
|
1301
|
+
directBonusRebateRate: 0,
|
|
1077
1302
|
onSuccess: () => {
|
|
1078
1303
|
multiLevelRebateInfoMutate();
|
|
1079
1304
|
}
|
|
1080
1305
|
});
|
|
1081
1306
|
};
|
|
1307
|
+
const onCreateReferralCode = () => {
|
|
1308
|
+
if (!isTrader) {
|
|
1309
|
+
modal.show(BindReferralCodeDialogId, {
|
|
1310
|
+
onSuccess: async ({ skipped }) => {
|
|
1311
|
+
if (skipped) {
|
|
1312
|
+
showCreateReferralCodeModal();
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
const results = await Promise.allSettled([
|
|
1316
|
+
maxRebateRateMutate(),
|
|
1317
|
+
multiLevelRebateInfoMutate(),
|
|
1318
|
+
mutate()
|
|
1319
|
+
]);
|
|
1320
|
+
const latestMaxRebateRate = parseMaxRebateRateFromSettled(results[0]) ?? maxRebateRate;
|
|
1321
|
+
showCreateReferralCodeModal(latestMaxRebateRate);
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
showCreateReferralCodeModal();
|
|
1327
|
+
};
|
|
1082
1328
|
const description = useMemo(() => {
|
|
1083
1329
|
if (wrongNetwork) {
|
|
1084
1330
|
return t("affiliate.wrongNetwork.description");
|
|
@@ -1093,24 +1339,64 @@ var Hero = () => {
|
|
|
1093
1339
|
return "";
|
|
1094
1340
|
}
|
|
1095
1341
|
return t("affiliate.newReferralProgram.description");
|
|
1096
|
-
}, [t, wrongNetwork, status]);
|
|
1342
|
+
}, [t, wrongNetwork, status, isMultiLevelReferralUnlocked]);
|
|
1097
1343
|
const renderContent = () => {
|
|
1098
1344
|
if (!isMultiLevelReferralUnlocked) {
|
|
1099
|
-
return /* @__PURE__ */
|
|
1100
|
-
|
|
1345
|
+
return /* @__PURE__ */ jsxs(
|
|
1346
|
+
Flex,
|
|
1101
1347
|
{
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1348
|
+
direction: "column",
|
|
1349
|
+
itemAlign: "start",
|
|
1350
|
+
gap: 4,
|
|
1351
|
+
className: "oui-w-full",
|
|
1352
|
+
children: [
|
|
1353
|
+
/* @__PURE__ */ jsx(
|
|
1354
|
+
TradingVolumeProgress,
|
|
1355
|
+
{
|
|
1356
|
+
classNames: {
|
|
1357
|
+
root: "oui-items-start",
|
|
1358
|
+
description: "!oui-text-start"
|
|
1359
|
+
},
|
|
1360
|
+
buttonProps: {
|
|
1361
|
+
size: "xl"
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
),
|
|
1365
|
+
boundReferralCode ? /* @__PURE__ */ jsx(Text, { size: "sm", intensity: 54, className: "oui-leading-normal", children: t("affiliate.newReferralProgram.referredBy", {
|
|
1366
|
+
code: boundReferralCode
|
|
1367
|
+
}) }) : /* @__PURE__ */ jsx(
|
|
1368
|
+
"button",
|
|
1369
|
+
{
|
|
1370
|
+
type: "button",
|
|
1371
|
+
className: cn(
|
|
1372
|
+
"oui-cursor-pointer oui-border-none oui-bg-transparent oui-p-0",
|
|
1373
|
+
"oui-text-start oui-text-sm oui-font-normal oui-text-base-contrast-54 oui-underline oui-underline-offset-2",
|
|
1374
|
+
"oui-affiliate-landing-hero-bindReferralCode"
|
|
1375
|
+
),
|
|
1376
|
+
onClick: openBindReferralOnlyModal,
|
|
1377
|
+
children: t("affiliate.newReferralProgram.wereYouReferred")
|
|
1378
|
+
}
|
|
1379
|
+
)
|
|
1380
|
+
]
|
|
1109
1381
|
}
|
|
1110
1382
|
);
|
|
1111
1383
|
}
|
|
1112
1384
|
if (isMultiLevelEnabled && !multiLevelRebateInfo?.referral_code) {
|
|
1113
|
-
return /* @__PURE__ */
|
|
1385
|
+
return /* @__PURE__ */ jsxs(
|
|
1386
|
+
Flex,
|
|
1387
|
+
{
|
|
1388
|
+
direction: "column",
|
|
1389
|
+
itemAlign: "start",
|
|
1390
|
+
gap: 4,
|
|
1391
|
+
className: "oui-w-full",
|
|
1392
|
+
children: [
|
|
1393
|
+
/* @__PURE__ */ jsx(Button, { size: "lg", className: "oui-px-4", onClick: onCreateReferralCode, children: t("affiliate.referralCode.create") }),
|
|
1394
|
+
boundReferralCode ? /* @__PURE__ */ jsx(Text, { size: "sm", intensity: 54, className: "oui-leading-normal", children: t("affiliate.newReferralProgram.referredBy", {
|
|
1395
|
+
code: boundReferralCode
|
|
1396
|
+
}) }) : null
|
|
1397
|
+
]
|
|
1398
|
+
}
|
|
1399
|
+
);
|
|
1114
1400
|
}
|
|
1115
1401
|
return "";
|
|
1116
1402
|
};
|
|
@@ -1530,8 +1816,8 @@ var useMultiLevelReferralScript = () => {
|
|
|
1530
1816
|
modal.show(ReferralCodeFormDialogId, {
|
|
1531
1817
|
type: "create" /* Create */,
|
|
1532
1818
|
maxRebateRate,
|
|
1533
|
-
|
|
1534
|
-
|
|
1819
|
+
// because there is no multi level code, the /v1/referral/multi_level/rebate_info interface will throw an error, so here set to 0, and hide the extra bonus display when creating multi level code
|
|
1820
|
+
directBonusRebateRate: 0,
|
|
1535
1821
|
onSuccess: () => {
|
|
1536
1822
|
multiLevelRebateInfoMutate();
|
|
1537
1823
|
}
|
|
@@ -2976,6 +3262,7 @@ var Summary = (props) => {
|
|
|
2976
3262
|
value: statistics.total_rebate,
|
|
2977
3263
|
direct: statistics.direct_rebate + statistics.direct_bonus_rebate,
|
|
2978
3264
|
indirect: statistics.indirect_rebate,
|
|
3265
|
+
referredByCode: props.referredByCode,
|
|
2979
3266
|
classNames: {
|
|
2980
3267
|
root: "!oui-py-12",
|
|
2981
3268
|
value: "oui-text-trade-profit",
|
|
@@ -3039,7 +3326,7 @@ var SummaryItem = (props) => {
|
|
|
3039
3326
|
Text.numeral,
|
|
3040
3327
|
{
|
|
3041
3328
|
rule,
|
|
3042
|
-
dp
|
|
3329
|
+
dp,
|
|
3043
3330
|
size: "3xl",
|
|
3044
3331
|
prefix: props.prefix,
|
|
3045
3332
|
placeholder: "--",
|
|
@@ -3058,7 +3345,7 @@ var SummaryItem = (props) => {
|
|
|
3058
3345
|
Text.numeral,
|
|
3059
3346
|
{
|
|
3060
3347
|
rule,
|
|
3061
|
-
dp
|
|
3348
|
+
dp,
|
|
3062
3349
|
prefix: props.prefix,
|
|
3063
3350
|
intensity: 54,
|
|
3064
3351
|
className: props.classNames?.direct,
|
|
@@ -3076,7 +3363,7 @@ var SummaryItem = (props) => {
|
|
|
3076
3363
|
Text.numeral,
|
|
3077
3364
|
{
|
|
3078
3365
|
rule,
|
|
3079
|
-
dp
|
|
3366
|
+
dp,
|
|
3080
3367
|
prefix: props.prefix,
|
|
3081
3368
|
intensity: 54,
|
|
3082
3369
|
className: props.classNames?.indirect,
|
|
@@ -3084,15 +3371,28 @@ var SummaryItem = (props) => {
|
|
|
3084
3371
|
}
|
|
3085
3372
|
)
|
|
3086
3373
|
] })
|
|
3087
|
-
] })
|
|
3374
|
+
] }),
|
|
3375
|
+
props.referredByCode ? /* @__PURE__ */ jsx(
|
|
3376
|
+
Text,
|
|
3377
|
+
{
|
|
3378
|
+
intensity: 54,
|
|
3379
|
+
className: "oui-affiliate-summary-referred-by oui-mt-5 oui-text-base-contrast-54",
|
|
3380
|
+
children: t("affiliate.referredBy", { name: props.referredByCode })
|
|
3381
|
+
}
|
|
3382
|
+
) : null
|
|
3088
3383
|
]
|
|
3089
3384
|
}
|
|
3090
3385
|
);
|
|
3091
3386
|
};
|
|
3092
3387
|
var useSummaryScript = () => {
|
|
3093
3388
|
const { t } = useTranslation();
|
|
3389
|
+
const { referralInfo } = useReferralContext();
|
|
3094
3390
|
const [period, setPeriod] = useState("all_time" /* All */);
|
|
3095
3391
|
const { data } = useMultiLevelStatistics(period);
|
|
3392
|
+
const referredByCode = useMemo(() => {
|
|
3393
|
+
const code = referralInfo?.referee_info?.referer_code?.trim();
|
|
3394
|
+
return code || void 0;
|
|
3395
|
+
}, [referralInfo]);
|
|
3096
3396
|
const periodTypes = [
|
|
3097
3397
|
{ label: t("common.all"), value: "all_time" /* All */ },
|
|
3098
3398
|
{ label: t("common.select.1d"), value: "1d" /* 1d */ },
|
|
@@ -3134,7 +3434,8 @@ var useSummaryScript = () => {
|
|
|
3134
3434
|
period,
|
|
3135
3435
|
periodTypes,
|
|
3136
3436
|
onPeriodChange,
|
|
3137
|
-
statistics
|
|
3437
|
+
statistics,
|
|
3438
|
+
referredByCode
|
|
3138
3439
|
};
|
|
3139
3440
|
};
|
|
3140
3441
|
var SummaryWidget = () => {
|