@1sat/react 0.0.17 → 0.0.18

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.
@@ -0,0 +1,30 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface ConnectDialogProviderInfo {
3
+ type: string;
4
+ name: string;
5
+ icon?: string;
6
+ isConnecting: boolean;
7
+ connect: () => void;
8
+ }
9
+ export interface ConnectDialogRenderProps {
10
+ providers: ConnectDialogProviderInfo[];
11
+ error: Error | null;
12
+ close: () => void;
13
+ }
14
+ export interface ConnectDialogProps {
15
+ /** Controlled open state */
16
+ open: boolean;
17
+ /** Called when dialog should close */
18
+ onOpenChange: (open: boolean) => void;
19
+ /** Render the dialog content. If omitted, a basic unstyled list is rendered. */
20
+ children?: (props: ConnectDialogRenderProps) => ReactNode;
21
+ }
22
+ /**
23
+ * Dialog for selecting a wallet provider when auto-detect finds nothing.
24
+ *
25
+ * Provides a list of available providers from WalletProvider config.
26
+ * Supports custom rendering via render-prop children, or renders a
27
+ * basic unstyled dialog if no children are provided.
28
+ */
29
+ export declare function ConnectDialog({ open, onOpenChange, children, }: ConnectDialogProps): import("react/jsx-runtime").JSX.Element;
30
+ //# sourceMappingURL=ConnectDialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectDialog.d.ts","sourceRoot":"","sources":["../src/ConnectDialog.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAA4C,MAAM,OAAO,CAAA;AAGhF,MAAM,WAAW,yBAAyB;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,OAAO,CAAA;IACrB,OAAO,EAAE,MAAM,IAAI,CAAA;CACnB;AAED,MAAM,WAAW,wBAAwB;IACxC,SAAS,EAAE,yBAAyB,EAAE,CAAA;IACtC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,KAAK,EAAE,MAAM,IAAI,CAAA;CACjB;AAED,MAAM,WAAW,kBAAkB;IAClC,4BAA4B;IAC5B,IAAI,EAAE,OAAO,CAAA;IACb,sCAAsC;IACtC,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,SAAS,CAAA;CACzD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,EAC7B,IAAI,EACJ,YAAY,EACZ,QAAQ,GACR,EAAE,kBAAkB,2CAgIpB"}
@@ -0,0 +1,23 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type ConnectDialogRenderProps } from './ConnectDialog';
3
+ interface ConnectDialogContextValue {
4
+ openConnectDialog: () => void;
5
+ }
6
+ /**
7
+ * Hook to open the connect wallet dialog from any component.
8
+ */
9
+ export declare function useConnectDialog(): ConnectDialogContextValue;
10
+ export interface ConnectDialogProviderProps {
11
+ children: ReactNode;
12
+ /** Custom render for the dialog content */
13
+ renderDialog?: (props: ConnectDialogRenderProps) => ReactNode;
14
+ }
15
+ /**
16
+ * Provides the connect dialog and useConnectDialog() hook to the app.
17
+ *
18
+ * Place inside WalletProvider. Login buttons call openConnectDialog()
19
+ * to show the provider selector.
20
+ */
21
+ export declare function ConnectDialogProvider({ children, renderDialog, }: ConnectDialogProviderProps): import("react/jsx-runtime").JSX.Element;
22
+ export {};
23
+ //# sourceMappingURL=ConnectDialogProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectDialogProvider.d.ts","sourceRoot":"","sources":["../src/ConnectDialogProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,SAAS,EAKd,MAAM,OAAO,CAAA;AACd,OAAO,EAAiB,KAAK,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAE9E,UAAU,yBAAyB;IAClC,iBAAiB,EAAE,MAAM,IAAI,CAAA;CAC7B;AAID;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,yBAAyB,CAQ5D;AAED,MAAM,WAAW,0BAA0B;IAC1C,QAAQ,EAAE,SAAS,CAAA;IACnB,2CAA2C;IAC3C,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,SAAS,CAAA;CAC7D;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,EACrC,QAAQ,EACR,YAAY,GACZ,EAAE,0BAA0B,2CAe5B"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from '@1sat/connect';
2
2
  export { WalletProvider, useWallet, type WalletContextValue, type WalletProviderProps, type WalletStatus, } from './wallet-context';
3
3
  export { SigmaCallback, type SigmaCallbackProps } from './SigmaCallback';
4
+ export { ConnectDialog, type ConnectDialogProps, type ConnectDialogProviderInfo, type ConnectDialogRenderProps, } from './ConnectDialog';
5
+ export { ConnectDialogProvider, useConnectDialog, type ConnectDialogProviderProps, } from './ConnectDialogProvider';
4
6
  export { ConnectButton, type ConnectButtonProps } from './ConnectButton';
