@pollar/stellar-wallets-kit-adapter 0.10.0-rc.10 → 0.10.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/README.md +96 -54
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @pollar/stellar-wallets-kit-adapter
|
|
2
2
|
|
|
3
|
-
Plug [Stellar Wallets Kit](https://stellarwalletskit.dev) into [`@pollar/core`](../core) as a
|
|
3
|
+
Plug [Stellar Wallets Kit](https://stellarwalletskit.dev) into [`@pollar/core`](../core) as a set of wallet adapters, without `@pollar/core` having to depend on the kit. One install gives Pollar access to **every wallet module the kit supports** — Freighter, Albedo, xBull, Lobstr, Rabet, Hana, Bitget, OneKey, Klever, Fordefi, CactusLink, HotWallet, plus Ledger / Trezor / WalletConnect via opt-in.
|
|
4
4
|
|
|
5
|
-
The
|
|
5
|
+
The adapters are registered through the `walletAdapters` slot on `PollarClientConfig`. `stellarWalletsKitAdapters()` returns a `WalletAdapter[]` (one adapter per kit module) that you spread into that array alongside any other adapters you register.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -16,46 +16,54 @@ npm install @pollar/stellar-wallets-kit-adapter @creit.tech/stellar-wallets-kit
|
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
import { PollarClient } from '@pollar/core';
|
|
19
|
-
import {
|
|
19
|
+
import { stellarWalletsKitAdapters } from '@pollar/stellar-wallets-kit-adapter';
|
|
20
20
|
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
21
21
|
|
|
22
22
|
const client = new PollarClient({
|
|
23
23
|
apiKey: 'your-api-key',
|
|
24
|
-
|
|
24
|
+
walletAdapters: stellarWalletsKitAdapters({ network: Networks.PUBLIC }),
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
//
|
|
28
|
-
client.
|
|
27
|
+
// Log in with one of the registered kit wallets
|
|
28
|
+
client.login({ provider: 'xbull' });
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
With React:
|
|
32
32
|
|
|
33
33
|
```tsx
|
|
34
34
|
import { PollarProvider } from '@pollar/react';
|
|
35
|
-
import {
|
|
35
|
+
import { stellarWalletsKitAdapters } from '@pollar/stellar-wallets-kit-adapter';
|
|
36
36
|
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
37
37
|
|
|
38
38
|
<PollarProvider
|
|
39
39
|
client={{
|
|
40
40
|
apiKey: 'your-api-key',
|
|
41
|
-
|
|
41
|
+
walletAdapters: stellarWalletsKitAdapters({ network: Networks.TESTNET }),
|
|
42
42
|
}}
|
|
43
43
|
>
|
|
44
44
|
{/* your app */}
|
|
45
45
|
</PollarProvider>;
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
>
|
|
48
|
+
Every wallet you register this way renders as its own button inside Pollar's
|
|
49
|
+
`LoginModal` (collapsed behind a shared "Wallet" gateway) - see
|
|
50
|
+
[Login UI](#login-ui) below.
|
|
51
|
+
|
|
52
|
+
The kit is a global singleton. `stellarWalletsKitAdapters(...)` returns a
|
|
53
|
+
`WalletAdapter[]` and runs `StellarWalletsKit.init(...)` synchronously at call
|
|
54
|
+
time (via `ensureInit()`), building one `StellarWalletsKitAdapter` per module up
|
|
55
|
+
front. It is not lazy - a later `login({ provider })` just routes to the
|
|
56
|
+
matching adapter that was already built.
|
|
57
|
+
|
|
58
|
+
> **0.10.0** - switched to the `walletAdapters[]` array model: the factory is now
|
|
59
|
+
> `stellarWalletsKitAdapters()` (was `stellarWalletsKit()`) and returns a
|
|
60
|
+
> `WalletAdapter[]` for the plural `walletAdapters` config slot instead of a
|
|
61
|
+
> single resolver for `walletAdapter`. SSR-safe: returns `[]` when there is no
|
|
62
|
+
> `window`. Requires `@pollar/core@^0.10.0` / `@pollar/react@^0.10.0`.
|
|
63
|
+
>
|
|
64
|
+
> **0.9.0** - `connect()` resolves to `{ address }` only (the duplicate
|
|
65
|
+
> `publicKey` field is gone, matching the new `ConnectWalletResponse`). Adds
|
|
66
|
+
> `logLevel` / `logger` options (set once at init - the kit is a global singleton).
|
|
59
67
|
>
|
|
60
68
|
> **0.8.0** — `network` is **required**. The previous `Networks.TESTNET`
|
|
61
69
|
> default was removed because the kit is a global singleton, and silently
|
|
@@ -64,7 +72,7 @@ The kit is a global singleton. `stellarWalletsKit(...)` returns a resolver and `
|
|
|
64
72
|
|
|
65
73
|
## Default wallets
|
|
66
74
|
|
|
67
|
-
Calling `
|
|
75
|
+
Calling `stellarWalletsKitAdapters({ network })` with no `modules` argument enables every module that loads without extra configuration (12 in total):
|
|
68
76
|
|
|
69
77
|
| Module | Wallet id (`WalletId`) | Type |
|
|
70
78
|
| ------------------ | ---------------------- | ------------------ |
|
|
@@ -88,7 +96,7 @@ Calling `stellarWalletsKit({ network })` with no `modules` argument enables ever
|
|
|
88
96
|
Pass your own `modules` list. Import from the kit's per-wallet subpaths so unused modules tree-shake out:
|
|
89
97
|
|
|
90
98
|
```ts
|
|
91
|
-
import {
|
|
99
|
+
import { stellarWalletsKitAdapters } from '@pollar/stellar-wallets-kit-adapter';
|
|
92
100
|
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
93
101
|
import { FreighterModule } from '@creit.tech/stellar-wallets-kit/modules/freighter';
|
|
94
102
|
import { xBullModule } from '@creit.tech/stellar-wallets-kit/modules/xbull';
|
|
@@ -96,7 +104,7 @@ import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wal
|
|
|
96
104
|
|
|
97
105
|
const client = new PollarClient({
|
|
98
106
|
apiKey: 'your-api-key',
|
|
99
|
-
|
|
107
|
+
walletAdapters: stellarWalletsKitAdapters({
|
|
100
108
|
network: Networks.PUBLIC,
|
|
101
109
|
modules: [
|
|
102
110
|
new FreighterModule(),
|
|
@@ -136,11 +144,22 @@ interface StellarWalletsKitAdapterOptions {
|
|
|
136
144
|
modules?: ModuleInterface[];
|
|
137
145
|
|
|
138
146
|
/**
|
|
139
|
-
* Picker-specific options
|
|
140
|
-
* `
|
|
141
|
-
*
|
|
147
|
+
* Picker-specific options: which kit wallets to include, label overrides, and
|
|
148
|
+
* the gateway group label. `wallets`, `labels`, and `groupLabel` are honored by
|
|
149
|
+
* `stellarWalletsKitAdapters()`; the remaining fields are consumed by the
|
|
150
|
+
* `/picker` subpath.
|
|
142
151
|
*/
|
|
143
152
|
picker?: KitPickerOptions;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Minimum log severity. `'silent'` disables logging; otherwise
|
|
156
|
+
* `error` < `warn` < `info` < `debug`. Defaults to `'info'`. Set once at init
|
|
157
|
+
* since the kit is a global singleton.
|
|
158
|
+
*/
|
|
159
|
+
logLevel?: LogLevel;
|
|
160
|
+
|
|
161
|
+
/** Sink for logs. Defaults to the global `console`. */
|
|
162
|
+
logger?: PollarLogger;
|
|
144
163
|
}
|
|
145
164
|
|
|
146
165
|
interface KitPickerOptions {
|
|
@@ -152,35 +171,55 @@ interface KitPickerOptions {
|
|
|
152
171
|
showInstalledOnly?: boolean;
|
|
153
172
|
/** Per-wallet label overrides. Key = wallet id. */
|
|
154
173
|
labels?: Record<string, string>;
|
|
174
|
+
/**
|
|
175
|
+
* Label of the gateway button the kit wallets collapse behind in the login UI
|
|
176
|
+
* (applied as each adapter's `meta.group`). Default `'Wallet'` - the same group
|
|
177
|
+
* as the built-in Freighter/Albedo, so they share one gateway. Set a distinct
|
|
178
|
+
* value (e.g. `'More wallets'`) to render the kit wallets as a separate gateway.
|
|
179
|
+
*/
|
|
180
|
+
groupLabel?: string;
|
|
155
181
|
/** Visual layout. Default `'grid'`. */
|
|
156
182
|
layout?: 'grid' | 'list';
|
|
157
|
-
/** Theme passthrough
|
|
183
|
+
/** Theme passthrough - applied as CSS custom properties on the picker root. */
|
|
158
184
|
theme?: { accent?: string; mode?: 'light' | 'dark' };
|
|
159
185
|
}
|
|
160
186
|
```
|
|
161
187
|
|
|
162
|
-
|
|
188
|
+
`stellarWalletsKitAdapters()` returns `WalletAdapter[]` from `@pollar/core` - one
|
|
189
|
+
adapter per included kit module - which you assign to
|
|
190
|
+
`PollarClientConfig.walletAdapters`. Each adapter's `type` is the kit `WalletId`
|
|
191
|
+
(`WalletType | (string & {})`, so `WalletType.FREIGHTER` keeps autocomplete while
|
|
192
|
+
`'xbull'`, `'lobstr'`, ... are accepted as plain strings) and its `meta` carries
|
|
193
|
+
the module's label/icon for the auto-rendered login button.
|
|
163
194
|
|
|
164
|
-
|
|
165
|
-
type WalletAdapterResolver = (id: WalletId) => WalletAdapter | Promise<WalletAdapter>;
|
|
166
|
-
```
|
|
195
|
+
### SSR safety
|
|
167
196
|
|
|
168
|
-
`
|
|
197
|
+
`stellarWalletsKitAdapters()` returns `[]` when `typeof window === 'undefined'`.
|
|
198
|
+
The kit talks to browser wallet extensions and touches `window` both at
|
|
199
|
+
`StellarWalletsKit.init()` and inside its module constructors, so there are no
|
|
200
|
+
wallets to build server-side. Under Next.js/Remix, construct your `PollarClient`
|
|
201
|
+
and render the wallet UI on the client (e.g. behind a mounted flag or
|
|
202
|
+
`dynamic(..., { ssr: false })`); the real adapters are built when the factory
|
|
203
|
+
re-runs in the browser.
|
|
169
204
|
|
|
170
205
|
## How it fits the Pollar wallet contract
|
|
171
206
|
|
|
172
207
|
The adapter implements `WalletAdapter` from `@pollar/core`:
|
|
173
208
|
|
|
174
|
-
| `WalletAdapter` method | Kit call
|
|
175
|
-
| ---------------------------- |
|
|
176
|
-
| `isAvailable()` | `
|
|
177
|
-
| `connect()` | `setWallet(id)`
|
|
178
|
-
| `disconnect()` | `StellarWalletsKit.disconnect()`
|
|
179
|
-
| `getPublicKey()` | `StellarWalletsKit.getAddress()`
|
|
180
|
-
| `signTransaction(xdr, opts)` | `setWallet(id)`
|
|
181
|
-
| `signAuthEntry(xdr, opts)` | `setWallet(id)`
|
|
182
|
-
|
|
183
|
-
`setWallet` is called before every operation so a single
|
|
209
|
+
| `WalletAdapter` method | Kit call |
|
|
210
|
+
| ---------------------------- | ----------------------------------------------------------- |
|
|
211
|
+
| `isAvailable()` | `refreshSupportedWallets()` then check the wallet's `isAvailable` flag |
|
|
212
|
+
| `connect()` | `setWallet(id)` > `fetchAddress()` |
|
|
213
|
+
| `disconnect()` | `StellarWalletsKit.disconnect()` |
|
|
214
|
+
| `getPublicKey()` | `StellarWalletsKit.getAddress()` |
|
|
215
|
+
| `signTransaction(xdr, opts)` | `setWallet(id)` > `signTransaction(xdr, opts)` |
|
|
216
|
+
| `signAuthEntry(xdr, opts)` | `setWallet(id)` > `signAuthEntry(xdr, opts)` |
|
|
217
|
+
|
|
218
|
+
`setWallet` is called before every signing/connect operation so a single
|
|
219
|
+
`StellarWalletsKit.init({ modules })` covers many wallets. `stellarWalletsKitAdapters()`
|
|
220
|
+
builds one `StellarWalletsKitAdapter` per module up front and returns the array;
|
|
221
|
+
each adapter is bound to its own `WalletId` and the kit routes to the correct
|
|
222
|
+
module under the hood.
|
|
184
223
|
|
|
185
224
|
## Login UI
|
|
186
225
|
|
|
@@ -219,33 +258,36 @@ import { StellarWalletsKitAdapter } from '@pollar/stellar-wallets-kit-adapter';
|
|
|
219
258
|
|
|
220
259
|
StellarWalletsKit.init({ network: Networks.PUBLIC, modules: [new FreighterModule()] });
|
|
221
260
|
|
|
222
|
-
|
|
261
|
+
// The constructor requires a meta arg whose `label` is required.
|
|
262
|
+
const adapter = new StellarWalletsKitAdapter('freighter', { label: 'Freighter' });
|
|
223
263
|
const { address } = await adapter.connect();
|
|
224
264
|
```
|
|
225
265
|
|
|
226
|
-
##
|
|
266
|
+
## Composing with other adapters
|
|
227
267
|
|
|
228
|
-
`
|
|
268
|
+
`walletAdapters` is a plain `WalletAdapter[]`, so you can spread the kit adapters
|
|
269
|
+
alongside adapters from other packages (`@pollar/privy-adapter`, ...) or your own.
|
|
270
|
+
Entries later in the array override an earlier one that reuses the same `type`, and
|
|
271
|
+
each entry also overrides a built-in Freighter/Albedo with a matching `type`:
|
|
229
272
|
|
|
230
273
|
```ts
|
|
231
|
-
import {
|
|
232
|
-
import {
|
|
233
|
-
|
|
234
|
-
|
|
274
|
+
import { PollarClient } from '@pollar/core';
|
|
275
|
+
import { stellarWalletsKitAdapters } from '@pollar/stellar-wallets-kit-adapter';
|
|
276
|
+
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
277
|
+
import { MyCustomAdapter } from './my-custom-adapter';
|
|
235
278
|
|
|
236
279
|
new PollarClient({
|
|
237
280
|
apiKey: 'your-api-key',
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
},
|
|
281
|
+
walletAdapters: [
|
|
282
|
+
...stellarWalletsKitAdapters({ network: Networks.PUBLIC }),
|
|
283
|
+
new MyCustomAdapter(),
|
|
284
|
+
],
|
|
243
285
|
});
|
|
244
286
|
```
|
|
245
287
|
|
|
246
288
|
## Fallback behaviour
|
|
247
289
|
|
|
248
|
-
If `
|
|
290
|
+
If `walletAdapters` is omitted from `PollarClientConfig`, `@pollar/core` falls back to its built-in `FreighterAdapter` / `AlbedoAdapter`. Installing this package is opt-in - existing apps keep working without changes until they add adapters to the slot.
|
|
249
291
|
|
|
250
292
|
## License
|
|
251
293
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pollar/stellar-wallets-kit-adapter",
|
|
3
|
-
"version": "0.10.0
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Stellar Wallets Kit adapter for @pollar/core — plug additional wallet modules (xBull, Lobstr, WalletConnect, hardware wallets…) into Pollar without bundling them into @pollar/core.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@creit.tech/stellar-wallets-kit": "^2.0.0",
|
|
35
|
-
"@pollar/core": "^0.10.0
|
|
35
|
+
"@pollar/core": "^0.10.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@pollar/core": "^0.10.0
|
|
38
|
+
"@pollar/core": "^0.10.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@creit.tech/stellar-wallets-kit": "^2.3.0",
|