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