5
7
  export { WalletSelector, type WalletSelectorProps, type WalletSelectorProviderInfo, type WalletSelectorRenderProps, } from './WalletSelector';
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAA;AAG7B,OAAO,EACN,cAAc,EACd,SAAS,EACT,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,YAAY,GACjB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAGxE,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EACN,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,GAC9B,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAA;AAG7B,OAAO,EACN,cAAc,EACd,SAAS,EACT,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,YAAY,GACjB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAGxE,OAAO,EACN,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,GAC7B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACN,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,0BAA0B,GAC/B,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EACN,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,GAC9B,MAAM,kBAAkB,CAAA"}
package/dist/index.js CHANGED
@@ -284,8 +284,160 @@ function SigmaCallback({
284
284
  })
285
285
  });
286
286
  }
287
+ // src/ConnectDialog.tsx
288
+ import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
289
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
290
+ "use client";
291
+ function ConnectDialog({
292
+ open,
293
+ onOpenChange,
294
+ children
295
+ }) {
296
+ const { availableProviders, connect, error } = useWallet();
297
+ const [connectingType, setConnectingType] = useState3(null);
298
+ const dialogRef = useRef2(null);
299
+ useEffect3(() => {
300
+ const dialog = dialogRef.current;
301
+ if (!dialog)
302
+ return;
303
+ if (open && !dialog.open) {
304
+ dialog.showModal();
305
+ } else if (!open && dialog.open) {
306
+ dialog.close();
307
+ }
308
+ }, [open]);
309
+ const handleClose = useCallback2(() => {
310
+ onOpenChange(false);
311
+ }, [onOpenChange]);
312
+ const handleConnect = useCallback2((providerType) => {
313
+ setConnectingType(providerType);
314
+ connect(providerType).finally(() => {
315
+ setConnectingType(null);
316
+ });
317
+ }, [connect]);
318
+ const providers = availableProviders.map((p) => ({
319
+ type: p.type,
320
+ name: p.name,
321
+ icon: p.icon,
322
+ isConnecting: connectingType === p.type,
323
+ connect: () => handleConnect(p.type)
324
+ }));
325
+ const renderProps = {
326
+ providers,
327
+ error,
328
+ close: handleClose
329
+ };
330
+ return /* @__PURE__ */ jsx3("dialog", {
331
+ ref: dialogRef,
332
+ onClose: handleClose,
333
+ style: {
334
+ padding: 0,
335
+ border: "none",
336
+ borderRadius: "0.75rem",
337
+ maxWidth: "24rem",
338
+ width: "100%",
339
+ background: "var(--background, #fff)",
340
+ color: "var(--foreground, #000)"
341
+ },
342
+ children: children ? children(renderProps) : /* @__PURE__ */ jsxs2("div", {
343
+ style: { padding: "1.5rem" },
344
+ children: [
345
+ /* @__PURE__ */ jsx3("h2", {
346
+ style: {
347
+ margin: "0 0 0.25rem",
348
+ fontSize: "1.125rem",
349
+ fontWeight: 600
350
+ },
351
+ children: "Connect Wallet"
352
+ }),
353
+ /* @__PURE__ */ jsx3("p", {
354
+ style: {
355
+ margin: "0 0 1rem",
356
+ fontSize: "0.875rem",
357
+ opacity: 0.6
358
+ },
359
+ children: "Choose how to connect."
360
+ }),
361
+ /* @__PURE__ */ jsx3("div", {
362
+ style: {
363
+ display: "flex",
364
+ flexDirection: "column",
365
+ gap: "0.5rem"
366
+ },
367
+ children: providers.map((provider) => /* @__PURE__ */ jsxs2("button", {
368
+ type: "button",
369
+ disabled: provider.isConnecting,
370
+ onClick: provider.connect,
371
+ style: {
372
+ display: "flex",
373
+ alignItems: "center",
374
+ gap: "0.75rem",
375
+ width: "100%",
376
+ padding: "0.75rem 1rem",
377
+ border: "1px solid #e5e5e5",
378
+ borderRadius: "0.5rem",
379
+ background: "transparent",
380
+ cursor: provider.isConnecting ? "wait" : "pointer",
381
+ fontSize: "0.875rem",
382
+ opacity: provider.isConnecting ? 0.6 : 1
383
+ },
384
+ children: [
385
+ provider.name,
386
+ provider.isConnecting && " ..."
387
+ ]
388
+ }, provider.type))
389
+ }),
390
+ error && /* @__PURE__ */ jsx3("p", {
391
+ style: {
392
+ marginTop: "0.75rem",
393
+ fontSize: "0.875rem",
394
+ color: "#dc2626"
395
+ },
396
+ children: error.message
397
+ })
398
+ ]
399
+ })
400
+ });
401
+ }
402
+ // src/ConnectDialogProvider.tsx
403
+ import {
404
+ createContext as createContext2,
405
+ useCallback as useCallback3,
406
+ useContext as useContext2,
407
+ useState as useState4
408
+ } from "react";
409
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
410
+ "use client";
411
+ var ConnectDialogCtx = createContext2(null);
412
+ function useConnectDialog() {
413
+ const ctx = useContext2(ConnectDialogCtx);
414
+ if (!ctx) {
415
+ throw new Error("useConnectDialog must be used within ConnectDialogProvider");
416
+ }
417
+ return ctx;
418
+ }
419
+ function ConnectDialogProvider({
420
+ children,
421
+ renderDialog
422
+ }) {
423
+ const [open, setOpen] = useState4(false);
424
+ const openConnectDialog = useCallback3(() => {
425
+ setOpen(true);
426
+ }, []);
427
+ return /* @__PURE__ */ jsxs3(ConnectDialogCtx.Provider, {
428
+ value: { openConnectDialog },
429
+ children: [
430
+ children,
431
+ /* @__PURE__ */ jsx4(ConnectDialog, {
432
+ open,
433
+ onOpenChange: setOpen,
434
+ children: renderDialog
435
+ })
436
+ ]
437
+ });
438
+ }
287
439
  // src/ConnectButton.tsx
