@fiber-pay/react 0.2.3 → 0.2.4

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/README.md CHANGED
@@ -11,7 +11,7 @@ pnpm add @fiber-pay/react react
11
11
  ## One-line import
12
12
 
13
13
  ```tsx
14
- import { FiberPayQuickCard, useFiberNode, useFiberPayment } from '@fiber-pay/react';
14
+ import { ConnectButton, FiberPayQuickCard, useFiberNode, useFiberPayment } from '@fiber-pay/react';
15
15
  ```
16
16
 
17
17
  ## Quick start
@@ -33,6 +33,42 @@ export function App() {
33
33
  - `onPaymentResult(result)`
34
34
  - `onError({ scope, message })`
35
35
 
36
+ ## ConnectButton
37
+
38
+ Use `ConnectButton` with an existing `useFiberNode` result for drop-in integration.
39
+
40
+ ```tsx
41
+ import { ConnectButton, useFiberNode } from '@fiber-pay/react';
42
+ import { Fiber } from '@nervosnetwork/fiber-js';
43
+
44
+ export function HeaderWallet() {
45
+ const fiber = useFiberNode({ network: 'testnet', wasmFactory: () => new Fiber() });
46
+ return <ConnectButton fiber={fiber} />;
47
+ }
48
+ ```
49
+
50
+ For custom connected-state panels (for example peer/channel controls), use `renderConnectedDropdown`:
51
+
52
+ ```tsx
53
+ <ConnectButton
54
+ fiber={fiber}
55
+ dropdownStyle={{ width: 320 }}
56
+ renderConnectedDropdown={({ fiber, disconnect }) => (
57
+ <div>
58
+ <div>State: {fiber.state}</div>
59
+ <button
60
+ type="button"
61
+ onClick={() => {
62
+ void disconnect();
63
+ }}
64
+ >
65
+ Disconnect
66
+ </button>
67
+ </div>
68
+ )}
69
+ />
70
+ ```
71
+
36
72
  ## Hooks
37
73
 
38
74
  - `useFiberNode(options)`
package/dist/index.d.ts CHANGED
@@ -1,34 +1,25 @@
1
+ import { BrowserNodeState, FiberBrowserNode, NodeInfoResult, PasskeySupportReason, FiberBrowserNodeConfig, FiberWasmFactory, GetPaymentResult } from '@fiber-pay/sdk/browser';
2
+ export { BrowserNodeState, ChannelState, ConfigBuilder, FiberBrowserNode, FiberBrowserNodeConfig, FiberRpcError, FiberWasmFactory, NodeInfoResult, PasskeyCredentialProvider, PasskeySupportReason, PasswordCredentialProvider, RawKeyCredentialProvider, ckbHash, ckbToShannons, derivePublicKey, formatShannonsAsCkb, fromHex, getLockBalanceShannons, scriptToAddress, shannonsToCkb, toHex } from '@fiber-pay/sdk/browser';
1
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { GetPaymentResult, FiberBrowserNodeConfig, FiberWasmFactory, BrowserNodeState, FiberBrowserNode, NodeInfoResult, PasskeySupportReason } from '@fiber-pay/sdk/browser';
3
- import { CSSProperties } from 'react';
4
-
5
- interface FiberPayQuickCardProps {
6
- network?: 'testnet' | 'mainnet';
7
- walletId?: string;
8
- passkeyUsername?: string;
9
- title?: string;
10
- className?: string;
11
- style?: CSSProperties;
12
- onInvoiceCreated?: (invoice: string) => void;
13
- onPaymentResult?: (result: GetPaymentResult) => void;
14
- onError?: (error: {
15
- scope: 'node' | 'payment' | 'invoice';
16
- message: string;
17
- }) => void;
18
- }
19
- declare function FiberPayQuickCard(props: FiberPayQuickCardProps): react_jsx_runtime.JSX.Element;
4
+ import { CSSProperties, ReactNode } from 'react';
20
5
 
21
6
  interface UseFiberNodeOptions {
22
7
  network: 'testnet' | 'mainnet';
23
8
  walletId?: string;
24
9
  nodeConfig?: FiberBrowserNodeConfig['nodeConfig'];
25
10
  wasmFactory?: FiberWasmFactory;
11
+ /** If false, suppresses initialization effects (like passkey detection). Default true. */
12
+ enabled?: boolean;
26
13
  }
27
14
  interface UseFiberNodeResult {
28
15
  state: BrowserNodeState;
29
16
  node: FiberBrowserNode | null;
30
17
  nodeInfo: NodeInfoResult | null;
31
18
  error: string | null;
19
+ /** Whether the node is currently starting (unlocking or starting state) */
20
+ isStarting: boolean;
21
+ /** Whether the node is running and ready for RPC calls */
22
+ isRunning: boolean;
32
23
  isPasskeySupported: boolean;
33
24
  passkeySupportReason: PasskeySupportReason | null;
34
25
  passkeyUnavailableReason: string | null;
@@ -36,10 +27,106 @@ interface UseFiberNodeResult {
36
27
  startWithPassword: (password: string) => Promise<void>;
37
28
  createPasskeyAndStart: (username?: string) => Promise<void>;
38
29
  startWithPasskey: () => Promise<void>;
30
+ startWithRawKey: (fiberKey: Uint8Array, ckbSecretKey?: Uint8Array) => Promise<void>;
39
31
  stop: () => Promise<void>;
40
32
  }
41
33
  declare function useFiberNode(options: UseFiberNodeOptions): UseFiberNodeResult;
42
34
 
35
+ /** Credential strategy the ConnectButton should use */
36
+ type ConnectStrategy = 'passkey' | 'password' | 'rawKey' | 'auto';
37
+ interface ConnectButtonProps {
38
+ /** Network to connect to. Required in standalone mode; ignored when `fiber` is provided. */
39
+ network?: 'testnet' | 'mainnet';
40
+ /**
41
+ * Pre-existing hook result from `useFiberNode()`.
42
+ * When provided, the button delegates to this instead of creating its own hook.
43
+ */
44
+ fiber?: UseFiberNodeResult;
45
+ /** Credential strategy. Defaults to `"auto"`. */
46
+ strategy?: ConnectStrategy;
47
+ /** Password for the "password" strategy. */
48
+ password?: string;
49
+ /** Raw Fiber key (32 bytes) for the "rawKey" strategy. */
50
+ rawKey?: Uint8Array;
51
+ /** Raw CKB secret key (32 bytes) for the "rawKey" strategy (optional). */
52
+ rawCkbKey?: Uint8Array;
53
+ /** Wallet identifier for IndexedDB isolation. */
54
+ walletId?: string;
55
+ /** Display name for passkey registration. */
56
+ passkeyUsername?: string;
57
+ /** Optional WASM factory override. */
58
+ wasmFactory?: FiberWasmFactory;
59
+ /** Additional node config. */
60
+ nodeConfig?: UseFiberNodeOptions['nodeConfig'];
61
+ /** Additional CSS class name(s) for the root container. */
62
+ className?: string;
63
+ /** Inline styles for the root container. */
64
+ style?: CSSProperties;
65
+ /** Inline styles for the connected dropdown container. */
66
+ dropdownStyle?: CSSProperties;
67
+ /**
68
+ * Optional custom renderer for the connected dropdown content.
69
+ * Use this to render project-specific controls (for example peer/channel actions)
70
+ * while reusing the SDK's connect/disconnect lifecycle logic via the provided context.
71
+ * When set, this replaces the default dropdown content, so custom renderers must
72
+ * render their own disconnect UI if they want to expose disconnect actions.
73
+ */
74
+ renderConnectedDropdown?: (context: ConnectButtonConnectedDropdownContext) => ReactNode;
75
+ /**
76
+ * Called when the node reaches the "running" state.
77
+ * Receives the `FiberBrowserNode` instance and its `NodeInfoResult`.
78
+ */
79
+ onConnect?: (node: FiberBrowserNode, nodeInfo: NodeInfoResult) => void;
80
+ /** Called after the node is stopped. */
81
+ onDisconnect?: () => void;
82
+ /** Called when an error occurs. */
83
+ onError?: (error: string) => void;
84
+ }
85
+ interface ConnectButtonConnectedDropdownContext {
86
+ fiber: UseFiberNodeResult;
87
+ closeDropdown: () => void;
88
+ disconnect: () => Promise<void>;
89
+ }
90
+ declare function ConnectButton(props: ConnectButtonProps): react_jsx_runtime.JSX.Element;
91
+
92
+ interface FiberPayQuickCardProps {
93
+ network?: 'testnet' | 'mainnet';
94
+ walletId?: string;
95
+ passkeyUsername?: string;
96
+ title?: string;
97
+ className?: string;
98
+ style?: CSSProperties;
99
+ onInvoiceCreated?: (invoice: string) => void;
100
+ onPaymentResult?: (result: GetPaymentResult) => void;
101
+ onError?: (error: {
102
+ scope: 'node' | 'payment' | 'invoice';
103
+ message: string;
104
+ }) => void;
105
+ }
106
+ declare function FiberPayQuickCard(props: FiberPayQuickCardProps): react_jsx_runtime.JSX.Element;
107
+
108
+ interface NodeInfoPanelProps {
109
+ /** The running FiberBrowserNode instance. */
110
+ node: FiberBrowserNode | null;
111
+ /** Network (needed for address derivation and RPC URL defaults). */
112
+ network: 'testnet' | 'mainnet';
113
+ /** How often to refresh stats (ms). Default: 15000. */
114
+ pollInterval?: number;
115
+ /** Whether to show a QR code of the CKB address. Requires `qrcode.react` to be installed. */
116
+ showQrCode?: boolean;
117
+ /**
118
+ * Optional QR code render function — allows consumers to bring their own QR library.
119
+ * Called with the CKB address string. If not provided and `showQrCode` is true,
120
+ * the component will attempt to dynamically import `qrcode.react`.
121
+ */
122
+ renderQrCode?: (value: string) => ReactNode;
123
+ /** Additional CSS class name(s). */
124
+ className?: string;
125
+ /** Inline styles. */
126
+ style?: CSSProperties;
127
+ }
128
+ declare function NodeInfoPanel(props: NodeInfoPanelProps): react_jsx_runtime.JSX.Element;
129
+
43
130
  interface UseFiberPaymentResult {
44
131
  payInvoice: (invoice: string) => Promise<void>;
45
132
  isPaying: boolean;
@@ -48,4 +135,4 @@ interface UseFiberPaymentResult {
48
135
  }
49
136
  declare function useFiberPayment(node: FiberBrowserNode | null): UseFiberPaymentResult;
50
137
 
51
- export { FiberPayQuickCard, type FiberPayQuickCardProps, type UseFiberNodeOptions, type UseFiberNodeResult, type UseFiberPaymentResult, useFiberNode, useFiberPayment };
138
+ export { ConnectButton, type ConnectButtonConnectedDropdownContext, type ConnectButtonProps, type ConnectStrategy, FiberPayQuickCard, type FiberPayQuickCardProps, NodeInfoPanel, type NodeInfoPanelProps, type UseFiberNodeOptions, type UseFiberNodeResult, type UseFiberPaymentResult, useFiberNode, useFiberPayment };