@ffaerber/swarm-connect 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Felix Faerber
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # swarm-connect
2
+
3
+ A React connect-button and wizard for [Ethereum Swarm](https://www.ethswarm.org/) on the [Gnosis](https://www.gnosis.io/) chain. Drop in a single `<SwarmConnectButton />` and let users connect their wallet, verify a running Bee node, and pick a postage stamp — all from one modal.
4
+
5
+ ## Features
6
+
7
+ - 🐝 **Bee node detection** — checks a Bee node's `/health` endpoint and surfaces its version.
8
+ - 🎟️ **Postage stamp selection** — fetches available stamps from `/stamps` and lets the user pick one.
9
+ - 🦊 **Wallet connect** — injected-wallet connection via [wagmi](https://wagmi.sh/), pinned to Gnosis chain (ID `100`).
10
+ - ✅ **At-a-glance status** — the button shows status dots for node, stamp, wallet, and network.
11
+ - 🧩 **Headless hooks** — use the `useSwarmConnect` / `useBeeNode` / `usePostageStamps` hooks to build your own UI.
12
+ - 🎨 **Zero-dependency styling** — inline styles, no CSS imports required.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @ffaerber/swarm-connect
18
+ ```
19
+
20
+ ### Peer dependencies
21
+
22
+ This package expects the following to be installed in your app:
23
+
24
+ ```bash
25
+ npm install react react-dom wagmi viem @tanstack/react-query
26
+ ```
27
+
28
+ | Package | Version |
29
+ | --- | --- |
30
+ | `react` | `>=18` |
31
+ | `react-dom` | `>=18` |
32
+ | `wagmi` | `>=2` |
33
+ | `viem` | `>=2` |
34
+ | `@tanstack/react-query` | `>=5` |
35
+
36
+ ## Quick start
37
+
38
+ Wrap your app in `SwarmConnectProvider` and drop in the button:
39
+
40
+ ```tsx
41
+ import { SwarmConnectProvider, SwarmConnectButton } from '@ffaerber/swarm-connect'
42
+
43
+ export function App() {
44
+ return (
45
+ <SwarmConnectProvider>
46
+ <SwarmConnectButton beeApiUrl="http://localhost:1633" />
47
+ </SwarmConnectProvider>
48
+ )
49
+ }
50
+ ```
51
+
52
+ `SwarmConnectProvider` sets up wagmi (Gnosis chain + injected connector) and a React Query client for you. If your app already has its own `WagmiProvider` and `QueryClientProvider`, you can skip the provider and use `SwarmConnectButton` directly.
53
+
54
+ ## Components
55
+
56
+ ### `<SwarmConnectProvider>`
57
+
58
+ Provides the wagmi and React Query context. Configured for the Gnosis chain with an injected connector.
59
+
60
+ | Prop | Type | Description |
61
+ | --- | --- | --- |
62
+ | `children` | `ReactNode` | Your app. |
63
+ | `config` | `SwarmConnectConfig` | Optional configuration. |
64
+
65
+ ### `<SwarmConnectButton>`
66
+
67
+ The connect button. Opens a two-tab modal (**Swarm** for the Bee node + postage stamp, **Wallet** for connecting your wallet).
68
+
69
+ | Prop | Type | Default | Description |
70
+ | --- | --- | --- | --- |
71
+ | `beeApiUrl` | `string` | `http://localhost:1633` | Base URL of the Bee node API. |
72
+ | `label` | `string` | auto | Overrides the button label. Defaults to `Connect to Swarm`, or the truncated address once fully connected. |
73
+
74
+ ### `<SwarmConnectModal>`
75
+
76
+ The modal rendered by `SwarmConnectButton`. Exported for advanced use if you want to manage open/close state yourself.
77
+
78
+ ## Hooks
79
+
80
+ ### `useSwarmConnect(config?)`
81
+
82
+ The top-level hook combining node, stamp, wallet, and network state.
83
+
84
+ ```tsx
85
+ import { useSwarmConnect } from '@ffaerber/swarm-connect'
86
+
87
+ function Status() {
88
+ const {
89
+ beeNode, // { isRunning, isChecking, version?, error?, check() }
90
+ stamps, // { stamps, isLoading, error?, fetchStamps(), selectedStampId?, selectStamp() }
91
+ isWalletConnected,
92
+ address,
93
+ isOnGnosis,
94
+ chainId,
95
+ isFullyConnected, // node running + stamp selected + wallet connected + on Gnosis
96
+ } = useSwarmConnect({ beeApiUrl: 'http://localhost:1633' })
97
+
98
+ return <span>{isFullyConnected ? 'Ready' : 'Not connected'}</span>
99
+ }
100
+ ```
101
+
102
+ ### `useBeeNode(beeApiUrl?)`
103
+
104
+ Checks a Bee node's health.
105
+
106
+ ```tsx
107
+ const { isRunning, isChecking, version, error, check } = useBeeNode('http://localhost:1633')
108
+ ```
109
+
110
+ ### `usePostageStamps(beeApiUrl?)`
111
+
112
+ Fetches and selects postage stamps.
113
+
114
+ ```tsx
115
+ const { stamps, isLoading, error, fetchStamps, selectedStampId, selectStamp } =
116
+ usePostageStamps('http://localhost:1633')
117
+ ```
118
+
119
+ ## Configuration
120
+
121
+ ```ts
122
+ interface SwarmConnectConfig {
123
+ beeApiUrl?: string // defaults to http://localhost:1633
124
+ }
125
+ ```
126
+
127
+ "Fully connected" requires all of the following:
128
+
129
+ 1. A reachable Bee node (`/health` responds OK).
130
+ 2. A selected postage stamp.
131
+ 3. A connected wallet.
132
+ 4. The wallet on the Gnosis chain (chain ID `100`).
133
+
134
+ ## Development
135
+
136
+ ```bash
137
+ npm install
138
+ npm run dev # start Vite dev server
139
+ npm run type-check # type-check without emitting
140
+ npm run build # build the library + type declarations to dist/
141
+ ```
142
+
143
+ The library is built with Vite in library mode and ships ESM (`swarm-connect.js`), CommonJS (`swarm-connect.umd.cjs`), and TypeScript declarations. `react`, `react-dom`, `wagmi`, `viem`, and `@tanstack/react-query` are externalized.
144
+
145
+ ## License
146
+
147
+ MIT
@@ -0,0 +1,6 @@
1
+ import { SwarmConnectConfig } from '../types';
2
+ interface SwarmConnectButtonProps extends SwarmConnectConfig {
3
+ label?: string;
4
+ }
5
+ export declare function SwarmConnectButton({ beeApiUrl, label }: SwarmConnectButtonProps): import("react").JSX.Element;
6
+ export {};
@@ -0,0 +1,11 @@
1
+ import { BeeNodeStatus, PostageStampsState } from '../types';
2
+ interface SwarmConnectModalProps {
3
+ onClose: () => void;
4
+ beeNode: BeeNodeStatus & {
5
+ check: () => void;
6
+ };
7
+ stamps: PostageStampsState;
8
+ beeApiUrl: string;
9
+ }
10
+ export declare function SwarmConnectModal({ onClose, beeNode, stamps, beeApiUrl }: SwarmConnectModalProps): import("react").JSX.Element;
11
+ export {};
@@ -0,0 +1,10 @@
1
+ import { BeeNodeStatus, PostageStampsState } from '../../types';
2
+ interface SwarmTabProps {
3
+ beeApiUrl: string;
4
+ beeNode: BeeNodeStatus & {
5
+ check: () => void;
6
+ };
7
+ stamps: PostageStampsState;
8
+ }
9
+ export declare function SwarmTab({ beeApiUrl, beeNode, stamps }: SwarmTabProps): import("react").JSX.Element;
10
+ export {};
@@ -0,0 +1 @@
1
+ export declare function WalletTab(): import("react").JSX.Element;
@@ -0,0 +1,22 @@
1
+ export declare const GNOSIS_CHAIN_ID = 100;
2
+ export declare const DEFAULT_BEE_API_URL = "http://localhost:1633";
3
+ export declare const STYLES: {
4
+ readonly colors: {
5
+ readonly primary: "#1a56db";
6
+ readonly primaryHover: "#1e429f";
7
+ readonly success: "#0e9f6e";
8
+ readonly successLight: "#f0fdf4";
9
+ readonly error: "#f05252";
10
+ readonly errorLight: "#fff5f5";
11
+ readonly warning: "#ff8a4c";
12
+ readonly warningLight: "#fffbf5";
13
+ readonly border: "#e5e7eb";
14
+ readonly text: "#111827";
15
+ readonly muted: "#6b7280";
16
+ readonly bg: "#ffffff";
17
+ readonly overlay: "rgba(0,0,0,0.5)";
18
+ readonly stepInactive: "#d1d5db";
19
+ readonly stepActive: "#1a56db";
20
+ readonly stepDone: "#0e9f6e";
21
+ };
22
+ };
@@ -0,0 +1,8 @@
1
+ import { default as React } from 'react';
2
+ import { SwarmConnectConfig } from '../types';
3
+ interface SwarmConnectProviderProps {
4
+ children: React.ReactNode;
5
+ config?: SwarmConnectConfig;
6
+ }
7
+ export declare function SwarmConnectProvider({ children }: SwarmConnectProviderProps): React.JSX.Element;
8
+ export {};
@@ -0,0 +1,7 @@
1
+ export declare function useBeeNode(beeApiUrl?: string): {
2
+ check: () => Promise<void>;
3
+ isRunning: boolean;
4
+ isChecking: boolean;
5
+ version?: string;
6
+ error?: string;
7
+ };
@@ -0,0 +1,2 @@
1
+ import { PostageStampsState } from '../types';
2
+ export declare function usePostageStamps(beeApiUrl?: string): PostageStampsState;
@@ -0,0 +1,2 @@
1
+ import { SwarmConnectConfig, SwarmConnectState } from '../types';
2
+ export declare function useSwarmConnect(config?: SwarmConnectConfig): SwarmConnectState;
@@ -0,0 +1,7 @@
1
+ export { SwarmConnectButton } from './components/SwarmConnectButton';
2
+ export { SwarmConnectModal } from './components/SwarmConnectModal';
3
+ export { SwarmConnectProvider } from './context/SwarmConnectProvider';
4
+ export { useSwarmConnect } from './hooks/useSwarmConnect';
5
+ export { useBeeNode } from './hooks/useBeeNode';
6
+ export { usePostageStamps } from './hooks/usePostageStamps';
7
+ export type { SwarmConnectConfig, SwarmConnectState, BeeNodeStatus, PostageStamp, PostageStampsState, } from './types';