@loafmarkets/ui 0.1.381 → 0.1.382

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.mjs CHANGED
@@ -6601,6 +6601,9 @@ PropertySubheader.displayName = "PropertySubheader";
6601
6601
  var DEFAULT_LOGO_SRC = Loaf_logo_Banner_default;
6602
6602
  var DEFAULT_LOGO_ALT = "Loaf";
6603
6603
  var OTP_INPUT_LENGTH = 6;
6604
+ var CODE_PREFIX = "LOAF-";
6605
+ var CODE_SUFFIX_LEN = 5;
6606
+ var normalizeAccessCode = (raw) => CODE_PREFIX + raw.toUpperCase().replace(/^LOAF-?/, "").replace(/[^A-Z0-9]/g, "").slice(0, CODE_SUFFIX_LEN);
6604
6607
  var friendlyError = (err, fallback) => {
6605
6608
  const data = err?.response?.data;
6606
6609
  if (typeof data?.error === "string" && data.error.trim()) return data.error;
@@ -6627,6 +6630,7 @@ var LoginPopup = ({
6627
6630
  renderKycWidget,
6628
6631
  onFundWallet,
6629
6632
  initialView,
6633
+ initialCode,
6630
6634
  kycStatus: kycStatusProp,
6631
6635
  walletAddress,
6632
6636
  onSubmitReferralCode,
@@ -6640,7 +6644,9 @@ var LoginPopup = ({
6640
6644
  const [otp, setOtp] = useState(Array(OTP_INPUT_LENGTH).fill(""));
6641
6645
  const [error, setError] = useState("");
6642
6646
  const [copied, setCopied] = useState(false);
6643
- const [referralCode, setReferralCode] = useState("");
6647
+ const [referralCode, setReferralCode] = useState(
6648
+ () => gate && initialCode ? normalizeAccessCode(initialCode) : ""
6649
+ );
6644
6650
  const [referralLoading, setReferralLoading] = useState(false);
6645
6651
  const [referralError, setReferralError] = useState("");
6646
6652
  const [codeStatus, setCodeStatus] = useState("idle");
@@ -6685,6 +6691,37 @@ var LoginPopup = ({
6685
6691
  );
6686
6692
  return false;
6687
6693
  }, [gate, onSubmitReferralCode, onCheckAccess]);
6694
+ const runCodeValidation = React5__default.useCallback(async (fullCode) => {
6695
+ setCodeStatus("checking");
6696
+ setError("");
6697
+ try {
6698
+ const ok = onValidateCode ? await onValidateCode(fullCode) : true;
6699
+ if (!ok) {
6700
+ validatedCodeRef.current = null;
6701
+ setCodeStatus("invalid");
6702
+ return;
6703
+ }
6704
+ validatedCodeRef.current = fullCode;
6705
+ setCodeStatus("valid");
6706
+ if (isAuthenticated) {
6707
+ if (await finishGate()) setTimeout(() => onClose(), 500);
6708
+ return;
6709
+ }
6710
+ setIsSignUp(true);
6711
+ setSignInRevealed(true);
6712
+ } catch {
6713
+ validatedCodeRef.current = null;
6714
+ setCodeStatus("invalid");
6715
+ }
6716
+ }, [onValidateCode, isAuthenticated, finishGate, onClose]);
6717
+ const autoCodeTriedRef = React5__default.useRef(false);
6718
+ useEffect(() => {
6719
+ if (autoCodeTriedRef.current || !gate || !initialCode) return;
6720
+ const full = normalizeAccessCode(initialCode);
6721
+ if (full.length !== CODE_PREFIX.length + CODE_SUFFIX_LEN) return;
6722
+ autoCodeTriedRef.current = true;
6723
+ void runCodeValidation(full);
6724
+ }, [gate, initialCode, runCodeValidation]);
6688
6725
  useEffect(() => {
6689
6726
  if (typeof initialView === "string") {
6690
6727
  setView(initialView);
@@ -7453,31 +7490,7 @@ var LoginPopup = ({
7453
7490
  setReferralLoading(false);
7454
7491
  }
7455
7492
  };
7456
- const CODE_PREFIX = "LOAF-";
7457
7493
  const codeSuffix = referralCode.startsWith(CODE_PREFIX) ? referralCode.slice(CODE_PREFIX.length) : referralCode.replace(/^LOAF-?/i, "");
7458
- const runCodeValidation = async (fullCode) => {
7459
- setCodeStatus("checking");
7460
- setError("");
7461
- try {
7462
- const ok = onValidateCode ? await onValidateCode(fullCode) : true;
7463
- if (!ok) {
7464
- validatedCodeRef.current = null;
7465
- setCodeStatus("invalid");
7466
- return;
7467
- }
7468
- validatedCodeRef.current = fullCode;
7469
- setCodeStatus("valid");
7470
- if (isAuthenticated) {
7471
- if (await finishGate()) setTimeout(() => onClose(), 500);
7472
- return;
7473
- }
7474
- setIsSignUp(true);
7475
- setSignInRevealed(true);
7476
- } catch {
7477
- validatedCodeRef.current = null;
7478
- setCodeStatus("invalid");
7479
- }
7480
- };
7481
7494
  const setCodeSuffix = (suffix) => {
7482
7495
  setReferralCode(CODE_PREFIX + suffix);
7483
7496
  setReferralError("");