@fiber-pay/react 0.2.3 → 0.2.5
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 +40 -1
- package/dist/index.d.ts +102 -19
- package/dist/index.js +877 -56
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
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,45 @@ 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} strategy="passkey" />;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`ConnectButton` uses explicit strategy selection and supports only `"passkey"` or `"password"`.
|
|
51
|
+
|
|
52
|
+
For custom connected-state panels (for example peer/channel controls), use `renderConnectedDropdown`:
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
<ConnectButton
|
|
56
|
+
fiber={fiber}
|
|
57
|
+
strategy="passkey"
|
|
58
|
+
dropdownStyle={{ width: 320 }}
|
|
59
|
+
renderConnectedDropdown={({ fiber, disconnect }) => (
|
|
60
|
+
<div>
|
|
61
|
+
<div>State: {fiber.state}</div>
|
|
62
|
+
<button
|
|
63
|
+
type="button"
|
|
64
|
+
onClick={() => {
|
|
65
|
+
void disconnect();
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
Disconnect
|
|
69
|
+
</button>
|
|
70
|
+
</div>
|
|
71
|
+
)}
|
|
72
|
+
/>
|
|
73
|
+
```
|
|
74
|
+
|
|
36
75
|
## Hooks
|
|
37
76
|
|
|
38
77
|
- `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 {
|
|
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,102 @@ 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';
|
|
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. Explicitly choose either `"passkey"` or `"password"`. */
|
|
46
|
+
strategy: ConnectStrategy;
|
|
47
|
+
/** Password for the "password" strategy. */
|
|
48
|
+
password?: string;
|
|
49
|
+
/** Wallet identifier for IndexedDB isolation. */
|
|
50
|
+
walletId?: string;
|
|
51
|
+
/** Display name for passkey registration. */
|
|
52
|
+
passkeyUsername?: string;
|
|
53
|
+
/** Optional WASM factory override. */
|
|
54
|
+
wasmFactory?: FiberWasmFactory;
|
|
55
|
+
/** Additional node config. */
|
|
56
|
+
nodeConfig?: UseFiberNodeOptions['nodeConfig'];
|
|
57
|
+
/** Additional CSS class name(s) for the root container. */
|
|
58
|
+
className?: string;
|
|
59
|
+
/** Inline styles for the root container. */
|
|
60
|
+
style?: CSSProperties;
|
|
61
|
+
/** Inline styles for the connected dropdown container. */
|
|
62
|
+
dropdownStyle?: CSSProperties;
|
|
63
|
+
/**
|
|
64
|
+
* Optional custom renderer for the connected dropdown content.
|
|
65
|
+
* Use this to render project-specific controls (for example peer/channel actions)
|
|
66
|
+
* while reusing the SDK's connect/disconnect lifecycle logic via the provided context.
|
|
67
|
+
* When set, this replaces the default dropdown content, so custom renderers must
|
|
68
|
+
* render their own disconnect UI if they want to expose disconnect actions.
|
|
69
|
+
*/
|
|
70
|
+
renderConnectedDropdown?: (context: ConnectButtonConnectedDropdownContext) => ReactNode;
|
|
71
|
+
/**
|
|
72
|
+
* Called when the node reaches the "running" state.
|
|
73
|
+
* Receives the `FiberBrowserNode` instance and its `NodeInfoResult`.
|
|
74
|
+
*/
|
|
75
|
+
onConnect?: (node: FiberBrowserNode, nodeInfo: NodeInfoResult) => void;
|
|
76
|
+
/** Called after the node is stopped. */
|
|
77
|
+
onDisconnect?: () => void;
|
|
78
|
+
/** Called when an error occurs. */
|
|
79
|
+
onError?: (error: string) => void;
|
|
80
|
+
}
|
|
81
|
+
interface ConnectButtonConnectedDropdownContext {
|
|
82
|
+
fiber: UseFiberNodeResult;
|
|
83
|
+
closeDropdown: () => void;
|
|
84
|
+
disconnect: () => Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
declare function ConnectButton(props: ConnectButtonProps): react_jsx_runtime.JSX.Element;
|
|
87
|
+
|
|
88
|
+
interface FiberPayQuickCardProps {
|
|
89
|
+
network?: 'testnet' | 'mainnet';
|
|
90
|
+
walletId?: string;
|
|
91
|
+
passkeyUsername?: string;
|
|
92
|
+
title?: string;
|
|
93
|
+
className?: string;
|
|
94
|
+
style?: CSSProperties;
|
|
95
|
+
onInvoiceCreated?: (invoice: string) => void;
|
|
96
|
+
onPaymentResult?: (result: GetPaymentResult) => void;
|
|
97
|
+
onError?: (error: {
|
|
98
|
+
scope: 'node' | 'payment' | 'invoice';
|
|
99
|
+
message: string;
|
|
100
|
+
}) => void;
|
|
101
|
+
}
|
|
102
|
+
declare function FiberPayQuickCard(props: FiberPayQuickCardProps): react_jsx_runtime.JSX.Element;
|
|
103
|
+
|
|
104
|
+
interface NodeInfoPanelProps {
|
|
105
|
+
/** The running FiberBrowserNode instance. */
|
|
106
|
+
node: FiberBrowserNode | null;
|
|
107
|
+
/** Network (needed for address derivation and RPC URL defaults). */
|
|
108
|
+
network: 'testnet' | 'mainnet';
|
|
109
|
+
/** How often to refresh stats (ms). Default: 15000. */
|
|
110
|
+
pollInterval?: number;
|
|
111
|
+
/** Whether to show a QR code of the CKB address. Requires `qrcode.react` to be installed. */
|
|
112
|
+
showQrCode?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Optional QR code render function — allows consumers to bring their own QR library.
|
|
115
|
+
* Called with the CKB address string. If not provided and `showQrCode` is true,
|
|
116
|
+
* the component will attempt to dynamically import `qrcode.react`.
|
|
117
|
+
*/
|
|
118
|
+
renderQrCode?: (value: string) => ReactNode;
|
|
119
|
+
/** Additional CSS class name(s). */
|
|
120
|
+
className?: string;
|
|
121
|
+
/** Inline styles. */
|
|
122
|
+
style?: CSSProperties;
|
|
123
|
+
}
|
|
124
|
+
declare function NodeInfoPanel(props: NodeInfoPanelProps): react_jsx_runtime.JSX.Element;
|
|
125
|
+
|
|
43
126
|
interface UseFiberPaymentResult {
|
|
44
127
|
payInvoice: (invoice: string) => Promise<void>;
|
|
45
128
|
isPaying: boolean;
|
|
@@ -48,4 +131,4 @@ interface UseFiberPaymentResult {
|
|
|
48
131
|
}
|
|
49
132
|
declare function useFiberPayment(node: FiberBrowserNode | null): UseFiberPaymentResult;
|
|
50
133
|
|
|
51
|
-
export { FiberPayQuickCard, type FiberPayQuickCardProps, type UseFiberNodeOptions, type UseFiberNodeResult, type UseFiberPaymentResult, useFiberNode, useFiberPayment };
|
|
134
|
+
export { ConnectButton, type ConnectButtonConnectedDropdownContext, type ConnectButtonProps, type ConnectStrategy, FiberPayQuickCard, type FiberPayQuickCardProps, NodeInfoPanel, type NodeInfoPanelProps, type UseFiberNodeOptions, type UseFiberNodeResult, type UseFiberPaymentResult, useFiberNode, useFiberPayment };
|