@1sat/react 0.0.17 → 0.0.19

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"}
@@ -1 +1 @@
1
- {"version":3,"file":"SigmaCallback.d.ts","sourceRoot":"","sources":["../src/SigmaCallback.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAA;AAI3D,MAAM,WAAW,kBAAkB;IAClC,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,6BAA6B;IAC7B,cAAc,CAAC,EAAE,SAAS,CAAA;IAC1B,0BAA0B;IAC1B,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,KAAK,SAAS,CAAA;CAC9D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,EAC7B,UAAgB,EAChB,cAAc,EACd,WAAW,GACX,EAAE,kBAAkB,2CAoGpB"}
1
+ {"version":3,"file":"SigmaCallback.d.ts","sourceRoot":"","sources":["../src/SigmaCallback.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAA;AAI3D,MAAM,WAAW,kBAAkB;IAClC,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,6BAA6B;IAC7B,cAAc,CAAC,EAAE,SAAS,CAAA;IAC1B,0BAA0B;IAC1B,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,KAAK,SAAS,CAAA;CAC9D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,EAC7B,UAAgB,EAChB,cAAc,EACd,WAAW,GACX,EAAE,kBAAkB,2CAuGpB"}
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
@@ -203,7 +203,9 @@ function SigmaCallback({
203
203
  const [error, setError] = useState2(null);
204
204
  useEffect2(() => {
205
205
  const searchParams = new URLSearchParams(window.location.search);
206
+ localStorage.setItem("__sigma_debug", JSON.stringify({ stage: "start", search: window.location.search }));
206
207
  completeSigmaOAuth(searchParams).then((result) => {
208
+ localStorage.setItem("__sigma_debug", JSON.stringify({ stage: "success", bapId: result.bapId, pubkey: result.pubkey, hasUser: !!result.user }));
207
209
  localStorage.setItem(STORAGE_KEY2, JSON.stringify({
208
210
  providerType: "sigma",
209
211
  identityKey: result.pubkey,
@@ -213,6 +215,7 @@ function SigmaCallback({
213
215
  }));
214
216
  window.location.href = redirectTo;
215
217
  }).catch((err) => {
218
+ localStorage.setItem("__sigma_debug", JSON.stringify({ stage: "error", error: typeof err === "object" ? JSON.stringify(err) : String(err) }));
216
219
  console.error("Sigma OAuth callback error:", err);
217
220
  const msg = err instanceof Error ? err.message : typeof err === "object" && err !== null && ("message" in err) ? String(err.message) : "Authentication failed";
218
221
  setError(msg);
@@ -284,8 +287,160 @@ function SigmaCallback({
284
287
  })
285
288
  });
286
289
  }
290
+ // src/ConnectDialog.tsx
291
+ import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
292
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
293
+ "use client";
294
+ function ConnectDialog({
295
+ open,
296
+ onOpenChange,
297
+ children
298
+ }) {
299
+ const { availableProviders, connect, error } = useWallet();
300
+ const [connectingType, setConnectingType] = useState3(null);
301
+ const dialogRef = useRef2(null);
302
+ useEffect3(() => {
303
+ const dialog = dialogRef.current;
304
+ if (!dialog)
305
+ return;
306
+ if (open && !dialog.open) {
307
+ dialog.showModal();
308
+ } else if (!open && dialog.open) {
309
+ dialog.close();
310
+ }
311
+ }, [open]);
312
+ const handleClose = useCallback2(() => {
313
+ onOpenChange(false);
314
+ }, [onOpenChange]);
315
+ const handleConnect = useCallback2((providerType) => {
316
+ setConnectingType(providerType);
317
+ connect(providerType).finally(() => {
318
+ setConnectingType(null);
319
+ });
320
+ }, [connect]);
321
+ const providers = availableProviders.map((p) => ({
322
+ type: p.type,
323
+ name: p.name,
324
+ icon: p.icon,
325
+ isConnecting: connectingType === p.type,
326
+ connect: () => handleConnect(p.type)
327
+ }));
328
+ const renderProps = {
329
+ providers,
330
+ error,
331
+ close: handleClose
332
+ };
333
+ return /* @__PURE__ */ jsx3("dialog", {
334
+ ref: dialogRef,
335
+ onClose: handleClose,
336
+ style: {
337
+ padding: 0,
338
+ border: "none",
339
+ borderRadius: "0.75rem",
340
+ maxWidth: "24rem",
341
+ width: "100%",
342
+ background: "var(--background, #fff)",
343
+ color: "var(--foreground, #000)"
344
+ },
345
+ children: children ? children(renderProps) : /* @__PURE__ */ jsxs2("div", {
346
+ style: { padding: "1.5rem" },
347
+ children: [
348
+ /* @__PURE__ */ jsx3("h2", {
349
+ style: {
350
+ margin: "0 0 0.25rem",
351
+ fontSize: "1.125rem",
352
+ fontWeight: 600
353
+ },
354
+ children: "Connect Wallet"
355
+ }),
356
+ /* @__PURE__ */ jsx3("p", {
357
+ style: {
358
+ margin: "0 0 1rem",
359
+ fontSize: "0.875rem",
360
+ opacity: 0.6
361
+ },
362
+ children: "Choose how to connect."
363
+ }),
364
+ /* @__PURE__ */ jsx3("div", {
365
+ style: {
366
+ display: "flex",
367
+ flexDirection: "column",
368
+ gap: "0.5rem"
369
+ },
370
+ children: providers.map((provider) => /* @__PURE__ */ jsxs2("button", {
371
+ type: "button",
372
+ disabled: provider.isConnecting,
373
+ onClick: provider.connect,
374
+ style: {
375
+ display: "flex",
376
+ alignItems: "center",
377
+ gap: "0.75rem",
378
+ width: "100%",
379
+ padding: "0.75rem 1rem",
380
+ border: "1px solid #e5e5e5",
381
+ borderRadius: "0.5rem",
382
+ background: "transparent",
383
+ cursor: provider.isConnecting ? "wait" : "pointer",
384
+ fontSize: "0.875rem",
385
+ opacity: provider.isConnecting ? 0.6 : 1
386
+ },
387
+ children: [
388
+ provider.name,
389
+ provider.isConnecting && " ..."
390
+ ]
391
+ }, provider.type))
392
+ }),
393
+ error && /* @__PURE__ */ jsx3("p", {
394
+ style: {
395
+ marginTop: "0.75rem",
396
+ fontSize: "0.875rem",
397
+ color: "#dc2626"
398
+ },
399
+ children: error.message
400
+ })
401
+ ]
402
+ })
403
+ });
404
+ }
405
+ // src/ConnectDialogProvider.tsx
406
+ import {
407
+ createContext as createContext2,
408
+ useCallback as useCallback3,
409
+ useContext as useContext2,
410
+ useState as useState4
411
+ } from "react";
412
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
413
+ "use client";
414
+ var ConnectDialogCtx = createContext2(null);
415
+ function useConnectDialog() {
416
+ const ctx = useContext2(ConnectDialogCtx);
417
+ if (!ctx) {
418
+ throw new Error("useConnectDialog must be used within ConnectDialogProvider");
419
+ }
420
+ return ctx;
421
+ }
422
+ function ConnectDialogProvider({
423
+ children,
424
+ renderDialog
425
+ }) {
426
+ const [open, setOpen] = useState4(false);
427
+ const openConnectDialog = useCallback3(() => {
428
+ setOpen(true);
429
+ }, []);
430
+ return /* @__PURE__ */ jsxs3(ConnectDialogCtx.Provider, {
431
+ value: { openConnectDialog },
432
+ children: [
433
+ children,
434
+ /* @__PURE__ */ jsx4(ConnectDialog, {
435
+ open,
436
+ onOpenChange: setOpen,
437
+ children: renderDialog
438
+ })
439
+ ]
440
+ });
441
+ }
287
442
  // src/ConnectButton.tsx
288
- import { jsx as jsx3, Fragment as Fragment2 } from "react/jsx-runtime";
443
+ import { jsx as jsx5, Fragment as Fragment2 } from "react/jsx-runtime";
289
444
  "use client";
290
445
  function truncateIdentityKey(key) {
291
446
  if (key.length <= 12)
@@ -329,7 +484,7 @@ function ConnectButton({
329
484
  }
330
485
  };
331
486
  if (children) {
332
- return /* @__PURE__ */ jsx3(Fragment2, {
487
+ return /* @__PURE__ */ jsx5(Fragment2, {
333
488
  children: children({
334
489
  isConnected,
335
490
  isConnecting,
@@ -340,7 +495,7 @@ function ConnectButton({
340
495
  });
341
496
  }
342
497
  if (isConnecting) {
343
- return /* @__PURE__ */ jsx3("button", {
498
+ return /* @__PURE__ */ jsx5("button", {
344
499
  className,
345
500
  style,
346
501
  disabled: true,
@@ -350,7 +505,7 @@ function ConnectButton({
350
505
  }
351
506
  if (isConnected) {
352
507
  const label = typeof connectedLabel === "function" ? connectedLabel(identityKey ?? "") : connectedLabel ?? truncateIdentityKey(identityKey ?? "");
353
- return /* @__PURE__ */ jsx3("button", {
508
+ return /* @__PURE__ */ jsx5("button", {
354
509
  className,
355
510
  style,
356
511
  onClick: disconnectOnClick ? disconnect : undefined,
@@ -358,7 +513,7 @@ function ConnectButton({
358
513
  children: label
359
514
  });
360
515
  }
361
- return /* @__PURE__ */ jsx3("button", {
516
+ return /* @__PURE__ */ jsx5("button", {
362
517
  className,
363
518
  style,
364
519
  onClick: connect,
@@ -367,13 +522,13 @@ function ConnectButton({
367
522
  });
368
523
  }
369
524
  // 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";
525
+ import { useCallback as useCallback4, useState as useState5 } from "react";
526
+ import { jsx as jsx6, Fragment as Fragment3 } from "react/jsx-runtime";
372
527
  "use client";
373
528
  function WalletSelector({ onClose, children }) {
374
529
  const { availableProviders, connect, error } = useWallet();
375
- const [connectingType, setConnectingType] = useState3(null);
376
- const handleConnect = useCallback2(async (providerType) => {
530
+ const [connectingType, setConnectingType] = useState5(null);
531
+ const handleConnect = useCallback4(async (providerType) => {
377
532
  setConnectingType(providerType);
378
533
  try {
379
534
  await connect(providerType);
@@ -390,14 +545,17 @@ function WalletSelector({ onClose, children }) {
390
545
  isConnecting: connectingType === p.type,
391
546
  connect: () => handleConnect(p.type)
392
547
  }));
393
- return /* @__PURE__ */ jsx4(Fragment3, {
548
+ return /* @__PURE__ */ jsx6(Fragment3, {
394
549
  children: children({ providers, error })
395
550
  });
396
551
  }
397
552
  export {
398
553
  useWallet,
554
+ useConnectDialog,
399
555
  WalletSelector,
400
556
  WalletProvider,
401
557
  SigmaCallback,
558
+ ConnectDialogProvider,
559
+ ConnectDialog,
402
560
  ConnectButton
403
561
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/react",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "React hooks and components for 1Sat wallet integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",