@fiber-pay/react 0.2.5 → 0.2.6
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 +232 -1
- package/dist/index.d.ts +225 -5
- package/dist/index.js +2604 -269
- package/dist/index.js.map +1 -1
- package/package.json +11 -5
package/README.md
CHANGED
|
@@ -5,9 +5,63 @@ React hooks and components for browser payment flows on Fiber.
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
pnpm add @fiber-pay/react react
|
|
8
|
+
pnpm add @fiber-pay/react @nervosnetwork/fiber-js react
|
|
9
|
+
# optional, for QR codes in NodeInfoPanel
|
|
10
|
+
pnpm add qrcode.react
|
|
9
11
|
```
|
|
10
12
|
|
|
13
|
+
`@nervosnetwork/fiber-js` is a peer dependency used by the browser WASM runtime.
|
|
14
|
+
If you provide a custom `wasmFactory`, you can manage that dependency yourself.
|
|
15
|
+
|
|
16
|
+
## Browser Requirements (WASM + Passkey)
|
|
17
|
+
|
|
18
|
+
For multithreaded WASM runtime (`SharedArrayBuffer`) in modern browsers, serve your app with:
|
|
19
|
+
|
|
20
|
+
- `Cross-Origin-Opener-Policy: same-origin`
|
|
21
|
+
- `Cross-Origin-Embedder-Policy: require-corp`
|
|
22
|
+
|
|
23
|
+
Without these headers, Fiber WASM startup may fail with browser/runtime errors.
|
|
24
|
+
|
|
25
|
+
Vite example:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
29
|
+
import { defineConfig, type Plugin } from 'vite';
|
|
30
|
+
import react from '@vitejs/plugin-react';
|
|
31
|
+
|
|
32
|
+
function crossOriginIsolation(): Plugin {
|
|
33
|
+
return {
|
|
34
|
+
name: 'cross-origin-isolation',
|
|
35
|
+
configureServer(server) {
|
|
36
|
+
server.middlewares.use((_req: IncomingMessage, res: ServerResponse, next: () => void) => {
|
|
37
|
+
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
|
|
38
|
+
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
|
|
39
|
+
next();
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default defineConfig({
|
|
46
|
+
plugins: [react(), crossOriginIsolation()],
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Note: `configureServer` only applies to Vite dev server. For production builds,
|
|
51
|
+
set these headers on your web server or CDN (for example Nginx, Cloudflare, Vercel).
|
|
52
|
+
|
|
53
|
+
## Bundle Size Notes
|
|
54
|
+
|
|
55
|
+
Browser Fiber WASM artifacts are large by nature. In the current examples, a production build includes
|
|
56
|
+
an additional ~14 MB JS chunk (~6.5 MB gzip) for WASM/runtime assets.
|
|
57
|
+
|
|
58
|
+
Recommended integration strategy:
|
|
59
|
+
|
|
60
|
+
- Lazy-mount payment-heavy UI (for example route-level split).
|
|
61
|
+
- Keep WASM-dependent flows behind user intent (open panel, start node, pay flow).
|
|
62
|
+
- Accept a separate large chunk for WASM and tune warnings with `build.chunkSizeWarningLimit` when needed.
|
|
63
|
+
- Document expected bundle budgets in your downstream app so this chunk is intentional, not surprising.
|
|
64
|
+
|
|
11
65
|
## One-line import
|
|
12
66
|
|
|
13
67
|
```tsx
|
|
@@ -24,15 +78,35 @@ export function App() {
|
|
|
24
78
|
}
|
|
25
79
|
```
|
|
26
80
|
|
|
81
|
+
For a complete browser passkey + payment walkthrough, see [docs/wasm-passkey-payment-component-quickstart.md](./docs/wasm-passkey-payment-component-quickstart.md).
|
|
82
|
+
|
|
27
83
|
## Component customization
|
|
28
84
|
|
|
29
85
|
`FiberPayQuickCard` supports lightweight integration hooks:
|
|
30
86
|
|
|
87
|
+
- `fiber` (reuse existing `useFiberNode()` session)
|
|
31
88
|
- `className`, `style`, `title`
|
|
32
89
|
- `onInvoiceCreated(invoice)`
|
|
33
90
|
- `onPaymentResult(result)`
|
|
34
91
|
- `onError({ scope, message })`
|
|
35
92
|
|
|
93
|
+
When you already manage connection state (for example with `ConnectButton`), pass the same hook result into `FiberPayQuickCard` so invoices and payments run on the same node session:
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import { ConnectButton, FiberPayQuickCard, useFiberNode } from '@fiber-pay/react';
|
|
97
|
+
|
|
98
|
+
export function UnifiedFlow() {
|
|
99
|
+
const fiber = useFiberNode({ network: 'testnet', walletId: 'demo-wallet' });
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<>
|
|
103
|
+
<ConnectButton fiber={fiber} strategy="passkey" />
|
|
104
|
+
<FiberPayQuickCard fiber={fiber} network="testnet" title="Quick Card" />
|
|
105
|
+
</>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
36
110
|
## ConnectButton
|
|
37
111
|
|
|
38
112
|
Use `ConnectButton` with an existing `useFiberNode` result for drop-in integration.
|
|
@@ -47,6 +121,118 @@ export function HeaderWallet() {
|
|
|
47
121
|
}
|
|
48
122
|
```
|
|
49
123
|
|
|
124
|
+
## FiberNodeButton
|
|
125
|
+
|
|
126
|
+
`FiberNodeButton` is a higher-level button + dropdown panel for day-to-day node operations.
|
|
127
|
+
It wraps `ConnectButton` and provides default sections for:
|
|
128
|
+
|
|
129
|
+
- Connection state and disconnect
|
|
130
|
+
- Channel management (peer connect / open channel)
|
|
131
|
+
- Payment management (create invoice / pay invoice)
|
|
132
|
+
- Optional connector section (custom renderer)
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
import { FiberNodeButton, useFiberNode } from '@fiber-pay/react';
|
|
136
|
+
|
|
137
|
+
export function WalletEntry() {
|
|
138
|
+
const fiber = useFiberNode({ network: 'testnet', walletId: 'demo-wallet' });
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<FiberNodeButton
|
|
142
|
+
fiber={fiber}
|
|
143
|
+
strategy="passkey"
|
|
144
|
+
onLog={(message) => console.log(message)}
|
|
145
|
+
/>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
For external funding, pass `externalFunding` with an async `resolve` callback that returns
|
|
151
|
+
`signFundingTx` and optional script / dep overrides.
|
|
152
|
+
|
|
153
|
+
If you use CCC wallets, `@fiber-pay/sdk/browser` provides
|
|
154
|
+
`createCccExternalFundingResolver(...)` so you do not need to handwrite resolve logic:
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
import { ccc } from '@ckb-ccc/connector-react';
|
|
158
|
+
import { createCccExternalFundingResolver } from '@fiber-pay/sdk/browser';
|
|
159
|
+
|
|
160
|
+
const resolveExternalFunding = createCccExternalFundingResolver({
|
|
161
|
+
signer: cccSigner,
|
|
162
|
+
knownScripts: Object.values(ccc.KnownScript),
|
|
163
|
+
ckbRpcUrl: 'https://testnet.ckbapp.dev/',
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Customizing The Panel
|
|
168
|
+
|
|
169
|
+
`FiberNodeButton` now supports additive panel customization without forking the component:
|
|
170
|
+
|
|
171
|
+
- `tabs`: reorder / hide built-in tabs and add custom tabs
|
|
172
|
+
- `renderTabContent(tabId, context)`: override tab body rendering
|
|
173
|
+
- `renderAction(context)`: replace default action button UI/behavior for selected actions (context includes `state`)
|
|
174
|
+
- `t(key, fallback, vars?)`: localize labels and copy
|
|
175
|
+
|
|
176
|
+
Render precedence for a tab body is:
|
|
177
|
+
1. `renderTabContent(tabId, context)` when it returns a value other than `undefined`
|
|
178
|
+
2. `tabs[i].render(context)` for the selected tab (including built-in tab ids)
|
|
179
|
+
3. built-in tab body (`Workbench`, `Channels`, `Diagnostics`)
|
|
180
|
+
|
|
181
|
+
`renderTabContent` semantics:
|
|
182
|
+
- return `undefined` to fall back to the next renderer
|
|
183
|
+
- return `null` to intentionally render an empty tab body
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
import { FiberNodeButton, useFiberNode } from '@fiber-pay/react';
|
|
187
|
+
|
|
188
|
+
export function CustomPanelDemo() {
|
|
189
|
+
const fiber = useFiberNode({ network: 'testnet', walletId: 'custom-panel-demo' });
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<FiberNodeButton
|
|
193
|
+
fiber={fiber}
|
|
194
|
+
strategy="passkey"
|
|
195
|
+
tabs={[
|
|
196
|
+
{ id: 'workbench' },
|
|
197
|
+
{
|
|
198
|
+
id: 'my-stats',
|
|
199
|
+
label: 'My Stats',
|
|
200
|
+
render: ({ state }) => <div>Peers: {state.connectedPeers.length}</div>,
|
|
201
|
+
},
|
|
202
|
+
{ id: 'channels' },
|
|
203
|
+
{ id: 'diagnostics', hidden: true },
|
|
204
|
+
]}
|
|
205
|
+
renderAction={({ id, defaultProps }) => {
|
|
206
|
+
if (id !== 'pay-invoice') {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<button
|
|
212
|
+
type="button"
|
|
213
|
+
disabled={defaultProps.disabled}
|
|
214
|
+
onClick={() => {
|
|
215
|
+
void defaultProps.onTrigger();
|
|
216
|
+
}}
|
|
217
|
+
>
|
|
218
|
+
{defaultProps.loading ? 'Paying...' : 'Pay Now'}
|
|
219
|
+
</button>
|
|
220
|
+
);
|
|
221
|
+
}}
|
|
222
|
+
t={(key, fallback) => {
|
|
223
|
+
const zh: Record<string, string> = {
|
|
224
|
+
'tabs.workbench': '操作台',
|
|
225
|
+
'tabs.channels': '通道',
|
|
226
|
+
'actions.payInvoice': '立即支付',
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
return zh[key] ?? fallback;
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
50
236
|
`ConnectButton` uses explicit strategy selection and supports only `"passkey"` or `"password"`.
|
|
51
237
|
|
|
52
238
|
For custom connected-state panels (for example peer/channel controls), use `renderConnectedDropdown`:
|
|
@@ -78,3 +264,48 @@ For custom connected-state panels (for example peer/channel controls), use `rend
|
|
|
78
264
|
- `useFiberPayment(node)`
|
|
79
265
|
|
|
80
266
|
`useFiberNode` exposes passkey/password startup, node lifecycle methods, and passkey diagnostics (`passkeySupportReason`, `passkeyUnavailableReason`).
|
|
267
|
+
|
|
268
|
+
`useFiberPayment` supports both convenience and staged flows:
|
|
269
|
+
|
|
270
|
+
- `payInvoice(invoice)` (parse + send + wait in one call)
|
|
271
|
+
- `parseInvoice(invoice)`
|
|
272
|
+
- `sendPayment(invoice)`
|
|
273
|
+
- `waitForPayment(paymentHash)`
|
|
274
|
+
|
|
275
|
+
Staged flow example:
|
|
276
|
+
|
|
277
|
+
```tsx
|
|
278
|
+
const { parseInvoice, sendPayment, waitForPayment, error } = useFiberPayment(node);
|
|
279
|
+
|
|
280
|
+
const confirmAndPay = async (invoice: string) => {
|
|
281
|
+
const parsed = await parseInvoice(invoice);
|
|
282
|
+
// Render your own confirmation UI before actually sending
|
|
283
|
+
console.log('Will pay hash:', parsed.invoice.data.payment_hash);
|
|
284
|
+
|
|
285
|
+
await sendPayment(invoice);
|
|
286
|
+
const result = await waitForPayment(parsed.invoice.data.payment_hash);
|
|
287
|
+
console.log('Payment status:', result.status);
|
|
288
|
+
};
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Error Recovery Pattern
|
|
292
|
+
|
|
293
|
+
If `useFiberNode` startup fails, `state` may enter `error` and `error` will contain the raw failure message.
|
|
294
|
+
You can retry with the same hook instance (no unmount/remount required):
|
|
295
|
+
|
|
296
|
+
```tsx
|
|
297
|
+
const { state, error, startWithPasskey, startWithPassword } = useFiberNode({
|
|
298
|
+
network: 'testnet',
|
|
299
|
+
walletId: 'demo-wallet',
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
const retry = async () => {
|
|
303
|
+
if (state === 'error') {
|
|
304
|
+
await startWithPasskey();
|
|
305
|
+
// or: await startWithPassword('your-password');
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
For production UIs, map `error` to actionable guidance (for example: COOP/COEP missing, invalid password,
|
|
311
|
+
passkey canceled, secure-context requirement).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { BrowserNodeState, FiberBrowserNode, NodeInfoResult, PasskeySupportReason, FiberBrowserNodeConfig, FiberWasmFactory, GetPaymentResult } from '@fiber-pay/sdk/browser';
|
|
1
|
+
import { BrowserNodeState, FiberBrowserNode, NodeInfoResult, PasskeySupportReason, FiberBrowserNodeConfig, FiberWasmFactory, Script, CellDep, HexString, IFiberClient, Channel, GetPaymentResult, ListPeersResult, GraphNodesResult, GraphChannelsResult, ParseInvoiceResult, SendPaymentResult, PaymentHash } from '@fiber-pay/sdk/browser';
|
|
2
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';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
import { CSSProperties, ReactNode } from 'react';
|
|
4
|
+
import { CSSProperties, ReactNode, Dispatch, SetStateAction } from 'react';
|
|
5
5
|
|
|
6
6
|
interface UseFiberNodeOptions {
|
|
7
7
|
network: 'testnet' | 'mainnet';
|
|
8
8
|
walletId?: string;
|
|
9
9
|
nodeConfig?: FiberBrowserNodeConfig['nodeConfig'];
|
|
10
10
|
wasmFactory?: FiberWasmFactory;
|
|
11
|
+
/** If true, CKB signing key is omitted and external wallet is expected for funding/signing. */
|
|
12
|
+
externalWallet?: boolean;
|
|
11
13
|
/** If false, suppresses initialization effects (like passkey detection). Default true. */
|
|
12
14
|
enabled?: boolean;
|
|
13
15
|
}
|
|
@@ -42,8 +44,13 @@ interface ConnectButtonProps {
|
|
|
42
44
|
* When provided, the button delegates to this instead of creating its own hook.
|
|
43
45
|
*/
|
|
44
46
|
fiber?: UseFiberNodeResult;
|
|
45
|
-
/** Credential strategy.
|
|
46
|
-
strategy
|
|
47
|
+
/** Credential strategy. Defaults to `"passkey"`. */
|
|
48
|
+
strategy?: ConnectStrategy;
|
|
49
|
+
/**
|
|
50
|
+
* Enable external wallet mode (no internal CKB key derivation).
|
|
51
|
+
* Only applies when ConnectButton manages its own `useFiberNode` instance.
|
|
52
|
+
*/
|
|
53
|
+
externalWallet?: boolean;
|
|
47
54
|
/** Password for the "password" strategy. */
|
|
48
55
|
password?: string;
|
|
49
56
|
/** Wallet identifier for IndexedDB isolation. */
|
|
@@ -85,7 +92,217 @@ interface ConnectButtonConnectedDropdownContext {
|
|
|
85
92
|
}
|
|
86
93
|
declare function ConnectButton(props: ConnectButtonProps): react_jsx_runtime.JSX.Element;
|
|
87
94
|
|
|
95
|
+
interface ChannelOpenFlowParams {
|
|
96
|
+
pubkey: string;
|
|
97
|
+
fundingAmountCkb: string;
|
|
98
|
+
externalWallet: boolean;
|
|
99
|
+
shutdownScript?: Script;
|
|
100
|
+
fundingLockScript?: Script;
|
|
101
|
+
fundingLockScriptCellDeps?: CellDep[];
|
|
102
|
+
signFundingTx?: (txForSigner: unknown) => Promise<unknown>;
|
|
103
|
+
ckbRpcUrl?: string;
|
|
104
|
+
}
|
|
105
|
+
interface ChannelOpenFlowResult {
|
|
106
|
+
mode: 'internal' | 'external';
|
|
107
|
+
channelId: HexString;
|
|
108
|
+
fundingTxHash?: HexString;
|
|
109
|
+
unsignedFundingTx?: unknown;
|
|
110
|
+
signedFundingTx?: Record<string, unknown>;
|
|
111
|
+
}
|
|
112
|
+
interface UseChannelOpenFlowOptions {
|
|
113
|
+
node: IFiberClient | null;
|
|
114
|
+
onLog?: (message: string) => void;
|
|
115
|
+
}
|
|
116
|
+
interface UseChannelOpenFlowResult {
|
|
117
|
+
openChannel: (params: ChannelOpenFlowParams) => Promise<ChannelOpenFlowResult | null>;
|
|
118
|
+
reset: () => void;
|
|
119
|
+
isOpening: boolean;
|
|
120
|
+
error: string | null;
|
|
121
|
+
diagnostic: string | null;
|
|
122
|
+
suggestedFundingAmountCkb: string | null;
|
|
123
|
+
lastResult: ChannelOpenFlowResult | null;
|
|
124
|
+
}
|
|
125
|
+
declare function useChannelOpenFlow(options: UseChannelOpenFlowOptions): UseChannelOpenFlowResult;
|
|
126
|
+
|
|
127
|
+
interface PanelStatusNotice {
|
|
128
|
+
tone: 'info' | 'success';
|
|
129
|
+
text: string;
|
|
130
|
+
}
|
|
131
|
+
interface PanelChannelCounts {
|
|
132
|
+
active: number;
|
|
133
|
+
pending: number;
|
|
134
|
+
closed: number;
|
|
135
|
+
all: number;
|
|
136
|
+
}
|
|
137
|
+
interface FiberNodeButtonPanelState {
|
|
138
|
+
activeTab: PanelTab;
|
|
139
|
+
switchTab: (next: PanelTab) => void;
|
|
140
|
+
tabPanelId: string;
|
|
141
|
+
peerPubkey: string;
|
|
142
|
+
setPeerPubkey: Dispatch<SetStateAction<string>>;
|
|
143
|
+
peerAddress: string;
|
|
144
|
+
setPeerAddress: Dispatch<SetStateAction<string>>;
|
|
145
|
+
fundingAmountCkb: string;
|
|
146
|
+
setFundingAmountCkb: Dispatch<SetStateAction<string>>;
|
|
147
|
+
peerListId: string;
|
|
148
|
+
connectedPeers: PeerInfo[];
|
|
149
|
+
isRefreshingPeers: boolean;
|
|
150
|
+
isConnectingPeer: boolean;
|
|
151
|
+
refreshConnectedPeers: () => Promise<void>;
|
|
152
|
+
connectPeerByAddress: () => Promise<void>;
|
|
153
|
+
graphNodes: GraphNodeInfo[];
|
|
154
|
+
graphChannels: GraphChannelInfo[];
|
|
155
|
+
isRefreshingGraph: boolean;
|
|
156
|
+
refreshGraph: () => Promise<void>;
|
|
157
|
+
channels: Channel[];
|
|
158
|
+
channelFilter: ChannelFilter;
|
|
159
|
+
setChannelFilter: Dispatch<SetStateAction<ChannelFilter>>;
|
|
160
|
+
isRefreshingChannels: boolean;
|
|
161
|
+
refreshChannels: () => Promise<void>;
|
|
162
|
+
closeChannel: (channelId: string, force?: boolean) => Promise<void>;
|
|
163
|
+
selectedChannelId: string | null;
|
|
164
|
+
setSelectedChannelId: Dispatch<SetStateAction<string | null>>;
|
|
165
|
+
selectedChannel: Channel | null;
|
|
166
|
+
selectedPending: boolean;
|
|
167
|
+
selectedCanClose: boolean;
|
|
168
|
+
selectedIsClosing: boolean;
|
|
169
|
+
forceCloseConfirmOpen: boolean;
|
|
170
|
+
setForceCloseConfirmOpen: Dispatch<SetStateAction<boolean>>;
|
|
171
|
+
channelCounts: PanelChannelCounts;
|
|
172
|
+
visibleChannels: Channel[];
|
|
173
|
+
activeChannelCount: number;
|
|
174
|
+
invoiceInput: string;
|
|
175
|
+
setInvoiceInput: Dispatch<SetStateAction<string>>;
|
|
176
|
+
createdInvoice: string;
|
|
177
|
+
isCreatingInvoice: boolean;
|
|
178
|
+
createInvoice: () => Promise<void>;
|
|
179
|
+
submitPayment: () => Promise<void>;
|
|
180
|
+
isPaying: boolean;
|
|
181
|
+
paymentResult: GetPaymentResult | null;
|
|
182
|
+
channelOpenFlow: UseChannelOpenFlowResult;
|
|
183
|
+
openChannel: () => Promise<void>;
|
|
184
|
+
latestError: string | null;
|
|
185
|
+
statusNotice: PanelStatusNotice | null;
|
|
186
|
+
refreshDiagnostics: () => Promise<void>;
|
|
187
|
+
isNodeReady: boolean;
|
|
188
|
+
connectorContext: FiberNodeButtonConnectorSectionContext;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
type ChannelFilter = 'active' | 'pending' | 'closed' | 'all';
|
|
192
|
+
type PanelTab = string;
|
|
193
|
+
type FiberNodeButtonTabId = PanelTab;
|
|
194
|
+
type GraphChannelInfo = GraphChannelsResult['channels'][number];
|
|
195
|
+
type GraphNodeInfo = GraphNodesResult['nodes'][number];
|
|
196
|
+
type PeerInfo = ListPeersResult['peers'][number];
|
|
197
|
+
type FiberNodeButtonI18n = (key: string, fallback: string, vars?: Record<string, string | number>) => string;
|
|
198
|
+
type FiberNodeButtonActionId = 'open-channel' | 'create-invoice' | 'pay-invoice' | 'close-channel' | 'force-close-channel';
|
|
199
|
+
interface FiberNodeButtonActionDefaultPropsBase {
|
|
200
|
+
label: string;
|
|
201
|
+
loadingLabel?: string;
|
|
202
|
+
disabled: boolean;
|
|
203
|
+
loading?: boolean;
|
|
204
|
+
onTrigger: () => void | Promise<void>;
|
|
205
|
+
}
|
|
206
|
+
interface FiberNodeButtonOpenChannelActionDefaultProps extends FiberNodeButtonActionDefaultPropsBase {
|
|
207
|
+
id: 'open-channel';
|
|
208
|
+
}
|
|
209
|
+
interface FiberNodeButtonCreateInvoiceActionDefaultProps extends FiberNodeButtonActionDefaultPropsBase {
|
|
210
|
+
id: 'create-invoice';
|
|
211
|
+
}
|
|
212
|
+
interface FiberNodeButtonPayInvoiceActionDefaultProps extends FiberNodeButtonActionDefaultPropsBase {
|
|
213
|
+
id: 'pay-invoice';
|
|
214
|
+
}
|
|
215
|
+
interface FiberNodeButtonCloseChannelActionDefaultProps extends FiberNodeButtonActionDefaultPropsBase {
|
|
216
|
+
id: 'close-channel';
|
|
217
|
+
channelId?: string;
|
|
218
|
+
}
|
|
219
|
+
interface FiberNodeButtonForceCloseChannelActionDefaultProps extends FiberNodeButtonActionDefaultPropsBase {
|
|
220
|
+
id: 'force-close-channel';
|
|
221
|
+
channelId?: string;
|
|
222
|
+
}
|
|
223
|
+
type FiberNodeButtonActionDefaultProps = FiberNodeButtonOpenChannelActionDefaultProps | FiberNodeButtonCreateInvoiceActionDefaultProps | FiberNodeButtonPayInvoiceActionDefaultProps | FiberNodeButtonCloseChannelActionDefaultProps | FiberNodeButtonForceCloseChannelActionDefaultProps;
|
|
224
|
+
interface FiberNodeButtonTabActions {
|
|
225
|
+
openChannel: () => Promise<void>;
|
|
226
|
+
createInvoice: () => Promise<void>;
|
|
227
|
+
payInvoice: () => Promise<void>;
|
|
228
|
+
closeChannel: (channelId: string) => Promise<void>;
|
|
229
|
+
forceCloseChannel: (channelId: string) => Promise<void>;
|
|
230
|
+
}
|
|
231
|
+
interface FiberNodeButtonTabContext {
|
|
232
|
+
fiber: UseFiberNodeResult;
|
|
233
|
+
state: FiberNodeButtonPanelState;
|
|
234
|
+
externalFundingEnabled: boolean;
|
|
235
|
+
t: FiberNodeButtonI18n;
|
|
236
|
+
actions: FiberNodeButtonTabActions;
|
|
237
|
+
}
|
|
238
|
+
interface FiberNodeButtonTabConfig {
|
|
239
|
+
id: FiberNodeButtonTabId;
|
|
240
|
+
label?: string | ((t: FiberNodeButtonI18n) => string);
|
|
241
|
+
hidden?: boolean;
|
|
242
|
+
render?: (context: FiberNodeButtonTabContext) => ReactNode;
|
|
243
|
+
}
|
|
244
|
+
interface FiberNodeButtonRenderActionContext {
|
|
245
|
+
id: FiberNodeButtonActionId;
|
|
246
|
+
defaultProps: FiberNodeButtonActionDefaultProps;
|
|
247
|
+
fiber: UseFiberNodeResult;
|
|
248
|
+
state: FiberNodeButtonPanelState;
|
|
249
|
+
t: FiberNodeButtonI18n;
|
|
250
|
+
}
|
|
251
|
+
type FiberNodeButtonRenderAction = (context: FiberNodeButtonRenderActionContext) => ReactNode | undefined;
|
|
252
|
+
interface FiberNodeButtonExternalFundingResolved {
|
|
253
|
+
signFundingTx: (txForSigner: unknown) => Promise<unknown>;
|
|
254
|
+
shutdownScript?: Script;
|
|
255
|
+
fundingLockScript?: Script;
|
|
256
|
+
fundingLockScriptCellDeps?: CellDep[];
|
|
257
|
+
ckbRpcUrl?: string;
|
|
258
|
+
}
|
|
259
|
+
interface FiberNodeButtonExternalFundingResolverContext {
|
|
260
|
+
node: FiberBrowserNode;
|
|
261
|
+
pubkey: HexString;
|
|
262
|
+
fundingAmountCkb: string;
|
|
263
|
+
}
|
|
264
|
+
interface FiberNodeButtonExternalFundingConfig {
|
|
265
|
+
enabled: boolean;
|
|
266
|
+
resolve: (context: FiberNodeButtonExternalFundingResolverContext) => Promise<FiberNodeButtonExternalFundingResolved>;
|
|
267
|
+
}
|
|
268
|
+
interface FiberNodeButtonConnectorSectionContext {
|
|
269
|
+
fiber: UseFiberNodeResult;
|
|
270
|
+
externalFundingEnabled: boolean;
|
|
271
|
+
isOpeningChannel: boolean;
|
|
272
|
+
}
|
|
273
|
+
interface FiberNodeButtonProps {
|
|
274
|
+
network?: 'testnet' | 'mainnet';
|
|
275
|
+
fiber?: UseFiberNodeResult;
|
|
276
|
+
strategy?: ConnectStrategy;
|
|
277
|
+
externalWallet?: boolean;
|
|
278
|
+
password?: string;
|
|
279
|
+
walletId?: string;
|
|
280
|
+
passkeyUsername?: string;
|
|
281
|
+
wasmFactory?: FiberWasmFactory;
|
|
282
|
+
nodeConfig?: UseFiberNodeOptions['nodeConfig'];
|
|
283
|
+
className?: string;
|
|
284
|
+
style?: CSSProperties;
|
|
285
|
+
dropdownStyle?: CSSProperties;
|
|
286
|
+
onConnect?: (node: FiberBrowserNode, nodeInfo: NodeInfoResult) => void;
|
|
287
|
+
onDisconnect?: () => void;
|
|
288
|
+
onError?: (error: string) => void;
|
|
289
|
+
onLog?: (message: string) => void;
|
|
290
|
+
initialPeerPubkey?: string;
|
|
291
|
+
initialPeerAddress?: string;
|
|
292
|
+
initialFundingAmountCkb?: string;
|
|
293
|
+
externalFunding?: FiberNodeButtonExternalFundingConfig;
|
|
294
|
+
renderConnectorSection?: (context: FiberNodeButtonConnectorSectionContext) => ReactNode;
|
|
295
|
+
tabs?: ReadonlyArray<FiberNodeButtonTabConfig>;
|
|
296
|
+
renderTabContent?: (tabId: FiberNodeButtonTabId, context: FiberNodeButtonTabContext) => ReactNode | undefined;
|
|
297
|
+
renderAction?: FiberNodeButtonRenderAction;
|
|
298
|
+
t?: FiberNodeButtonI18n;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
declare function FiberNodeButton(props: FiberNodeButtonProps): react_jsx_runtime.JSX.Element;
|
|
302
|
+
|
|
88
303
|
interface FiberPayQuickCardProps {
|
|
304
|
+
/** Reuse an existing useFiberNode() result instead of creating a new session. */
|
|
305
|
+
fiber?: UseFiberNodeResult;
|
|
89
306
|
network?: 'testnet' | 'mainnet';
|
|
90
307
|
walletId?: string;
|
|
91
308
|
passkeyUsername?: string;
|
|
@@ -124,6 +341,9 @@ interface NodeInfoPanelProps {
|
|
|
124
341
|
declare function NodeInfoPanel(props: NodeInfoPanelProps): react_jsx_runtime.JSX.Element;
|
|
125
342
|
|
|
126
343
|
interface UseFiberPaymentResult {
|
|
344
|
+
parseInvoice: (invoice: string) => Promise<ParseInvoiceResult>;
|
|
345
|
+
sendPayment: (invoice: string) => Promise<SendPaymentResult>;
|
|
346
|
+
waitForPayment: (paymentHash: PaymentHash) => Promise<GetPaymentResult>;
|
|
127
347
|
payInvoice: (invoice: string) => Promise<void>;
|
|
128
348
|
isPaying: boolean;
|
|
129
349
|
paymentResult: GetPaymentResult | null;
|
|
@@ -131,4 +351,4 @@ interface UseFiberPaymentResult {
|
|
|
131
351
|
}
|
|
132
352
|
declare function useFiberPayment(node: FiberBrowserNode | null): UseFiberPaymentResult;
|
|
133
353
|
|
|
134
|
-
export { ConnectButton, type ConnectButtonConnectedDropdownContext, type ConnectButtonProps, type ConnectStrategy, FiberPayQuickCard, type FiberPayQuickCardProps, NodeInfoPanel, type NodeInfoPanelProps, type UseFiberNodeOptions, type UseFiberNodeResult, type UseFiberPaymentResult, useFiberNode, useFiberPayment };
|
|
354
|
+
export { type ChannelOpenFlowParams, type ChannelOpenFlowResult, ConnectButton, type ConnectButtonConnectedDropdownContext, type ConnectButtonProps, type ConnectStrategy, FiberNodeButton, type FiberNodeButtonActionDefaultProps, type FiberNodeButtonActionId, type FiberNodeButtonConnectorSectionContext, type FiberNodeButtonExternalFundingConfig, type FiberNodeButtonExternalFundingResolved, type FiberNodeButtonExternalFundingResolverContext, type FiberNodeButtonI18n, type FiberNodeButtonProps, type FiberNodeButtonRenderAction, type FiberNodeButtonRenderActionContext, type FiberNodeButtonTabActions, type FiberNodeButtonTabConfig, type FiberNodeButtonTabContext, type FiberNodeButtonTabId, FiberPayQuickCard, type FiberPayQuickCardProps, NodeInfoPanel, type NodeInfoPanelProps, type UseChannelOpenFlowOptions, type UseChannelOpenFlowResult, type UseFiberNodeOptions, type UseFiberNodeResult, type UseFiberPaymentResult, useChannelOpenFlow, useFiberNode, useFiberPayment };
|