@thenamespace/ens-components 1.3.0 → 1.3.1
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.ts +11 -1
- package/dist/index.js +191 -31
- package/dist/index.js.map +1 -1
- package/dist/types/components/ens-name-registration/RegistrationSummary.d.ts +2 -0
- package/dist/types/components/ens-name-registration/registration/types.d.ts +1 -0
- package/dist/types/hooks/useRegisterENS.d.ts +10 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -628,6 +628,15 @@ interface RentPriceResponse {
|
|
|
628
628
|
wei: bigint;
|
|
629
629
|
eth: number;
|
|
630
630
|
}
|
|
631
|
+
interface RegistrationFeeEstimate {
|
|
632
|
+
wei: bigint;
|
|
633
|
+
eth: number;
|
|
634
|
+
gasEstimate: bigint;
|
|
635
|
+
gasPrice: bigint;
|
|
636
|
+
/** True when the precise eth_estimateGas+stateOverride path failed and we
|
|
637
|
+
* fell back to a heuristic. UI can mark the value as approximate. */
|
|
638
|
+
isHeuristic: boolean;
|
|
639
|
+
}
|
|
631
640
|
interface RegistrationRequest {
|
|
632
641
|
label: string;
|
|
633
642
|
owner: Address;
|
|
@@ -641,6 +650,7 @@ declare const useRegisterENS: ({ isTestnet }: {
|
|
|
641
650
|
}) => {
|
|
642
651
|
isEnsAvailable: (label: string) => Promise<boolean>;
|
|
643
652
|
getRegistrationPrice: (label: string, durationInSeconds?: number) => Promise<RentPriceResponse>;
|
|
653
|
+
estimateRegistrationFees: (request: RegistrationRequest) => Promise<RegistrationFeeEstimate>;
|
|
644
654
|
sendCommitmentTx: (request: RegistrationRequest) => Promise<Hash>;
|
|
645
655
|
sendRegisterTx: (request: RegistrationRequest) => Promise<{
|
|
646
656
|
txHash: Hash;
|
|
@@ -880,4 +890,4 @@ declare const useAvatarClient: ({ isTestnet, domain }: UseAvatarClientParams) =>
|
|
|
880
890
|
};
|
|
881
891
|
|
|
882
892
|
export { Accordion, Alert, Button, Card, ChainIcon, ConnectAndSetChain, ContenthashIcon, ContenthashProtocol, ContractErrorLabel, Dropdown, DurationPicker, ENS_RESOLVER_ABI, EnsNameRegistrationForm, EnsRecordsForm, Icon, Input, ListingNetwork, ListingType, MIN_REGISTRATION_SECONDS, MULTICALL, Modal, ONE_DAY, ONE_YEAR, OffchainSubnameForm, PricingDisplay, ProfileHeader, ProgressBar, SET_ADDRESS_FUNC, SET_CONTENTHASH_FUNC, SET_TEXT_FUNC, SelectRecordsForm, ShurikenSpinner, SubnameMintForm, Text, TextRecordCategory, Textarea, ThemeProvider, Tooltip, TransactionPendingScreen, TxProgress, capitalize, convertEVMChainIdToCoinType, convertToMulticallResolverData, convertToResolverData, createEnsReferer, debounce, deepCopy, diffToEnsRecords, ensureFloatInput, equalsIgnoreCase, formatDurationSummary, formatFloat, getAvatarUploadErrorMessage, getBlockExplorer, getBlockExplorerAddressUrl, getBlockExplorerName, getBlockExplorerTransactionUrl, getChainIdForListingNetwork, getEnsAppUrl, getEnsRecordsDiff, getImageUploadErrorMessage, getSupportedAddressByChainId, getSupportedAddressByCoin, getSupportedAddressByName, getSupportedAddressMap, getSupportedChashByProtocol, getSupportedText, isCommitmentToNewErr, isContenthashValid, isUserDeniedError, roundDurationWithDay, secondsFromYears, secondsToDateInput, supportedAddresses, supportedContenthashRecords, supportedTexts, useAvatarClient, useENSResolver, useEthDollarValue, useMintManager, useMintSubname, useOffchainManager, useRegisterENS, useTheme, useWaitTransaction, validateEnsRecords, wait, yearsFromSeconds };
|
|
883
|
-
export type { AccordionProps, AlertPosition, AlertProps, AlertVariant, ButtonProps, ButtonSize, ButtonVariant, ChainName$1 as ChainName, ConnectAndSetChainProps, ContractErrorLabelProps, DropdownProps, DurationPickerProps, EnsAddressRecord$1 as EnsAddressRecord, EnsContenthashRecord, EnsRecords$1 as EnsRecords, EnsRecordsDiff, EnsTextRecord$1 as EnsTextRecord, EstimatedFees, IconName, IconProps, InputProps, InputSize, InputType, ModalPresentation, ModalProps, ModalResponsivePresentation, ModalSize, NameListing, OffchainSubnameCreatedData, PricingDisplayProps, ProfileHeaderProps, RecordValidationError, RegistrationRequest, ShurikenSpinnerProps, SupportedContenthashRecord, SupportedEnsAddress, SupportedText, SupportedTextRecord, TextCategory, TextColor, TextProps, TextSize, TextWeight, TextareaProps, TextareaSize, ThemeContextValue, ThemeName, ThemeProviderProps, TooltipPosition, TooltipProps, UploadAvatarParams, UploadImageType };
|
|
893
|
+
export type { AccordionProps, AlertPosition, AlertProps, AlertVariant, ButtonProps, ButtonSize, ButtonVariant, ChainName$1 as ChainName, ConnectAndSetChainProps, ContractErrorLabelProps, DropdownProps, DurationPickerProps, EnsAddressRecord$1 as EnsAddressRecord, EnsContenthashRecord, EnsRecords$1 as EnsRecords, EnsRecordsDiff, EnsTextRecord$1 as EnsTextRecord, EstimatedFees, IconName, IconProps, InputProps, InputSize, InputType, ModalPresentation, ModalProps, ModalResponsivePresentation, ModalSize, NameListing, OffchainSubnameCreatedData, PricingDisplayProps, ProfileHeaderProps, RecordValidationError, RegistrationFeeEstimate, RegistrationRequest, ShurikenSpinnerProps, SupportedContenthashRecord, SupportedEnsAddress, SupportedText, SupportedTextRecord, TextCategory, TextColor, TextProps, TextSize, TextWeight, TextareaProps, TextareaSize, ThemeContextValue, ThemeName, ThemeProviderProps, TooltipPosition, TooltipProps, UploadAvatarParams, UploadImageType };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as zlib from 'zlib';
|
|
|
4
4
|
import * as crypto$5 from 'crypto';
|
|
5
5
|
import * as net from 'net';
|
|
6
6
|
import * as viem from 'viem';
|
|
7
|
-
import { ContractFunctionExecutionError, parseAbi, namehash as namehash$1, encodeFunctionData, toHex, toBytes as toBytes$1, pad, isAddress as isAddress$1, keccak256, formatEther, zeroAddress, zeroHash } from 'viem';
|
|
7
|
+
import { ContractFunctionExecutionError, parseAbi, namehash as namehash$1, encodeFunctionData, toHex, toBytes as toBytes$1, pad, isAddress as isAddress$1, keccak256, parseEther, padHex, formatEther, zeroAddress, concatHex, zeroHash } from 'viem';
|
|
8
8
|
import * as chains$1 from 'viem/chains';
|
|
9
9
|
import { baseSepolia, sepolia, mainnet, optimism, base as base$3, zoraSepolia, zora, celoAlfajores, celo, polygonMumbai, polygon, arbitrumSepolia, arbitrum, optimismSepolia } from 'viem/chains';
|
|
10
10
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
@@ -12030,7 +12030,7 @@ const PricingDisplay = ({
|
|
|
12030
12030
|
if (!ethUsdRate || totalLoading || total.amount === "Free" || total.amount === "N/A") {
|
|
12031
12031
|
return null;
|
|
12032
12032
|
}
|
|
12033
|
-
const eth = parseFloat(String(total.amount));
|
|
12033
|
+
const eth = parseFloat(String(total.amount).replace(/^~/, ""));
|
|
12034
12034
|
if (isNaN(eth) || eth <= 0) return null;
|
|
12035
12035
|
return (eth * ethUsdRate).toFixed(2);
|
|
12036
12036
|
}, [ethUsdRate, total.amount, totalLoading]);
|
|
@@ -12045,19 +12045,16 @@ const PricingDisplay = ({
|
|
|
12045
12045
|
) }),
|
|
12046
12046
|
/* @__PURE__ */ jsxs("div", { className: "d-flex justify-content-between align-items-center mb-1", children: [
|
|
12047
12047
|
/* @__PURE__ */ jsx(Text, { size: "sm", color: "grey", children: primaryFee.label }),
|
|
12048
|
-
primaryFee.isChecking ? /* @__PURE__ */ jsx(ShurikenSpinner, { size: 16 }) : /* @__PURE__ */ jsx(Text, { size: "sm", color: "grey", children: primaryFee.amount === "Free"
|
|
12048
|
+
primaryFee.isChecking ? /* @__PURE__ */ jsx(ShurikenSpinner, { size: 16 }) : /* @__PURE__ */ jsx(Text, { size: "sm", color: "grey", children: primaryFee.amount === "Free" || primaryFee.amount === "N/A" ? primaryFee.amount : `${primaryFee.amount} ETH` })
|
|
12049
12049
|
] }),
|
|
12050
12050
|
networkFees && /* @__PURE__ */ jsxs("div", { className: "d-flex justify-content-between align-items-center mb-1", children: [
|
|
12051
12051
|
/* @__PURE__ */ jsx(Text, { size: "sm", color: "grey", children: "Est. network fees" }),
|
|
12052
|
-
networkFees.isChecking ? /* @__PURE__ */ jsx(ShurikenSpinner, { size: 16 }) : /* @__PURE__ */
|
|
12053
|
-
networkFees.amount,
|
|
12054
|
-
" ETH"
|
|
12055
|
-
] })
|
|
12052
|
+
networkFees.isChecking ? /* @__PURE__ */ jsx(ShurikenSpinner, { size: 16 }) : /* @__PURE__ */ jsx(Text, { size: "sm", color: "grey", children: networkFees.amount === "N/A" ? "N/A" : `${networkFees.amount} ETH` })
|
|
12056
12053
|
] }),
|
|
12057
12054
|
/* @__PURE__ */ jsxs("div", { className: "d-flex justify-content-between align-items-center mt-2 total-fee", children: [
|
|
12058
12055
|
/* @__PURE__ */ jsx(Text, { size: "lg", weight: "bold", children: "Total" }),
|
|
12059
12056
|
totalLoading ? /* @__PURE__ */ jsx(ShurikenSpinner, { size: 20 }) : /* @__PURE__ */ jsxs("div", { style: { textAlign: "right" }, children: [
|
|
12060
|
-
/* @__PURE__ */ jsx(Text, { size: "lg", weight: "bold", children: total.amount === "Free"
|
|
12057
|
+
/* @__PURE__ */ jsx(Text, { size: "lg", weight: "bold", children: total.amount === "Free" || total.amount === "N/A" ? total.amount : `${total.amount} ETH` }),
|
|
12061
12058
|
totalUsd && /* @__PURE__ */ jsxs(Text, { size: "xs", color: "grey", children: [
|
|
12062
12059
|
"\u2248 $",
|
|
12063
12060
|
totalUsd
|
|
@@ -64136,6 +64133,18 @@ const ABIS = {
|
|
|
64136
64133
|
RESOLVER
|
|
64137
64134
|
};
|
|
64138
64135
|
|
|
64136
|
+
const COMMITMENTS_SLOT = 1n;
|
|
64137
|
+
const FIVE_MINUTES_SECONDS = 5 * 60;
|
|
64138
|
+
const HEURISTIC_COMMIT_GAS = 50000n;
|
|
64139
|
+
const HEURISTIC_REGISTER_BASE_GAS = 240000n;
|
|
64140
|
+
const HEURISTIC_GAS_PER_RECORD = 50000n;
|
|
64141
|
+
const isStateOverrideRejection = (err) => {
|
|
64142
|
+
const e = err;
|
|
64143
|
+
const code = e?.code ?? e?.cause?.code;
|
|
64144
|
+
if (code === -32602 || code === -32601 || code === -32e3) return true;
|
|
64145
|
+
const msg = `${e?.shortMessage ?? ""} ${e?.message ?? ""}`.toLowerCase();
|
|
64146
|
+
return msg.includes("state override") || msg.includes("stateoverride") || msg.includes("too many arguments") || msg.includes("invalid argument 2") || msg.includes("3rd parameter") || msg.includes("does not support");
|
|
64147
|
+
};
|
|
64139
64148
|
const NAMESPACE_REFERRER_ADDRESS = "0xb7B18611b8C51B4B3F400BaF09DB49E61e0aF044";
|
|
64140
64149
|
const ENS_REGISTRY_ABI = parseAbi([
|
|
64141
64150
|
"function owner(bytes32) view returns (address)"
|
|
@@ -64234,6 +64243,87 @@ const useRegisterENS = ({ isTestnet }) => {
|
|
|
64234
64243
|
const tx = await walletClient.writeContract(contractRequest);
|
|
64235
64244
|
return { txHash: tx, price };
|
|
64236
64245
|
};
|
|
64246
|
+
const getEffectiveGasPrice = () => publicClient.getGasPrice();
|
|
64247
|
+
const commitmentStorageSlot = (commitment) => keccak256(
|
|
64248
|
+
concatHex([padHex(commitment, { size: 32 }), padHex(toHex(COMMITMENTS_SLOT), { size: 32 })])
|
|
64249
|
+
);
|
|
64250
|
+
const estimateRegistrationFees = async (request) => {
|
|
64251
|
+
const fullName = `${request.label}.eth`;
|
|
64252
|
+
const resolverData = convertToResolverData(fullName, request.records);
|
|
64253
|
+
const controller = getEthController();
|
|
64254
|
+
const commitmentParams = {
|
|
64255
|
+
label: request.label,
|
|
64256
|
+
owner: request.owner,
|
|
64257
|
+
duration: BigInt(request.durationInSeconds),
|
|
64258
|
+
secret: keccak256(toBytes$1(request.secret)),
|
|
64259
|
+
resolver: getPublicResolver(),
|
|
64260
|
+
data: resolverData,
|
|
64261
|
+
reverseRecord: 0,
|
|
64262
|
+
referrer: getRegReferrer(request)
|
|
64263
|
+
};
|
|
64264
|
+
const commitment = await publicClient.readContract({
|
|
64265
|
+
functionName: "makeCommitment",
|
|
64266
|
+
abi: ABIS.ETH_REGISTRAR_CONTOLLER,
|
|
64267
|
+
address: controller,
|
|
64268
|
+
args: [commitmentParams]
|
|
64269
|
+
});
|
|
64270
|
+
const price = await getRegistrationPrice(request.label, request.durationInSeconds);
|
|
64271
|
+
const fiveMinAgo = BigInt(Math.floor(Date.now() / 1e3) - FIVE_MINUTES_SECONDS);
|
|
64272
|
+
const balanceOverride = price.wei * 2n + parseEther("1000000");
|
|
64273
|
+
const gasPricePromise = getEffectiveGasPrice();
|
|
64274
|
+
const commitGasPromise = publicClient.estimateContractGas({
|
|
64275
|
+
address: controller,
|
|
64276
|
+
abi: ABIS.ETH_REGISTRAR_CONTOLLER,
|
|
64277
|
+
functionName: "commit",
|
|
64278
|
+
args: [commitment],
|
|
64279
|
+
account: request.owner
|
|
64280
|
+
}).catch(() => HEURISTIC_COMMIT_GAS);
|
|
64281
|
+
const registerGasPromise = publicClient.estimateContractGas({
|
|
64282
|
+
address: controller,
|
|
64283
|
+
abi: ABIS.ETH_REGISTRAR_CONTOLLER,
|
|
64284
|
+
functionName: "register",
|
|
64285
|
+
args: [commitmentParams],
|
|
64286
|
+
account: request.owner,
|
|
64287
|
+
value: price.wei,
|
|
64288
|
+
stateOverride: [
|
|
64289
|
+
{
|
|
64290
|
+
address: controller,
|
|
64291
|
+
stateDiff: [
|
|
64292
|
+
{
|
|
64293
|
+
slot: commitmentStorageSlot(commitment),
|
|
64294
|
+
value: padHex(toHex(fiveMinAgo), { size: 32 })
|
|
64295
|
+
}
|
|
64296
|
+
]
|
|
64297
|
+
},
|
|
64298
|
+
{ address: request.owner, balance: balanceOverride }
|
|
64299
|
+
]
|
|
64300
|
+
}).then((g) => ({ gas: g, isHeuristic: false })).catch((err) => {
|
|
64301
|
+
if (typeof console !== "undefined") {
|
|
64302
|
+
console.warn(
|
|
64303
|
+
"[useRegisterENS] register-gas estimation failed; using heuristic.",
|
|
64304
|
+
isStateOverrideRejection(err) ? "(state override unsupported)" : "",
|
|
64305
|
+
err
|
|
64306
|
+
);
|
|
64307
|
+
}
|
|
64308
|
+
const recordCount = (request.records.addresses?.length ?? 0) + (request.records.texts?.length ?? 0);
|
|
64309
|
+
const heuristic = HEURISTIC_REGISTER_BASE_GAS + BigInt(recordCount) * HEURISTIC_GAS_PER_RECORD;
|
|
64310
|
+
return { gas: heuristic, isHeuristic: true };
|
|
64311
|
+
});
|
|
64312
|
+
const [commitGas, registerResult, gasPrice] = await Promise.all([
|
|
64313
|
+
commitGasPromise,
|
|
64314
|
+
registerGasPromise,
|
|
64315
|
+
gasPricePromise
|
|
64316
|
+
]);
|
|
64317
|
+
const totalGas = commitGas + registerResult.gas;
|
|
64318
|
+
const totalWei = totalGas * gasPrice;
|
|
64319
|
+
return {
|
|
64320
|
+
wei: totalWei,
|
|
64321
|
+
eth: parseFloat(formatEther(totalWei)),
|
|
64322
|
+
gasEstimate: totalGas,
|
|
64323
|
+
gasPrice,
|
|
64324
|
+
isHeuristic: registerResult.isHeuristic
|
|
64325
|
+
};
|
|
64326
|
+
};
|
|
64237
64327
|
const getEthController = () => distExports$1.getEnsContracts(isTestnet).ethRegistrarController;
|
|
64238
64328
|
const getEnsRegistry = () => distExports$1.getEnsContracts(isTestnet).ensRegistry;
|
|
64239
64329
|
const getPublicResolver = () => distExports$1.getEnsContracts(isTestnet).publicResolver;
|
|
@@ -64244,6 +64334,7 @@ const useRegisterENS = ({ isTestnet }) => {
|
|
|
64244
64334
|
return {
|
|
64245
64335
|
isEnsAvailable,
|
|
64246
64336
|
getRegistrationPrice,
|
|
64337
|
+
estimateRegistrationFees,
|
|
64247
64338
|
sendCommitmentTx,
|
|
64248
64339
|
sendRegisterTx
|
|
64249
64340
|
};
|
|
@@ -89488,18 +89579,13 @@ const RegistrationSummary = ({
|
|
|
89488
89579
|
const { ethUsdRate } = useEthDollarValue();
|
|
89489
89580
|
const { isEnsAvailable, getRegistrationPrice } = useRegisterENS({ isTestnet });
|
|
89490
89581
|
const { regPrice, regFees, regTotal } = useMemo(() => {
|
|
89491
|
-
|
|
89492
|
-
|
|
89493
|
-
|
|
89494
|
-
|
|
89495
|
-
|
|
89496
|
-
|
|
89497
|
-
}
|
|
89498
|
-
if (transactionFees) {
|
|
89499
|
-
regFees2 += transactionFees.price.eth;
|
|
89500
|
-
total += transactionFees.price.eth;
|
|
89501
|
-
}
|
|
89502
|
-
return { regFees: regFees2, regPrice: regPrice2, regTotal: formatFloat(total, 5) };
|
|
89582
|
+
const priceEth = price?.eth ?? 0;
|
|
89583
|
+
const feesEth = transactionFees?.price.eth ?? 0;
|
|
89584
|
+
const heuristicPrefix = transactionFees?.isHeuristic ? "~" : "";
|
|
89585
|
+
const regPrice2 = priceEth > 0 ? priceEth.toFixed(4) : "0.0000";
|
|
89586
|
+
const regFees2 = transactionFees?.failed ? "N/A" : `${heuristicPrefix}${feesEth.toFixed(4)}`;
|
|
89587
|
+
const regTotal2 = transactionFees?.failed ? "N/A" : `${heuristicPrefix}${(priceEth + feesEth).toFixed(4)}`;
|
|
89588
|
+
return { regPrice: regPrice2, regFees: regFees2, regTotal: regTotal2 };
|
|
89503
89589
|
}, [price, transactionFees]);
|
|
89504
89590
|
const checkAvailability = async (labelToCheck) => {
|
|
89505
89591
|
try {
|
|
@@ -89613,10 +89699,7 @@ const RegistrationSummary = ({
|
|
|
89613
89699
|
amount: regPrice,
|
|
89614
89700
|
isChecking: price.isChecking
|
|
89615
89701
|
},
|
|
89616
|
-
networkFees: {
|
|
89617
|
-
amount: regFees,
|
|
89618
|
-
isChecking: transactionFeesLoading
|
|
89619
|
-
},
|
|
89702
|
+
networkFees: transactionFees ? { amount: regFees, isChecking: transactionFeesLoading } : void 0,
|
|
89620
89703
|
total: {
|
|
89621
89704
|
amount: regTotal,
|
|
89622
89705
|
isChecking: totalPriceLoading
|
|
@@ -89846,13 +89929,19 @@ const CommitmentStep = ({
|
|
|
89846
89929
|
return;
|
|
89847
89930
|
}
|
|
89848
89931
|
try {
|
|
89849
|
-
await waitTx({ hash: tx });
|
|
89932
|
+
const receipt = await waitTx({ hash: tx });
|
|
89933
|
+
const commitFeeWei = receipt.gasUsed * (receipt.effectiveGasPrice || 0n);
|
|
89850
89934
|
setCommitTxStatus({ sent: true, completed: true, hash: tx });
|
|
89851
89935
|
setTimeout(() => {
|
|
89852
89936
|
onStateUpdated({
|
|
89853
89937
|
...state,
|
|
89854
89938
|
step: ProcessSteps.TimerStarted,
|
|
89855
|
-
commitment: {
|
|
89939
|
+
commitment: {
|
|
89940
|
+
tx,
|
|
89941
|
+
completed: true,
|
|
89942
|
+
time: (/* @__PURE__ */ new Date()).getTime(),
|
|
89943
|
+
feeWei: commitFeeWei
|
|
89944
|
+
}
|
|
89856
89945
|
});
|
|
89857
89946
|
setCommitTxStatus({ sent: false, completed: false, hash: "" });
|
|
89858
89947
|
}, 1e3);
|
|
@@ -90072,9 +90161,10 @@ const RegistrationStep = ({
|
|
|
90072
90161
|
try {
|
|
90073
90162
|
const receipt = await waitTx({ hash: tx });
|
|
90074
90163
|
setCommitTxStatus({ sent: true, completed: true, hash: tx });
|
|
90075
|
-
const
|
|
90076
|
-
const
|
|
90077
|
-
const
|
|
90164
|
+
const registerFeeWei = receipt.gasUsed * (receipt.effectiveGasPrice || 0n);
|
|
90165
|
+
const commitFeeWei = state.commitment?.feeWei ?? 0n;
|
|
90166
|
+
const totalFeeWei = registerFeeWei + commitFeeWei;
|
|
90167
|
+
const transactionFeesEth = formatEther(totalFeeWei);
|
|
90078
90168
|
const totalCost = (registrationPrice + parseFloat(transactionFeesEth)).toString();
|
|
90079
90169
|
const expiryDate = new Date(Date.now() + state.durationInSeconds * 1e3);
|
|
90080
90170
|
const formattedExpiryDate = expiryDate.toLocaleDateString("en-US", {
|
|
@@ -91062,19 +91152,24 @@ const RegistrationProcess = ({
|
|
|
91062
91152
|
] });
|
|
91063
91153
|
};
|
|
91064
91154
|
|
|
91155
|
+
const REG_SECRET_PLACEHOLDER = "0x0000000000000000000000000000000000000000000000000000000000000001";
|
|
91065
91156
|
const getLabel = (name) => {
|
|
91066
91157
|
if (!name) return "";
|
|
91067
91158
|
if (name.split(".").length !== 1) return name.split(".")[0];
|
|
91068
91159
|
return name;
|
|
91069
91160
|
};
|
|
91070
91161
|
const EnsNameRegistrationForm = (props) => {
|
|
91162
|
+
const { address: connectedAddress } = useAccount();
|
|
91163
|
+
const { estimateRegistrationFees } = useRegisterENS({ isTestnet: props.isTestnet });
|
|
91071
91164
|
const [label, setLabel] = useState(getLabel(props.name));
|
|
91072
91165
|
const [step, setStep] = useState(0 /* Summary */);
|
|
91073
91166
|
const [durationSeconds, setDurationSeconds] = useState(() => secondsFromYears(/* @__PURE__ */ new Date(), 1));
|
|
91074
91167
|
const [regTxFees, setRegTxFees] = useState({
|
|
91075
91168
|
estimatedGas: 0,
|
|
91076
91169
|
isChecking: false,
|
|
91077
|
-
|
|
91170
|
+
failed: false,
|
|
91171
|
+
isHeuristic: false,
|
|
91172
|
+
price: { wei: 0n, eth: 0 }
|
|
91078
91173
|
});
|
|
91079
91174
|
const [price, setPrice] = useState({ isChecking: false, wei: 0n, eth: 0 });
|
|
91080
91175
|
const [nameValidation, setNameValidation] = useState({ isChecking: false, isTaken: false });
|
|
@@ -91092,6 +91187,71 @@ const EnsNameRegistrationForm = (props) => {
|
|
|
91092
91187
|
[ensRecords, ensRecordTemplate]
|
|
91093
91188
|
);
|
|
91094
91189
|
const [successData, setSuccessData] = useState();
|
|
91190
|
+
const feeRequestRef = useRef(0);
|
|
91191
|
+
const estimateFnRef = useRef(estimateRegistrationFees);
|
|
91192
|
+
const referrerRef = useRef(props.referrer);
|
|
91193
|
+
estimateFnRef.current = estimateRegistrationFees;
|
|
91194
|
+
referrerRef.current = props.referrer;
|
|
91195
|
+
const debouncedEstimate = useMemo(
|
|
91196
|
+
() => debounce(
|
|
91197
|
+
(requestId, params) => {
|
|
91198
|
+
estimateFnRef.current({
|
|
91199
|
+
label: params.label,
|
|
91200
|
+
owner: params.owner,
|
|
91201
|
+
durationInSeconds: params.durationInSeconds,
|
|
91202
|
+
secret: REG_SECRET_PLACEHOLDER,
|
|
91203
|
+
records: params.records,
|
|
91204
|
+
referrer: referrerRef.current
|
|
91205
|
+
}).then((result) => {
|
|
91206
|
+
if (feeRequestRef.current !== requestId) return;
|
|
91207
|
+
setRegTxFees({
|
|
91208
|
+
isChecking: false,
|
|
91209
|
+
failed: false,
|
|
91210
|
+
isHeuristic: result.isHeuristic,
|
|
91211
|
+
estimatedGas: Number(result.gasEstimate),
|
|
91212
|
+
price: { wei: result.wei, eth: result.eth }
|
|
91213
|
+
});
|
|
91214
|
+
}).catch(() => {
|
|
91215
|
+
if (feeRequestRef.current !== requestId) return;
|
|
91216
|
+
setRegTxFees({
|
|
91217
|
+
isChecking: false,
|
|
91218
|
+
failed: true,
|
|
91219
|
+
isHeuristic: false,
|
|
91220
|
+
estimatedGas: 0,
|
|
91221
|
+
price: { wei: 0n, eth: 0 }
|
|
91222
|
+
});
|
|
91223
|
+
});
|
|
91224
|
+
},
|
|
91225
|
+
500
|
|
91226
|
+
),
|
|
91227
|
+
[]
|
|
91228
|
+
);
|
|
91229
|
+
useEffect(() => {
|
|
91230
|
+
if (!connectedAddress || !label || label.length < 3 || nameValidation.isChecking || nameValidation.isTaken || price.isChecking || price.eth <= 0) {
|
|
91231
|
+
feeRequestRef.current += 1;
|
|
91232
|
+
return;
|
|
91233
|
+
}
|
|
91234
|
+
const requestId = feeRequestRef.current + 1;
|
|
91235
|
+
feeRequestRef.current = requestId;
|
|
91236
|
+
setRegTxFees(
|
|
91237
|
+
(prev) => prev.isChecking && !prev.failed ? prev : { ...prev, isChecking: true, failed: false }
|
|
91238
|
+
);
|
|
91239
|
+
debouncedEstimate(requestId, {
|
|
91240
|
+
label,
|
|
91241
|
+
owner: connectedAddress,
|
|
91242
|
+
durationInSeconds: durationSeconds,
|
|
91243
|
+
records: ensRecords
|
|
91244
|
+
});
|
|
91245
|
+
}, [
|
|
91246
|
+
connectedAddress,
|
|
91247
|
+
label,
|
|
91248
|
+
durationSeconds,
|
|
91249
|
+
ensRecords,
|
|
91250
|
+
nameValidation.isChecking,
|
|
91251
|
+
nameValidation.isTaken,
|
|
91252
|
+
price.isChecking,
|
|
91253
|
+
price.eth
|
|
91254
|
+
]);
|
|
91095
91255
|
const handleSaveRecords = () => {
|
|
91096
91256
|
setEnsRecords(deepCopy(ensRecordTemplate));
|
|
91097
91257
|
setShowProfile(false);
|
|
@@ -91137,7 +91297,7 @@ const EnsNameRegistrationForm = (props) => {
|
|
|
91137
91297
|
price,
|
|
91138
91298
|
nameValidation,
|
|
91139
91299
|
isTestnet: props.isTestnet || false,
|
|
91140
|
-
transactionFees: regTxFees,
|
|
91300
|
+
transactionFees: connectedAddress ? regTxFees : void 0,
|
|
91141
91301
|
title: props.title,
|
|
91142
91302
|
subtitle: props.subtitle,
|
|
91143
91303
|
bannerImage: props.bannerImage,
|