@thenamespace/ens-components 0.13.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