@thenamespace/ens-components 0.12.0 → 0.14.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
@@ -13335,6 +13335,7 @@ function RegistrationStep({
13335
13335
  onDurationChange,
13336
13336
  onUseAsPrimaryChange,
13337
13337
  onCompleteProfile,
13338
+ onRecordsChange,
13338
13339
  mintPrice = 0,
13339
13340
  isFetchingPrice = false,
13340
13341
  expiryYears = 1,
@@ -13346,10 +13347,58 @@ function RegistrationStep({
13346
13347
  const [ownerAddress, setOwnerAddress] = useState(owner);
13347
13348
  const [isOwnerExpanded, setIsOwnerExpanded] = useState(true);
13348
13349
  const [isDurationExpanded, setIsDurationExpanded] = useState(false);
13350
+ const [isModalOpen, setIsModalOpen] = useState(false);
13351
+ const [records, setRecords] = useState({
13352
+ addresses: [],
13353
+ texts: []
13354
+ });
13355
+ const [initialRecords, setInitialRecords] = useState({
13356
+ addresses: [],
13357
+ texts: []
13358
+ });
13349
13359
  const costBreakdownRef = useRef(null);
13360
+ const eth_address = getSupportedAddressByName("eth");
13361
+ const celo_address = getSupportedAddressByName("celo");
13350
13362
  useEffect(() => {
13351
13363
  setOwnerAddress(owner);
13352
13364
  }, [owner]);
13365
+ useEffect(() => {
13366
+ if (ownerAddress && ownerAddress.length > 0 && records.addresses.length === 0) {
13367
+ const newAddresses = [];
13368
+ if (eth_address) {
13369
+ newAddresses.push({ coinType: eth_address.coinType, value: ownerAddress });
13370
+ }
13371
+ if (celo_address) {
13372
+ newAddresses.push({ coinType: celo_address.coinType, value: ownerAddress });
13373
+ }
13374
+ if (newAddresses.length > 0) {
13375
+ setRecords((prevRecords) => ({
13376
+ ...prevRecords,
13377
+ addresses: newAddresses
13378
+ }));
13379
+ }
13380
+ }
13381
+ }, [ownerAddress]);
13382
+ const recordsToAdd = useMemo(() => {
13383
+ let count = 0;
13384
+ records.texts.forEach((text) => {
13385
+ if (text.value.length > 0) {
13386
+ count++;
13387
+ }
13388
+ });
13389
+ records.addresses.forEach((addr) => {
13390
+ const supportedAddr = getSupportedAddressByCoin(addr.coinType);
13391
+ if (supportedAddr) {
13392
+ if (addr.value.length > 0 && supportedAddr.validateFunc?.(addr.value)) {
13393
+ count++;
13394
+ }
13395
+ }
13396
+ });
13397
+ if (records.contenthash && records.contenthash.value.length > 0) {
13398
+ count++;
13399
+ }
13400
+ return count;
13401
+ }, [records]);
13353
13402
  useEffect(() => {
13354
13403
  if (isDurationExpanded && costBreakdownRef.current) {
13355
13404
  setTimeout(() => {
@@ -13381,6 +13430,20 @@ function RegistrationStep({
13381
13430
  setOwnerAddress(value);
13382
13431
  onOwnerChange?.(value);
13383
13432
  };
13433
+ const handleAddProfile = () => {
13434
+ setIsModalOpen(true);
13435
+ };
13436
+ const handleRecordsAdded = () => {
13437
+ const _initialRecords = deepCopy$2(records);
13438
+ setInitialRecords(_initialRecords);
13439
+ onRecordsChange?.(records);
13440
+ setIsModalOpen(false);
13441
+ onCompleteProfile?.();
13442
+ };
13443
+ const handleRecordsCancel = () => {
13444
+ setRecords(deepCopy$2(initialRecords));
13445
+ setIsModalOpen(false);
13446
+ };
13384
13447
  const fullName = name.includes(".") ? name : `${name}.${domainSuffix}`;
13385
13448
  return /* @__PURE__ */ jsxs("div", { className: "ns-onchain-register-card", children: [
13386
13449
  onClose && /* @__PURE__ */ jsx("button", { className: "ns-onchain-register-close-btn", onClick: onClose, children: /* @__PURE__ */ jsx(Icon, { name: "x", size: 20 }) }),
@@ -13492,7 +13555,7 @@ function RegistrationStep({
13492
13555
  "div",
13493
13556
  {
13494
13557
  className: "ns-onchain-register-profile-card",
13495
- onClick: onCompleteProfile,
13558
+ onClick: handleAddProfile,
13496
13559
  children: [
13497
13560
  /* @__PURE__ */ jsx("div", { className: "ns-onchain-register-profile-icon", children: /* @__PURE__ */ jsx("img", { src: img$2, alt: "Profile Icon" }) }),
13498
13561
  /* @__PURE__ */ jsxs("div", { className: "ns-onchain-register-profile-text", children: [
@@ -13539,7 +13602,65 @@ function RegistrationStep({
13539
13602
  children: "Register"
13540
13603
  }
13541
13604
  )
13542
- ] })
13605
+ ] }),
13606
+ /* @__PURE__ */ jsx(
13607
+ Modal,
13608
+ {
13609
+ isOpen: isModalOpen,
13610
+ onClose: () => setIsModalOpen(false),
13611
+ size: "md",
13612
+ footer: null,
13613
+ isDismissDisabled: true,
13614
+ style: { maxWidth: "500px" },
13615
+ children: /* @__PURE__ */ jsxs("div", { style: { margin: "-20px", padding: 0 }, children: [
13616
+ /* @__PURE__ */ jsx(
13617
+ SelectRecordsForm,
13618
+ {
13619
+ records,
13620
+ onRecordsUpdated: (updatedRecords) => {
13621
+ setRecords(updatedRecords);
13622
+ }
13623
+ }
13624
+ ),
13625
+ /* @__PURE__ */ jsxs(
13626
+ "div",
13627
+ {
13628
+ style: {
13629
+ background: "#f4f4f4",
13630
+ gap: "7px",
13631
+ display: "flex",
13632
+ padding: "4px"
13633
+ },
13634
+ children: [
13635
+ /* @__PURE__ */ jsx(
13636
+ Button,
13637
+ {
13638
+ onClick: handleRecordsCancel,
13639
+ variant: "outline",
13640
+ style: { width: "50%" },
13641
+ size: "lg",
13642
+ children: "Cancel"
13643
+ }
13644
+ ),
13645
+ /* @__PURE__ */ jsxs(
13646
+ Button,
13647
+ {
13648
+ onClick: handleRecordsAdded,
13649
+ size: "lg",
13650
+ style: { width: "50%" },
13651
+ children: [
13652
+ "Add (",
13653
+ recordsToAdd,
13654
+ ")"
13655
+ ]
13656
+ }
13657
+ )
13658
+ ]
13659
+ }
13660
+ )
13661
+ ] })
13662
+ }
13663
+ )
13543
13664
  ] });
13544
13665
  }
13545
13666
 
@@ -126619,93 +126740,218 @@ function RegistrationForm({
126619
126740
  onClose,
126620
126741
  onNext,
126621
126742
  onCompleteProfile,
126743
+ onRecordsChange,
126622
126744
  isLoadingPrice = false,
126623
126745
  priceError = null,
126624
126746
  nameAvailability = { isAvailable: false, isChecking: false },
126625
126747
  canProceed = false
126626
126748
  }) {
126627
126749
  const [isDurationExpanded, setIsDurationExpanded] = useState(false);
126628
- return /* @__PURE__ */ jsx("div", { className: "ens-names-register-container", children: /* @__PURE__ */ jsxs("div", { className: "ens-names-register-card", children: [
126629
- /* @__PURE__ */ jsx(Header, { showBack: true, onBack, onClose }),
126630
- /* @__PURE__ */ jsxs("div", { className: "ens-names-register-title-section", children: [
126631
- /* @__PURE__ */ jsx(Text$1, { size: "xl", weight: "light", className: "ens-names-register-title", children: "ENS Registration" }),
126632
- /* @__PURE__ */ jsx(Text$1, { size: "md", color: "grey", className: "ens-names-register-subtitle", children: "Your about to mint this ENS name" })
126633
- ] }),
126634
- ensName && /* @__PURE__ */ jsx("div", { className: "ens-names-register-name-display", children: /* @__PURE__ */ jsxs(Text$1, { size: "xl", weight: "bold", children: [
126635
- ensName,
126636
- ".eth"
126637
- ] }) }),
126638
- /* @__PURE__ */ jsxs("div", { className: "ens-names-register-duration-section", children: [
126639
- /* @__PURE__ */ jsxs("div", { className: "ens-names-register-duration-controls", children: [
126640
- /* @__PURE__ */ jsx(
126641
- "button",
126642
- {
126643
- className: "ens-names-register-duration-btn",
126644
- onClick: () => onDurationChange(-1),
126645
- disabled: duration <= 1,
126646
- children: /* @__PURE__ */ jsx("span", { style: { fontSize: "20px", lineHeight: "1" }, children: "\u2212" })
126647
- }
126648
- ),
126649
- /* @__PURE__ */ jsx(
126650
- "div",
126651
- {
126652
- className: "ens-names-register-duration-text",
126653
- onClick: () => setIsDurationExpanded(!isDurationExpanded),
126654
- children: /* @__PURE__ */ jsxs(Text$1, { size: "md", weight: "medium", children: [
126655
- duration,
126656
- " year",
126657
- duration !== 1 ? "s" : ""
126658
- ] })
126659
- }
126660
- ),
126661
- /* @__PURE__ */ jsx(
126662
- "button",
126750
+ const [isModalOpen, setIsModalOpen] = useState(false);
126751
+ const [records, setRecords] = useState({
126752
+ addresses: [],
126753
+ texts: []
126754
+ });
126755
+ const [initialRecords, setInitialRecords] = useState({
126756
+ addresses: [],
126757
+ texts: []
126758
+ });
126759
+ const { connectedAddress } = useConnectedPrincipal();
126760
+ const eth_address = getSupportedAddressByName("eth");
126761
+ const celo_address = getSupportedAddressByName("celo");
126762
+ useEffect(() => {
126763
+ if (connectedAddress && records.addresses.length === 0) {
126764
+ const newAddresses = [];
126765
+ if (eth_address) {
126766
+ newAddresses.push({ coinType: eth_address.coinType, value: connectedAddress });
126767
+ }
126768
+ if (celo_address) {
126769
+ newAddresses.push({ coinType: celo_address.coinType, value: connectedAddress });
126770
+ }
126771
+ if (newAddresses.length > 0) {
126772
+ setRecords((prevRecords) => ({
126773
+ ...prevRecords,
126774
+ addresses: newAddresses
126775
+ }));
126776
+ }
126777
+ }
126778
+ }, [connectedAddress]);
126779
+ const recordsToAdd = useMemo(() => {
126780
+ let count = 0;
126781
+ records.texts.forEach((text) => {
126782
+ if (text.value.length > 0) {
126783
+ count++;
126784
+ }
126785
+ });
126786
+ records.addresses.forEach((addr) => {
126787
+ const supportedAddr = getSupportedAddressByCoin(addr.coinType);
126788
+ if (supportedAddr) {
126789
+ if (addr.value.length > 0 && supportedAddr.validateFunc?.(addr.value)) {
126790
+ count++;
126791
+ }
126792
+ }
126793
+ });
126794
+ if (records.contenthash && records.contenthash.value.length > 0) {
126795
+ count++;
126796
+ }
126797
+ return count;
126798
+ }, [records]);
126799
+ const handleAddProfile = () => {
126800
+ setIsModalOpen(true);
126801
+ };
126802
+ const handleRecordsAdded = () => {
126803
+ const _initialRecords = deepCopy$2(records);
126804
+ setInitialRecords(_initialRecords);
126805
+ onRecordsChange?.(records);
126806
+ setIsModalOpen(false);
126807
+ onCompleteProfile?.();
126808
+ };
126809
+ const handleRecordsCancel = () => {
126810
+ setRecords(deepCopy$2(initialRecords));
126811
+ setIsModalOpen(false);
126812
+ };
126813
+ return /* @__PURE__ */ jsxs("div", { className: "ens-names-register-container", children: [
126814
+ /* @__PURE__ */ jsxs("div", { className: "ens-names-register-card", children: [
126815
+ /* @__PURE__ */ jsx(Header, { showBack: true, onBack, onClose }),
126816
+ /* @__PURE__ */ jsxs("div", { className: "ens-names-register-title-section", children: [
126817
+ /* @__PURE__ */ jsx(Text$1, { size: "xl", weight: "light", className: "ens-names-register-title", children: "ENS Registration" }),
126818
+ /* @__PURE__ */ jsx(Text$1, { size: "md", color: "grey", className: "ens-names-register-subtitle", children: "Your about to mint this ENS name" })
126819
+ ] }),
126820
+ ensName && /* @__PURE__ */ jsx("div", { className: "ens-names-register-name-display", children: /* @__PURE__ */ jsxs(Text$1, { size: "xl", weight: "bold", children: [
126821
+ ensName,
126822
+ ".eth"
126823
+ ] }) }),
126824
+ /* @__PURE__ */ jsxs("div", { className: "ens-names-register-duration-section", children: [
126825
+ /* @__PURE__ */ jsxs("div", { className: "ens-names-register-duration-controls", children: [
126826
+ /* @__PURE__ */ jsx(
126827
+ "button",
126828
+ {
126829
+ className: "ens-names-register-duration-btn",
126830
+ onClick: () => onDurationChange(-1),
126831
+ disabled: duration <= 1,
126832
+ children: /* @__PURE__ */ jsx("span", { style: { fontSize: "20px", lineHeight: "1" }, children: "\u2212" })
126833
+ }
126834
+ ),
126835
+ /* @__PURE__ */ jsx(
126836
+ "div",
126837
+ {
126838
+ className: "ens-names-register-duration-text",
126839
+ onClick: () => setIsDurationExpanded(!isDurationExpanded),
126840
+ children: /* @__PURE__ */ jsxs(Text$1, { size: "md", weight: "medium", children: [
126841
+ duration,
126842
+ " year",
126843
+ duration !== 1 ? "s" : ""
126844
+ ] })
126845
+ }
126846
+ ),
126847
+ /* @__PURE__ */ jsx(
126848
+ "button",
126849
+ {
126850
+ className: "ens-names-register-duration-btn",
126851
+ onClick: () => onDurationChange(1),
126852
+ children: /* @__PURE__ */ jsx("span", { style: { fontSize: "20px", lineHeight: "1" }, children: "+" })
126853
+ }
126854
+ )
126855
+ ] }),
126856
+ isDurationExpanded && /* @__PURE__ */ jsx("div", { className: "ens-names-register-cost-breakdown", children: /* @__PURE__ */ jsx(
126857
+ CostSummary,
126663
126858
  {
126664
- className: "ens-names-register-duration-btn",
126665
- onClick: () => onDurationChange(1),
126666
- children: /* @__PURE__ */ jsx("span", { style: { fontSize: "20px", lineHeight: "1" }, children: "+" })
126859
+ duration,
126860
+ registrationCost,
126861
+ networkFee,
126862
+ total,
126863
+ isLoading: isLoadingPrice,
126864
+ priceError
126667
126865
  }
126668
- )
126866
+ ) })
126669
126867
  ] }),
126670
- isDurationExpanded && /* @__PURE__ */ jsx("div", { className: "ens-names-register-cost-breakdown", children: /* @__PURE__ */ jsx(
126671
- CostSummary,
126868
+ /* @__PURE__ */ jsxs(
126869
+ "div",
126672
126870
  {
126673
- duration,
126674
- registrationCost,
126675
- networkFee,
126676
- total,
126677
- isLoading: isLoadingPrice,
126678
- priceError
126871
+ className: "ens-names-register-profile-card",
126872
+ onClick: handleAddProfile,
126873
+ children: [
126874
+ /* @__PURE__ */ jsx("div", { className: "ens-names-register-profile-icon", children: /* @__PURE__ */ jsx("img", { src: img$2, alt: "Profile Icon" }) }),
126875
+ /* @__PURE__ */ jsxs("div", { className: "ens-names-register-profile-text", children: [
126876
+ /* @__PURE__ */ jsx(Text$1, { size: "md", weight: "bold", children: "Complete your profile" }),
126877
+ /* @__PURE__ */ jsx(Text$1, { size: "sm", color: "grey", children: "Make your ENS more discoverable" })
126878
+ ] }),
126879
+ /* @__PURE__ */ jsx("button", { className: "ens-names-register-profile-arrow", children: /* @__PURE__ */ jsx(ChevronRight, { size: 20 }) })
126880
+ ]
126679
126881
  }
126680
- ) })
126882
+ ),
126883
+ /* @__PURE__ */ jsx(
126884
+ Button,
126885
+ {
126886
+ className: "ens-names-register-next-btn",
126887
+ variant: "solid",
126888
+ size: "lg",
126889
+ onClick: onNext,
126890
+ disabled: !canProceed,
126891
+ children: "Next"
126892
+ }
126893
+ )
126681
126894
  ] }),
126682
- /* @__PURE__ */ jsxs(
126683
- "div",
126684
- {
126685
- className: "ens-names-register-profile-card",
126686
- onClick: onCompleteProfile,
126687
- children: [
126688
- /* @__PURE__ */ jsx("div", { className: "ens-names-register-profile-icon", children: /* @__PURE__ */ jsx("img", { src: img$2, alt: "Profile Icon" }) }),
126689
- /* @__PURE__ */ jsxs("div", { className: "ens-names-register-profile-text", children: [
126690
- /* @__PURE__ */ jsx(Text$1, { size: "md", weight: "bold", children: "Complete your profile" }),
126691
- /* @__PURE__ */ jsx(Text$1, { size: "sm", color: "grey", children: "Make your ENS more discoverable" })
126692
- ] }),
126693
- /* @__PURE__ */ jsx("button", { className: "ens-names-register-profile-arrow", children: /* @__PURE__ */ jsx(ChevronRight, { size: 20 }) })
126694
- ]
126695
- }
126696
- ),
126697
126895
  /* @__PURE__ */ jsx(
126698
- Button,
126896
+ Modal,
126699
126897
  {
126700
- className: "ens-names-register-next-btn",
126701
- variant: "solid",
126702
- size: "lg",
126703
- onClick: onNext,
126704
- disabled: !canProceed,
126705
- children: "Next"
126898
+ isOpen: isModalOpen,
126899
+ onClose: () => setIsModalOpen(false),
126900
+ size: "md",
126901
+ footer: null,
126902
+ isDismissDisabled: true,
126903
+ style: { maxWidth: "500px" },
126904
+ children: /* @__PURE__ */ jsxs("div", { style: { margin: "-20px" }, children: [
126905
+ /* @__PURE__ */ jsx(
126906
+ SelectRecordsForm,
126907
+ {
126908
+ records,
126909
+ onRecordsUpdated: (updatedRecords) => {
126910
+ setRecords(updatedRecords);
126911
+ }
126912
+ }
126913
+ ),
126914
+ /* @__PURE__ */ jsxs(
126915
+ "div",
126916
+ {
126917
+ style: {
126918
+ background: "#f4f4f4",
126919
+ gap: "7px",
126920
+ display: "flex",
126921
+ padding: "8px",
126922
+ paddingTop: "0"
126923
+ },
126924
+ children: [
126925
+ /* @__PURE__ */ jsx(
126926
+ Button,
126927
+ {
126928
+ onClick: handleRecordsCancel,
126929
+ variant: "outline",
126930
+ style: { width: "50%" },
126931
+ size: "lg",
126932
+ children: "Cancel"
126933
+ }
126934
+ ),
126935
+ /* @__PURE__ */ jsxs(
126936
+ Button,
126937
+ {
126938
+ onClick: handleRecordsAdded,
126939
+ size: "lg",
126940
+ style: { width: "50%" },
126941
+ children: [
126942
+ "Add (",
126943
+ recordsToAdd,
126944
+ ")"
126945
+ ]
126946
+ }
126947
+ )
126948
+ ]
126949
+ }
126950
+ )
126951
+ ] })
126706
126952
  }
126707
126953
  )
126708
- ] }) });
126954
+ ] });
126709
126955
  }
126710
126956
 
126711
126957
  function StepItem({
@@ -127566,7 +127812,6 @@ function ENSNamesRegistrarComponent({
127566
127812
  }
127567
127813
  }, []);
127568
127814
  const handleNameSearchNext = () => {
127569
- console.log("[ENS Registration] handleNameSearchNext called - Moving to RegistrationBegin");
127570
127815
  if (ensName && ensName.length >= 3 && duration > 0) {
127571
127816
  const normalizedName = normalise(ensName.trim());
127572
127817
  if (normalizedName !== lastFetchedName || duration !== lastFetchedDuration) {
@@ -127644,6 +127889,13 @@ function ENSNamesRegistrarComponent({
127644
127889
  }
127645
127890
  if (currentStep === EnsRegistrationSteps.RegistrationBegin) {
127646
127891
  const canProceed = nameAvailability.isAvailable && !nameAvailability.isChecking && ensName.length >= 3;
127892
+ const normalizedName = normalise(ensName.trim());
127893
+ const handleRecordsChange = (records) => {
127894
+ setRecordsPerName({
127895
+ ...recordsPerName,
127896
+ [normalizedName]: records
127897
+ });
127898
+ };
127647
127899
  return /* @__PURE__ */ jsx(
127648
127900
  RegistrationForm,
127649
127901
  {
@@ -127658,6 +127910,7 @@ function ENSNamesRegistrarComponent({
127658
127910
  onClose,
127659
127911
  onNext: handleNext,
127660
127912
  onCompleteProfile,
127913
+ onRecordsChange: handleRecordsChange,
127661
127914
  isLoadingPrice,
127662
127915
  priceError,
127663
127916
  nameAvailability,