@manifoldxyz/dropkit 0.2.1 → 0.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.
package/dist/cart.d.ts ADDED
@@ -0,0 +1,216 @@
1
+ import { ReactNode, ReactElement } from 'react';
2
+ import { Address, Hex } from 'viem';
3
+ import { R as ReasonCode, M as ManifoldClaimConfig, D as DropInfo, a as Money, b as RpcUrls } from './types-BjKGb6c7.js';
4
+
5
+ declare const CART_REASONS: readonly ["CART_ERC20_UNSUPPORTED", "PERSISTENCE_UNAVAILABLE", "REQUEST_NOT_SENT"];
6
+ type CartOnlyReason = (typeof CART_REASONS)[number];
7
+ type CartReasonCode = ReasonCode | CartOnlyReason;
8
+ declare class CartError extends Error {
9
+ readonly reason: CartReasonCode;
10
+ constructor(reason: CartReasonCode, message: string, opts?: {
11
+ cause?: unknown;
12
+ });
13
+ }
14
+
15
+ /** A token the mint delivered, from the receipt (or the 1155 tokenId when the receipt was lost). */
16
+ type CollectedToken = {
17
+ contract: Address;
18
+ tokenId: string;
19
+ };
20
+ type CollectedLinks = {
21
+ /** The transaction on the chain's block explorer. null without a hash or a known explorer. */
22
+ tx: string | null;
23
+ /**
24
+ * The collector's OpenSea profile. Filtered to the collection when CartProvider has an OpenSea slug for the
25
+ * contract; the plain profile when there is no slug and no token is known; otherwise null.
26
+ */
27
+ profile: string | null;
28
+ /** One OpenSea item page per minted token. */
29
+ tokens: {
30
+ tokenId: string;
31
+ url: string;
32
+ }[];
33
+ };
34
+ declare const openseaChain: (chainId: number) => string | null;
35
+
36
+ /** config.extension is required (D20). */
37
+ type CartItem = {
38
+ key: string;
39
+ config: ManifoldClaimConfig;
40
+ quantity: number;
41
+ };
42
+ type CartProviderProps = {
43
+ /** The one chain every item is on and every mint is paid on. */
44
+ chainId: number;
45
+ /** Optional, same as MintButton. Without it the cart warns (R21). */
46
+ rpcUrls?: RpcUrls;
47
+ /** Default 'dropkit-cart:<chainId>'. One CartProvider per key per tab (R17). */
48
+ storageKey?: string;
49
+ connect?: {
50
+ walletConnectProjectId?: string;
51
+ };
52
+ /**
53
+ * OpenSea collection slug per creator contract, e.g. { '0xabc…': 'cities-paris' }. With a slug, a collected item's
54
+ * profile link opens the collector's OpenSea holdings filtered to that collection (D32).
55
+ */
56
+ openseaCollections?: Readonly<Record<string, string>>;
57
+ children: ReactNode;
58
+ };
59
+ type CartLineState = 'loading' | 'locked' | 'upcoming' | 'live' | 'sold-out' | 'ended' | 'ineligible' | 'unsupported' | 'error';
60
+ type CartLine = CartItem & {
61
+ /** locked: a mint for this line is pending (R16). */
62
+ state: CartLineState;
63
+ reason: CartReasonCode | null;
64
+ drop: DropInfo | null;
65
+ /** Copies left, capped by the wallet limit when a wallet is connected. null = no limit. */
66
+ maxQuantity: number | null;
67
+ /** (unitPrice + unitFee) x quantity, in the native token. */
68
+ total: Money | null;
69
+ };
70
+ /**
71
+ * Hash lost and holdings did not prove the mint (D15). `wallet` is the wallet that sent it; `message` names it:
72
+ * "We couldn't confirm this. Check wallet 0x1234…abcd. If it didn't go through, add it again."
73
+ */
74
+ type UnconfirmedItem = {
75
+ id: string;
76
+ key: string;
77
+ config: ManifoldClaimConfig;
78
+ quantity: number;
79
+ at: number;
80
+ wallet: Address;
81
+ message: string;
82
+ };
83
+ type CollectedItem = {
84
+ id: string;
85
+ key: string;
86
+ quantity: number;
87
+ at: number;
88
+ txHash: Hex | null;
89
+ wallet: Address;
90
+ /** The minted tokens, from the receipt. Empty when the receipt was lost and the token id is unknown. */
91
+ tokens: CollectedToken[];
92
+ /** Explorer transaction, OpenSea profile (filtered with a slug) and OpenSea token pages (D32). */
93
+ links: CollectedLinks;
94
+ };
95
+ type AddResult = 'added' | 'looks-collected' | 'check-unavailable';
96
+ type CartState = {
97
+ lines: CartLine[];
98
+ unconfirmed: UnconfirmedItem[];
99
+ collected: CollectedItem[];
100
+ /** Native total of every line that is not unsupported or locked. */
101
+ total: Money | null;
102
+ /** Number of lines in the cart. */
103
+ count: number;
104
+ /**
105
+ * Rejects with INVALID_CONFIG when extension is missing, the chain differs, or the type is 'contract'.
106
+ * For an item with an Unconfirmed result, runs the R20 check first.
107
+ */
108
+ add(config: ManifoldClaimConfig, quantity?: number, opts?: {
109
+ force?: boolean;
110
+ }): Promise<AddResult>;
111
+ setQuantity(key: string, quantity: number): void;
112
+ remove(key: string): void;
113
+ /** Removes items only. Pending mints and results stay. */
114
+ clear(): void;
115
+ /** Synchronous. The key needs no lookup because extension is required. */
116
+ has(config: ManifoldClaimConfig): boolean;
117
+ /** Deletes the result (D19). */
118
+ dismissUnconfirmed(id: string): void;
119
+ /** Runs the Step 5b algorithm once for every pending mint. For a "Check again" button on locked lines. */
120
+ checkPending(): Promise<void>;
121
+ };
122
+ type CheckoutStepStatus = 'pending' | 'active' | 'unknown' | 'success' | 'unconfirmed' | 'skipped' | 'failed';
123
+ type CheckoutStep = {
124
+ key: string;
125
+ /** unknown: waiting for a receipt. unconfirmed: hash lost, counted as gone through (D15). */
126
+ status: CheckoutStepStatus;
127
+ reason: CartReasonCode | null;
128
+ message: string | null;
129
+ txHash: Hex | null;
130
+ };
131
+ /** The wallet request the next confirm() sends. */
132
+ type CheckoutAction = {
133
+ kind: 'add-chain';
134
+ chainId: number;
135
+ } | {
136
+ kind: 'switch-chain';
137
+ chainId: number;
138
+ } | {
139
+ kind: 'mint';
140
+ key: string;
141
+ amount: Money;
142
+ };
143
+ type CheckoutStateName = 'idle' | 'preparing' | 'blocked' | 'ready' | 'sending' | 'checking' | 'paused' | 'done';
144
+ type CheckoutState = {
145
+ state: CheckoutStateName;
146
+ action: CheckoutAction | null;
147
+ reason: CartReasonCode | null;
148
+ message: string | null;
149
+ steps: CheckoutStep[];
150
+ /** 1-based index of the active step among the steps that are not skipped, for "Step 2 of 3". */
151
+ current: number | null;
152
+ checkout(): void;
153
+ /** Sends action. Call it only from a click handler. Does nothing outside ready. */
154
+ confirm(): void;
155
+ /** In checking: look for the receipt once more. */
156
+ check(): void;
157
+ retry(): void;
158
+ skip(): void;
159
+ stop(): void;
160
+ reset(): void;
161
+ };
162
+
163
+ declare function useCart(): CartState;
164
+ declare function CartProvider(props: CartProviderProps): ReactElement;
165
+
166
+ declare function useCheckout(): CheckoutState;
167
+
168
+ type Holding = {
169
+ /**
170
+ * owned: tokens of this drop the wallet holds now (ERC-1155).
171
+ * minted: how many it minted from this drop (ERC-721 with a wallet limit).
172
+ * owned-in-contract: tokens it holds on the drop's contract, any drop (other ERC-721). Equals "owned" when the
173
+ * contract has only this drop.
174
+ */
175
+ kind: 'owned' | 'minted' | 'owned-in-contract';
176
+ count: number;
177
+ };
178
+ type HoldingsState = {
179
+ /** The wallet read: opts.wallet, else the connected account. null = no wallet, nothing read. */
180
+ wallet: Address | null;
181
+ /** Keyed like cart lines (itemKey). A drop is missing until its first read finishes; null when it failed. */
182
+ byKey: Record<string, Holding | null>;
183
+ /** Read for one config. undefined while loading or without a wallet. */
184
+ get(config: ManifoldClaimConfig): Holding | null | undefined;
185
+ loading: boolean;
186
+ /** Reads every drop again. */
187
+ refresh(): void;
188
+ };
189
+ /**
190
+ * Reads on mount, when the wallet changes, when the config list changes, after each collected mint, and on refresh().
191
+ * No timer. Configs need extension, like cart configs.
192
+ */
193
+ declare function useHoldings(configs: readonly ManifoldClaimConfig[], opts?: {
194
+ wallet?: Address;
195
+ }): HoldingsState;
196
+
197
+ type AddToCartState = 'add' | 'adding' | 'in-cart' | 'locked' | 'unconfirmed' | 'sold-out' | 'upcoming' | 'unsupported';
198
+ type AddToCartButtonProps = {
199
+ config: ManifoldClaimConfig;
200
+ quantity?: number;
201
+ className?: string;
202
+ /** A function child replaces the default markup. It gets the state, the last AddResult and add(opts). */
203
+ children?: ReactNode | ((b: AddToCartRender) => ReactNode);
204
+ };
205
+ type AddToCartRender = {
206
+ state: AddToCartState;
207
+ /** The last AddResult of this button, or null. 'looks-collected' and 'check-unavailable' ask the site to confirm. */
208
+ result: AddResult | null;
209
+ line: CartLine | null;
210
+ add(opts?: {
211
+ force?: boolean;
212
+ }): void;
213
+ };
214
+ declare function AddToCartButton(props: AddToCartButtonProps): ReactNode;
215
+
216
+ export { type AddResult, AddToCartButton, type AddToCartButtonProps, type AddToCartRender, type AddToCartState, CartError, type CartItem, type CartLine, type CartLineState, type CartOnlyReason, CartProvider, type CartProviderProps, type CartReasonCode, type CartState, type CheckoutAction, type CheckoutState, type CheckoutStateName, type CheckoutStep, type CheckoutStepStatus, type CollectedItem, type CollectedLinks, type CollectedToken, type Holding, type HoldingsState, type UnconfirmedItem, openseaChain, useCart, useCheckout, useHoldings };