@thenamespace/ens-components 1.3.0 → 1.4.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.
@@ -10,6 +10,8 @@ export interface RegistrationSummaryProps {
10
10
  };
11
11
  transactionFees?: {
12
12
  isChecking: boolean;
13
+ failed?: boolean;
14
+ isHeuristic?: boolean;
13
15
  estimatedGas: number;
14
16
  price: {
15
17
  wei: bigint;
@@ -15,6 +15,7 @@ export interface RegistrationState {
15
15
  tx?: string;
16
16
  completed: boolean;
17
17
  time: number;
18
+ feeWei?: bigint;
18
19
  };
19
20
  timerStartedAt: number;
20
21
  registration: {
@@ -1,19 +1,19 @@
1
1
  import React from "react";
2
2
  import "./PricingDisplay.css";
3
+ interface FeeRow {
4
+ amount: number | string;
5
+ isChecking: boolean;
6
+ /** Optional precise wei value. When provided, USD is computed from wei
7
+ * rather than from the (possibly rounded) display string. See
8
+ * `usdFromWei` for the precision bound. */
9
+ weiAmount?: bigint;
10
+ }
3
11
  export interface PricingDisplayProps {
4
- primaryFee: {
12
+ primaryFee: FeeRow & {
5
13
  label: string;
6
- amount: number | string;
7
- isChecking: boolean;
8
- };
9
- networkFees?: {
10
- amount: number | string;
11
- isChecking: boolean;
12
- };
13
- total: {
14
- amount: number | string;
15
- isChecking: boolean;
16
14
  };
15
+ networkFees?: FeeRow;
16
+ total: FeeRow;
17
17
  expiryPicker?: {
18
18
  durationSeconds: number;
19
19
  onDurationChange: (seconds: number) => void;
@@ -4,6 +4,15 @@ interface RentPriceResponse {
4
4
  wei: bigint;
5
5
  eth: number;
6
6
  }
7
+ export interface RegistrationFeeEstimate {
8
+ wei: bigint;
9
+ eth: number;
10
+ gasEstimate: bigint;
11
+ gasPrice: bigint;
12
+ /** True when the precise eth_estimateGas+stateOverride path failed and we
13
+ * fell back to a heuristic. UI can mark the value as approximate. */
14
+ isHeuristic: boolean;
15
+ }
7
16
  export interface RegistrationRequest {
8
17
  label: string;
9
18
  owner: Address;
@@ -17,6 +26,7 @@ export declare const useRegisterENS: ({ isTestnet }: {
17
26
  }) => {
18
27
  isEnsAvailable: (label: string) => Promise<boolean>;
19
28
  getRegistrationPrice: (label: string, durationInSeconds?: number) => Promise<RentPriceResponse>;
29
+ estimateRegistrationFees: (request: RegistrationRequest) => Promise<RegistrationFeeEstimate>;
20
30
  sendCommitmentTx: (request: RegistrationRequest) => Promise<Hash>;
21
31
  sendRegisterTx: (request: RegistrationRequest) => Promise<{
22
32
  txHash: Hash;
@@ -7,3 +7,4 @@ export * from "./ens";
7
7
  export * from "./blockExplorer";
8
8
  export * from "./async";
9
9
  export * from "./date";
10
+ export * from "./pricing";
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Pure helpers for formatting ETH/USD pricing in the registration UI.
3
+ *
4
+ * Display rules:
5
+ * - ETH is rendered at a fixed 4 decimals.
6
+ * - Non-zero values smaller than 0.0001 ETH render as the literal "<0.0001"
7
+ * so cheap-gas rows stay informative without claiming a misleading exact
8
+ * figure. The USD subtitle is derived from wei (when available) so it
9
+ * stays numerically honest even when the ETH cell is rounded.
10
+ * - "Free" and "N/A" are sentinel strings — they bypass formatting and
11
+ * suppress the USD subtitle.
12
+ */
13
+ export declare const ETH_SENTINELS: readonly ["Free", "N/A"];
14
+ export type EthSentinel = (typeof ETH_SENTINELS)[number];
15
+ export declare const isSentinel: (amount: number | string) => amount is EthSentinel;
16
+ /**
17
+ * Format an ETH amount for display at a fixed 4 decimals.
18
+ *
19
+ * Any positive value below the 4-decimal threshold renders as the literal
20
+ * "<0.0001" — honest about the rounding direction, and (crucially) avoids
21
+ * the misleading 1:1 read against the wei-derived USD subtitle when the
22
+ * true amount is much smaller than 0.0001 ETH.
23
+ */
24
+ export declare const formatEth: (eth: number) => string;
25
+ /**
26
+ * Convert wei → USD. Note the `Number(bigint)` cast loses exactness above
27
+ * 2^53 wei (~0.009 ETH); the resulting error is < 1e-7 relative, which is
28
+ * invisible after `.toFixed(2)` for any realistic ENS registration total.
29
+ */
30
+ export declare const usdFromWei: (wei: bigint, rate: number) => number;
31
+ /**
32
+ * Compute the `≈ $X.XX` subtitle for a fee row.
33
+ *
34
+ * Prefers `weiAmount` (precise) over the displayed string (which may have
35
+ * been rounded by `formatEth`). Returns `null` when the row is loading,
36
+ * unpriced, a sentinel ("Free"/"N/A"), or otherwise unparseable.
37
+ */
38
+ export declare const computeUsd: (amount: number | string, weiAmount: bigint | undefined, ethUsdRate: number | null | undefined, isChecking: boolean) => string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thenamespace/ens-components",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",