288
- import { jsx as jsx3, Fragment as Fragment2 } from "react/jsx-runtime";
440
+ import { jsx as jsx5, Fragment as Fragment2 } from "react/jsx-runtime";
289
441
  "use client";
290
442
  function truncateIdentityKey(key) {
291
443
  if (key.length <= 12)
@@ -329,7 +481,7 @@ function ConnectButton({
329
481
  }
330
482
  };
331
483
  if (children) {
332
- return /* @__PURE__ */ jsx3(Fragment2, {
484
+ return /* @__PURE__ */ jsx5(Fragment2, {
333
485
  children: children({
334
486
  isConnected,
335
487
  isConnecting,
@@ -340,7 +492,7 @@ function ConnectButton({
340
492
  });
341
493
  }
342
494
  if (isConnecting) {
343
- return /* @__PURE__ */ jsx3("button", {
495
+ return /* @__PURE__ */ jsx5("button", {
344
496
  className,
345
497
  style,
346
498
  disabled: true,
@@ -350,7 +502,7 @@ function ConnectButton({
350
502
  }
351
503
  if (isConnected) {
352
504
  const label = typeof connectedLabel === "function" ? connectedLabel(identityKey ?? "") : connectedLabel ?? truncateIdentityKey(identityKey ?? "");
353
- return /* @__PURE__ */ jsx3("button", {
505
+ return /* @__PURE__ */ jsx5("button", {
354
506
  className,
355
507
  style,
356
508
  onClick: disconnectOnClick ? disconnect : undefined,
@@ -358,7 +510,7 @@ function ConnectButton({
358
510
  children: label
359
511
  });
360
512
  }
361
- return /* @__PURE__ */ jsx3("button", {
513
+ return /* @__PURE__ */ jsx5("button", {
362
514
  className,
363
515
  style,
364
516
  onClick: connect,
@@ -367,13 +519,13 @@ function ConnectButton({
367
519
  });
368
520
  }
369
521
  // src/WalletSelector.tsx
370
- import { useCallback as useCallback2, useState as useState3 } from "react";
371
- import { jsx as jsx4, Fragment as Fragment3 } from "react/jsx-runtime";
522
+ import { useCallback as useCallback4, useState as useState5 } from "react";
523
+ import { jsx as jsx6, Fragment as Fragment3 } from "react/jsx-runtime";
372
524
  "use client";
373
525
  function WalletSelector({ onClose, children }) {
374
526
  const { availableProviders, connect, error } = useWallet();
375
- const [connectingType, setConnectingType] = useState3(null);
376
- const handleConnect = useCallback2(async (providerType) => {
527
+ const [connectingType, setConnectingType] = useState5(null);
528
+ const handleConnect = useCallback4(async (providerType) => {
377
529
  setConnectingType(providerType);
378
530
  try {
379
531
  await connect(providerType);
@@ -390,14 +542,17 @@ function WalletSelector({ onClose, children }) {
390
542
  isConnecting: connectingType === p.type,
391
543
  connect: () => handleConnect(p.type)
392
544
  }));
393
- return /* @__PURE__ */ jsx4(Fragment3, {
545
+ return /* @__PURE__ */ jsx6(Fragment3, {
394
546
  children: children({ providers, error })
395
547
  });
396
548
  }
397
549
  export {
398
550
  useWallet,
551
+ useConnectDialog,
399
552
  WalletSelector,
400
553
  WalletProvider,
401
554
  SigmaCallback,
555
+ ConnectDialogProvider,
556
+ ConnectDialog,
402
557
  ConnectButton
403
558
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/react",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "React hooks and components for 1Sat wallet integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",