@tuwaio/orbit-core 0.1.2 → 0.2.1
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 +31 -31
- package/dist/index.d.mts +292 -51
- package/dist/index.d.ts +292 -51
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,17 +18,17 @@ Its primary goal is to establish a **unified interface** for interacting with di
|
|
|
18
18
|
|
|
19
19
|
## ✨ Key Features
|
|
20
20
|
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
-
|
|
21
|
+
- **Multi-Chain Foundation:** Defines the core `OrbitAdapter` enum (supporting EVM, Solana, Starknet) and types for building consistent multi-chain support.
|
|
22
|
+
- **Framework Agnostic & Headless:** Contains only logic, no UI components, ensuring compatibility with any frontend setup.
|
|
23
|
+
- **Type-Safe Development:** Fully written in TypeScript 5.9+ for a robust developer experience.
|
|
24
|
+
- **Flexible Adapter System:** Provides utilities like `selectAdapterByKey` to easily manage and switch between different blockchain adapter implementations.
|
|
25
|
+
- **Essential Utilities:** Includes common helpers for tasks such as:
|
|
26
|
+
- Formatting connector names and chain IDs (`formatConnectorName`, `formatConnectorChainId`).
|
|
27
|
+
- Identifying chain types (`isSolanaChain`, `getAdapterFromConnectorType`).
|
|
28
|
+
- Managing connector connection state in localStorage (`lastConnectedConnectorHelpers`, `recentConnectedConnectorHelpers`).
|
|
29
|
+
- Handling impersonation for development/testing (`impersonatedHelpers`).
|
|
30
|
+
- Basic async operations (`delay`, `waitFor`).
|
|
31
|
+
- **SSR Safe:** Utilities are designed to work safely in both browser and Server-Side Rendering environments.
|
|
32
32
|
|
|
33
33
|
---
|
|
34
34
|
|
|
@@ -117,33 +117,33 @@ if (selectedSolanaAdapter && selectedSolanaAdapter.key === OrbitAdapter.SOLANA)
|
|
|
117
117
|
```typescript
|
|
118
118
|
import {
|
|
119
119
|
OrbitAdapter,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
formatConnectorName,
|
|
121
|
+
getAdapterFromConnectorType,
|
|
122
|
+
getConnectorTypeFromName,
|
|
123
123
|
isSolanaChain,
|
|
124
|
-
|
|
124
|
+
lastConnectedConnectorHelpers
|
|
125
125
|
} from '@tuwaio/orbit-core';
|
|
126
126
|
|
|
127
127
|
// Formatting
|
|
128
|
-
const formattedName =
|
|
128
|
+
const formattedName = formatConnectorName('MetaMask'); // "metamask"
|
|
129
129
|
console.log(formattedName);
|
|
130
|
-
const
|
|
131
|
-
console.log(
|
|
130
|
+
const connectorType = getConnectorTypeFromName(OrbitAdapter.EVM, 'Brave Wallet'); // "evm:bravewallet"
|
|
131
|
+
console.log(connectorType);
|
|
132
132
|
|
|
133
133
|
// Identification
|
|
134
|
-
const adapterType =
|
|
134
|
+
const adapterType = getAdapterFromConnectorType(connectorType); // OrbitAdapter.EVM
|
|
135
135
|
console.log(adapterType);
|
|
136
136
|
console.log(isSolanaChain('devnet')); // true
|
|
137
137
|
console.log(isSolanaChain(1)); // false
|
|
138
138
|
|
|
139
|
-
// Local Storage Management for Last Connected
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
// Local Storage Management for Last Connected Connector
|
|
140
|
+
lastConnectedConnectorHelpers.setLastConnectedConnector({
|
|
141
|
+
connectorType: 'evm:metamask',
|
|
142
142
|
chainId: 1,
|
|
143
143
|
address: '0x123...'
|
|
144
144
|
});
|
|
145
|
-
const lastWallet =
|
|
146
|
-
console.log(lastWallet); // {
|
|
145
|
+
const lastWallet = lastConnectedConnectorHelpers.getLastConnectedConnector();
|
|
146
|
+
console.log(lastWallet); // { connectorType: 'evm:metamask', chainId: 1, address: '0x123...' }
|
|
147
147
|
|
|
148
148
|
// lastConnectedWalletHelpers.removeLastConnectedWallet();
|
|
149
149
|
```
|
|
@@ -154,17 +154,17 @@ console.log(lastWallet); // { walletType: 'evm:metamask', chainId: 1, address: '
|
|
|
154
154
|
|
|
155
155
|
Orbit Core is designed around modularity and abstraction:
|
|
156
156
|
|
|
157
|
-
1.
|
|
158
|
-
2.
|
|
159
|
-
3.
|
|
157
|
+
1. **Core Types (`types.ts`):** Defines fundamental structures like `OrbitAdapter` (enum for EVM, Solana, Starknet), `BaseAdapter` (common interface), and `ConnectorType`.
|
|
158
|
+
2. **Adapter System:** Enables handling multiple blockchain types via a common interface. The `selectAdapterByKey` utility allows runtime selection of the correct adapter implementation based on the `OrbitAdapter` key. Chain-specific logic resides in separate packages (e.g., `@tuwaio/orbit-evm`).
|
|
159
|
+
3. **Utilities (`utils/`):** A collection of framework-agnostic helper functions covering formatting, chain identification, localStorage management (for connection state persistence), async operations, and other common tasks needed when building multi-chain UIs.
|
|
160
160
|
|
|
161
161
|
### Key Exports (`index.ts`)
|
|
162
162
|
|
|
163
|
-
- **Types:** `OrbitAdapter`, `BaseAdapter`, `
|
|
164
|
-
- **Adapter Utilities:** `selectAdapterByKey`, `
|
|
165
|
-
- **Formatting Utilities:** `
|
|
163
|
+
- **Types:** `OrbitAdapter`, `BaseAdapter`, `ConnectorType`, `OrbitGenericAdapter`, `RecentConnectedConnector`.
|
|
164
|
+
- **Adapter Utilities:** `selectAdapterByKey`, `getAdapterFromConnectorType`.
|
|
165
|
+
- **Formatting Utilities:** `formatConnectorChainId`, `formatConnectorName`, `getConnectorTypeFromName`.
|
|
166
166
|
- **Chain Helpers:** `isSolanaChain`, `setChainId`.
|
|
167
|
-
- **Storage Helpers:** `
|
|
167
|
+
- **Storage Helpers:** `lastConnectedConnectorHelpers`, `recentConnectedConnectorHelpers`, `impersonatedHelpers`, `getParsedStorageItem`.
|
|
168
168
|
- **General Utilities:** `delay`, `filterUniqueByKey`, `waitFor`, `isSafeApp`.
|
|
169
169
|
|
|
170
170
|
-----
|
package/dist/index.d.mts
CHANGED
|
@@ -100,12 +100,32 @@ type BaseAdapter = {
|
|
|
100
100
|
getName?: (address: string) => Promise<string | null>;
|
|
101
101
|
/** Optional method to get avatar for resolved names */
|
|
102
102
|
getAvatar?: (name: string) => Promise<string | null>;
|
|
103
|
+
/** Optional method to resolve names to addresses */
|
|
104
|
+
getAddress?: (name: string) => Promise<string | null>;
|
|
103
105
|
};
|
|
104
106
|
/**
|
|
105
|
-
* Type representing a
|
|
107
|
+
* Type representing a connector identifier in format "OrbitAdapter:connector"
|
|
106
108
|
* @example "evm:metamask" | "solana:phantom"
|
|
107
109
|
*/
|
|
108
|
-
type
|
|
110
|
+
type ConnectorType = `${OrbitAdapter}:${string}`;
|
|
111
|
+
/**
|
|
112
|
+
* Array of chain identifiers (replaces IdentifierArray from @wallet-standard/base)
|
|
113
|
+
* Can contain strings, numbers, or other primitive types
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const chainIds: ChainIdentifierArray = ['ethereum', 1, 'solana:mainnet-beta'];
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
type ChainIdentifierArray = readonly (string | number)[];
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Universal address validation function that supports multiple blockchain formats
|
|
124
|
+
* @param value - Address string to validate
|
|
125
|
+
* @param type - Optional blockchain type to validate against ('evm' | 'solana' | 'auto')
|
|
126
|
+
* @returns boolean indicating if the address is valid
|
|
127
|
+
*/
|
|
128
|
+
declare function isAddress(value: string, type?: 'evm' | 'solana' | 'auto'): boolean;
|
|
109
129
|
|
|
110
130
|
/**
|
|
111
131
|
* @name delay
|
|
@@ -152,69 +172,92 @@ declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
|
152
172
|
*/
|
|
153
173
|
declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
154
174
|
|
|
155
|
-
declare function
|
|
175
|
+
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
156
176
|
|
|
157
|
-
declare const
|
|
177
|
+
declare const formatConnectorName: (connectorName: string) => string;
|
|
158
178
|
|
|
159
179
|
/**
|
|
160
|
-
* Extracts the adapter type from a
|
|
180
|
+
* Extracts the adapter type from a connector type string
|
|
161
181
|
*
|
|
162
182
|
* @example
|
|
163
183
|
* ```typescript
|
|
164
184
|
* // Returns OrbitAdapter.EVM
|
|
165
|
-
*
|
|
185
|
+
* getAdapterFromConnectorType('evm:metamask');
|
|
166
186
|
*
|
|
167
187
|
* // Returns OrbitAdapter.SOLANA
|
|
168
|
-
*
|
|
188
|
+
* getAdapterFromConnectorType('solana:phantom');
|
|
169
189
|
*
|
|
170
190
|
* // Returns OrbitAdapter.EVM (default)
|
|
171
|
-
*
|
|
191
|
+
* getAdapterFromConnectorType('unknown');
|
|
172
192
|
* ```
|
|
173
193
|
*
|
|
174
|
-
* @param
|
|
194
|
+
* @param connectorType - Connector type in format "orbit-adapter:connector" (e.g. "evm:metamask", "solana:phantom")
|
|
175
195
|
* @returns The corresponding {@link OrbitAdapter} type or EVM as default
|
|
176
196
|
*
|
|
177
197
|
* @remarks
|
|
178
|
-
* The function splits the
|
|
198
|
+
* The function splits the connector type string by ":" and takes the first part as the adapter type.
|
|
179
199
|
* If the split fails or the first part is empty, it defaults to EVM adapter.
|
|
180
200
|
*/
|
|
181
|
-
declare function
|
|
201
|
+
declare function getAdapterFromConnectorType(connectorType: ConnectorType): OrbitAdapter;
|
|
182
202
|
|
|
183
203
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* @param key - The key for localStorage
|
|
187
|
-
* @returns The parsed LastConnectedWallet object or undefined if data is not found/invalid
|
|
188
|
-
*/
|
|
189
|
-
declare function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Generates a standardized wallet type identifier from adapter type and connector name
|
|
204
|
+
* Generates a standardized connector type identifier from adapter type and connector name
|
|
193
205
|
*
|
|
194
206
|
* @example
|
|
195
207
|
* ```typescript
|
|
196
208
|
* // Returns "evm:metamask"
|
|
197
|
-
*
|
|
209
|
+
* getConnectorTypeFromName(OrbitAdapter.EVM, "MetaMask");
|
|
198
210
|
*
|
|
199
211
|
* // Returns "solana:phantom"
|
|
200
|
-
*
|
|
212
|
+
* getConnectorTypeFromName(OrbitAdapter.SOLANA, "Phantom");
|
|
201
213
|
*
|
|
202
214
|
* // Returns "evm:coinbasewallet" (removes spaces)
|
|
203
|
-
*
|
|
215
|
+
* getConnectorTypeFromName(OrbitAdapter.EVM, "Coinbase Wallet");
|
|
204
216
|
* ```
|
|
205
217
|
*
|
|
206
218
|
* @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
|
|
207
|
-
* @param name - The
|
|
208
|
-
* @returns A formatted
|
|
219
|
+
* @param name - The connector name (e.g. "MetaMask", "Phantom")
|
|
220
|
+
* @returns A formatted connector type string in format "orbit-adapter:connector"
|
|
209
221
|
*
|
|
210
222
|
* @remarks
|
|
211
223
|
* The function:
|
|
212
224
|
* 1. Combines adapter type with connector name using ":" as separator
|
|
213
225
|
* 2. Removes all whitespace from connector name
|
|
214
226
|
* 3. Converts connector name to lowercase
|
|
215
|
-
* This ensures consistent
|
|
227
|
+
* This ensures consistent connector type identifiers across the application
|
|
228
|
+
* and normalizes connector names for better UX/consistency.
|
|
229
|
+
*/
|
|
230
|
+
declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): string;
|
|
231
|
+
|
|
232
|
+
declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
233
|
+
chain: {
|
|
234
|
+
chainId: number;
|
|
235
|
+
name: string;
|
|
236
|
+
};
|
|
237
|
+
links: {
|
|
238
|
+
aboutNetwork: string;
|
|
239
|
+
choseWallet: string;
|
|
240
|
+
about: string;
|
|
241
|
+
};
|
|
242
|
+
} | {
|
|
243
|
+
chain: {
|
|
244
|
+
chainId: string;
|
|
245
|
+
name: string;
|
|
246
|
+
};
|
|
247
|
+
links: {
|
|
248
|
+
aboutNetwork: string;
|
|
249
|
+
choseWallet: string;
|
|
250
|
+
about: string;
|
|
251
|
+
};
|
|
252
|
+
} | undefined;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Internal function for safely retrieving and parsing data from localStorage.
|
|
256
|
+
*
|
|
257
|
+
* @param key - The key for localStorage
|
|
258
|
+
* @returns The parsed LastConnectedConnector object or undefined if data is not found/invalid
|
|
216
259
|
*/
|
|
217
|
-
declare function
|
|
260
|
+
declare function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined;
|
|
218
261
|
|
|
219
262
|
/**
|
|
220
263
|
* Helper utilities for managing impersonated wallet addresses
|
|
@@ -263,8 +306,8 @@ declare const impersonatedHelpers: {
|
|
|
263
306
|
|
|
264
307
|
declare const isSafeApp: boolean;
|
|
265
308
|
|
|
266
|
-
type
|
|
267
|
-
|
|
309
|
+
type LastConnectedConnector = {
|
|
310
|
+
connectorType: ConnectorType;
|
|
268
311
|
chainId: number | string;
|
|
269
312
|
address?: string;
|
|
270
313
|
};
|
|
@@ -272,71 +315,269 @@ type LastConnectedWallet = {
|
|
|
272
315
|
* Helper utilities for managing the last connected wallet state
|
|
273
316
|
*
|
|
274
317
|
* @remarks
|
|
275
|
-
* All data is stored in localStorage with the 'orbit-core:
|
|
318
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedConnector' key.
|
|
276
319
|
* Functions are safe to use in both browser and SSR environments.
|
|
277
320
|
*/
|
|
278
|
-
declare const
|
|
321
|
+
declare const lastConnectedConnectorHelpers: {
|
|
279
322
|
STORAGE_KEY: string;
|
|
280
323
|
/**
|
|
281
324
|
* The value of the last connected wallet, initialized when the module loads.
|
|
282
325
|
* Returns undefined if not set, invalid, or in an SSR context.
|
|
283
326
|
*/
|
|
284
|
-
|
|
327
|
+
lastConnectedConnector: LastConnectedConnector | undefined;
|
|
285
328
|
/**
|
|
286
329
|
* Stores the last connected wallet data in localStorage.
|
|
287
330
|
*
|
|
288
331
|
* @param data - Object containing the wallet type and chain ID.
|
|
289
332
|
* @returns undefined in SSR context, void in browser
|
|
290
333
|
*/
|
|
291
|
-
|
|
334
|
+
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector) => void;
|
|
292
335
|
/**
|
|
293
336
|
* Retrieves the current last connected wallet data from localStorage.
|
|
294
337
|
*
|
|
295
|
-
* @returns The
|
|
338
|
+
* @returns The LastConnectedConnector object or undefined if not set or in SSR context
|
|
296
339
|
*/
|
|
297
|
-
|
|
340
|
+
getLastConnectedConnector: () => LastConnectedConnector | undefined;
|
|
298
341
|
/**
|
|
299
342
|
* Removes the last connected wallet data from localStorage.
|
|
300
343
|
*
|
|
301
344
|
* @returns undefined in SSR context, void in browser
|
|
302
345
|
*/
|
|
303
|
-
|
|
346
|
+
removeLastConnectedConnector: () => void;
|
|
304
347
|
};
|
|
305
348
|
|
|
306
|
-
type RecentConnectedWallet = Record<OrbitAdapter, Record<string, boolean>>;
|
|
307
349
|
/**
|
|
308
|
-
*
|
|
350
|
+
* Data structure for a recently connected connector
|
|
351
|
+
*
|
|
352
|
+
* @interface RecentlyConnectedConnectorData
|
|
353
|
+
* @property {string} address - The wallet address that was connected
|
|
354
|
+
* @property {number} disconnectedTimestamp - Unix timestamp in milliseconds when the connector was disconnected
|
|
355
|
+
* @property {string} [icon] - Optional icon URL or identifier for the connector
|
|
356
|
+
*/
|
|
357
|
+
type RecentlyConnectedConnectorData = {
|
|
358
|
+
address: string;
|
|
359
|
+
disconnectedTimestamp: number;
|
|
360
|
+
icon?: string;
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* Record mapping connector types to their recently connected data
|
|
364
|
+
*
|
|
365
|
+
* @type RecentlyConnectedConnectorsList
|
|
366
|
+
*/
|
|
367
|
+
type RecentlyConnectedConnectorsList = Record<ConnectorType, RecentlyConnectedConnectorData>;
|
|
368
|
+
/**
|
|
369
|
+
* Helper utilities for managing recently connected connectors list with disconnect timestamps
|
|
309
370
|
*
|
|
310
371
|
* @remarks
|
|
311
|
-
* All data is stored in localStorage with the 'orbit-core:
|
|
372
|
+
* All data is stored in localStorage with the 'orbit-core:recentlyConnectedConnectorsListHelpers' key.
|
|
312
373
|
* Functions are safe to use in both browser and SSR environments.
|
|
374
|
+
*
|
|
375
|
+
* The storage contains a record where each key is a ConnectorType and value contains
|
|
376
|
+
* address, disconnectedTimestamp (Unix timestamp in milliseconds), and optional icon for that connector.
|
|
377
|
+
* This allows tracking when each connector was last disconnected for cleanup and sorting purposes.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* ```typescript
|
|
381
|
+
* // Set entire list
|
|
382
|
+
* recentlyConnectedConnectorsListHelpers.setRecentlyConnectedConnectorsList({
|
|
383
|
+
* 'evm:metamask': {
|
|
384
|
+
* address: '0x123...',
|
|
385
|
+
* disconnectedTimestamp: Date.now(),
|
|
386
|
+
* icon: 'metamask-icon.png'
|
|
387
|
+
* },
|
|
388
|
+
* 'solana:phantom': {
|
|
389
|
+
* address: 'ABC123...',
|
|
390
|
+
* disconnectedTimestamp: Date.now() - 3600000, // 1 hour ago
|
|
391
|
+
* icon: 'phantom-icon.png'
|
|
392
|
+
* }
|
|
393
|
+
* });
|
|
394
|
+
*
|
|
395
|
+
* // Add single connector
|
|
396
|
+
* recentlyConnectedConnectorsListHelpers.addConnector('evm:walletconnect', {
|
|
397
|
+
* address: '0x456...',
|
|
398
|
+
* disconnectedTimestamp: Date.now(),
|
|
399
|
+
* icon: 'walletconnect-icon.png'
|
|
400
|
+
* });
|
|
401
|
+
*
|
|
402
|
+
* // Remove single connector
|
|
403
|
+
* recentlyConnectedConnectorsListHelpers.removeConnector('evm:metamask');
|
|
404
|
+
* ```
|
|
313
405
|
*/
|
|
314
|
-
declare const
|
|
406
|
+
declare const recentlyConnectedConnectorsListHelpers: {
|
|
407
|
+
/** Key used for localStorage storage */
|
|
315
408
|
STORAGE_KEY: string;
|
|
316
409
|
/**
|
|
317
|
-
* The
|
|
410
|
+
* The current recently connected connectors list, initialized when the module loads.
|
|
318
411
|
* Returns undefined if not set, invalid, or in an SSR context.
|
|
412
|
+
*
|
|
413
|
+
* @readonly
|
|
319
414
|
*/
|
|
320
|
-
|
|
415
|
+
recentlyConnectedConnectorsList: RecentlyConnectedConnectorsList | undefined;
|
|
321
416
|
/**
|
|
322
|
-
* Stores the
|
|
417
|
+
* Stores the complete recently connected connectors list in localStorage.
|
|
418
|
+
* This will overwrite the entire existing list.
|
|
323
419
|
*
|
|
324
|
-
* @param
|
|
420
|
+
* @param connectors - Complete RecentlyConnectedConnectorsList object
|
|
325
421
|
* @returns undefined in SSR context, void in browser
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```typescript
|
|
425
|
+
* recentlyConnectedConnectorsListHelpers.setRecentlyConnectedConnectorsList({
|
|
426
|
+
* 'evm:metamask': {
|
|
427
|
+
* address: '0x123...',
|
|
428
|
+
* disconnectedTimestamp: Date.now(),
|
|
429
|
+
* icon: 'metamask.png'
|
|
430
|
+
* },
|
|
431
|
+
* 'solana:phantom': {
|
|
432
|
+
* address: 'ABC123...',
|
|
433
|
+
* disconnectedTimestamp: Date.now() - 1800000 // 30 minutes ago
|
|
434
|
+
* }
|
|
435
|
+
* });
|
|
436
|
+
* ```
|
|
326
437
|
*/
|
|
327
|
-
|
|
438
|
+
setRecentlyConnectedConnectorsList: (connectors: RecentlyConnectedConnectorsList) => void;
|
|
328
439
|
/**
|
|
329
|
-
* Retrieves the current
|
|
440
|
+
* Retrieves the current recently connected connectors list from localStorage.
|
|
441
|
+
*
|
|
442
|
+
* @returns The RecentlyConnectedConnectorsList object or undefined if not set or in SSR context
|
|
330
443
|
*
|
|
331
|
-
* @
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* const connectors = recentlyConnectedConnectorsListHelpers.getRecentlyConnectedConnectorsList();
|
|
447
|
+
* if (connectors) {
|
|
448
|
+
* console.log('Available connectors:', Object.keys(connectors));
|
|
449
|
+
* // Sort by most recently disconnected
|
|
450
|
+
* const sorted = Object.entries(connectors)
|
|
451
|
+
* .sort(([,a], [,b]) => b.disconnectedTimestamp - a.disconnectedTimestamp);
|
|
452
|
+
* }
|
|
453
|
+
* ```
|
|
332
454
|
*/
|
|
333
|
-
|
|
455
|
+
getRecentlyConnectedConnectorsList: () => RecentlyConnectedConnectorsList | undefined;
|
|
334
456
|
/**
|
|
335
|
-
*
|
|
457
|
+
* Adds or updates a single connector in the recently connected connectors list.
|
|
458
|
+
* Preserves existing connectors and only adds/updates the specified one.
|
|
336
459
|
*
|
|
460
|
+
* @param connectorType - The connector type to add/update
|
|
461
|
+
* @param connectorData - The connector data (address, disconnectedTimestamp, and optional icon)
|
|
337
462
|
* @returns undefined in SSR context, void in browser
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```typescript
|
|
466
|
+
* // Add new connector with current timestamp
|
|
467
|
+
* recentlyConnectedConnectorsListHelpers.addConnector('evm:metamask', {
|
|
468
|
+
* address: '0x123...',
|
|
469
|
+
* disconnectedTimestamp: Date.now(),
|
|
470
|
+
* icon: 'metamask.png'
|
|
471
|
+
* });
|
|
472
|
+
*
|
|
473
|
+
* // Update existing connector with new disconnect time
|
|
474
|
+
* recentlyConnectedConnectorsListHelpers.addConnector('evm:metamask', {
|
|
475
|
+
* address: '0x456...',
|
|
476
|
+
* disconnectedTimestamp: Date.now(),
|
|
477
|
+
* icon: 'new-metamask.png'
|
|
478
|
+
* });
|
|
479
|
+
* ```
|
|
480
|
+
*/
|
|
481
|
+
addConnector: (connectorType: ConnectorType, connectorData: RecentlyConnectedConnectorData) => undefined;
|
|
482
|
+
/**
|
|
483
|
+
* Removes a single connector from the recently connected connectors list.
|
|
484
|
+
* Preserves all other connectors in the list.
|
|
485
|
+
*
|
|
486
|
+
* @param connectorType - The connector type to remove
|
|
487
|
+
* @returns undefined in SSR context, void in browser
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```typescript
|
|
491
|
+
* // Remove specific connector
|
|
492
|
+
* recentlyConnectedConnectorsListHelpers.removeConnector('evm:metamask');
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
495
|
+
removeConnector: (connectorType: ConnectorType) => undefined;
|
|
496
|
+
/**
|
|
497
|
+
* Checks if a specific connector exists in the recently connected connectors list.
|
|
498
|
+
*
|
|
499
|
+
* @param connectorType - The connector type to check
|
|
500
|
+
* @returns true if the connector exists, false otherwise, undefined in SSR context
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```typescript
|
|
504
|
+
* if (recentlyConnectedConnectorsListHelpers.hasConnector('evm:metamask')) {
|
|
505
|
+
* console.log('MetaMask was recently connected');
|
|
506
|
+
* }
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
hasConnector: (connectorType: ConnectorType) => boolean | undefined;
|
|
510
|
+
/**
|
|
511
|
+
* Gets data for a specific connector from the recently connected connectors list.
|
|
512
|
+
*
|
|
513
|
+
* @param connectorType - The connector type to get data for
|
|
514
|
+
* @returns The connector data (including address, disconnectedTimestamp, and optional icon) or undefined if not found or in SSR context
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```typescript
|
|
518
|
+
* const metamaskData = recentlyConnectedConnectorsListHelpers.getConnector('evm:metamask');
|
|
519
|
+
* if (metamaskData) {
|
|
520
|
+
* console.log('MetaMask address:', metamaskData.address);
|
|
521
|
+
* console.log('Disconnected at:', new Date(metamaskData.disconnectedTimestamp));
|
|
522
|
+
* console.log('MetaMask icon:', metamaskData.icon);
|
|
523
|
+
* }
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
getConnector: (connectorType: ConnectorType) => RecentlyConnectedConnectorData | undefined;
|
|
527
|
+
/**
|
|
528
|
+
* Gets the count of recently connected connectors.
|
|
529
|
+
*
|
|
530
|
+
* @returns Number of connectors in the list, 0 in SSR context or if list is empty
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```typescript
|
|
534
|
+
* const count = recentlyConnectedConnectorsListHelpers.getConnectorCount();
|
|
535
|
+
* console.log(`${count} connectors recently connected`);
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
getConnectorCount: () => number;
|
|
539
|
+
/**
|
|
540
|
+
* Gets recently connected connectors sorted by disconnect time (most recent first).
|
|
541
|
+
* Useful for showing connectors in order of recent usage.
|
|
542
|
+
*
|
|
543
|
+
* @returns Array of [ConnectorType, RecentlyConnectedConnectorData] tuples sorted by disconnectedTimestamp (descending), empty array in SSR context
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* ```typescript
|
|
547
|
+
* const sortedConnectors = recentlyConnectedConnectorsListHelpers.getConnectorsSortedByTime();
|
|
548
|
+
* sortedConnectors.forEach(([connectorType, data]) => {
|
|
549
|
+
* console.log(`${connectorType}: disconnected ${new Date(data.disconnectedTimestamp)}`);
|
|
550
|
+
* });
|
|
551
|
+
* ```
|
|
552
|
+
*/
|
|
553
|
+
getConnectorsSortedByTime: () => [ConnectorType, RecentlyConnectedConnectorData][];
|
|
554
|
+
/**
|
|
555
|
+
* Removes connectors that were disconnected before the specified timestamp.
|
|
556
|
+
* Useful for cleaning up old connector entries.
|
|
557
|
+
*
|
|
558
|
+
* @param beforeTimestamp - Unix timestamp in milliseconds; connectors disconnected before this time will be removed
|
|
559
|
+
* @returns undefined in SSR context, void in browser
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* ```typescript
|
|
563
|
+
* // Remove connectors disconnected more than 7 days ago
|
|
564
|
+
* const weekAgo = Date.now() - (7 * 24 * 60 * 60 * 1000);
|
|
565
|
+
* recentlyConnectedConnectorsListHelpers.removeConnectorsOlderThan(weekAgo);
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
removeConnectorsOlderThan: (beforeTimestamp: number) => undefined;
|
|
569
|
+
/**
|
|
570
|
+
* Removes all recently connected connectors from localStorage.
|
|
571
|
+
*
|
|
572
|
+
* @returns undefined in SSR context, void in browser
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```typescript
|
|
576
|
+
* // Clear all recently connected connectors
|
|
577
|
+
* recentlyConnectedConnectorsListHelpers.removeRecentlyConnectedConnectorsList();
|
|
578
|
+
* ```
|
|
338
579
|
*/
|
|
339
|
-
|
|
580
|
+
removeRecentlyConnectedConnectorsList: () => void;
|
|
340
581
|
};
|
|
341
582
|
|
|
342
583
|
/**
|
|
@@ -406,4 +647,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
406
647
|
*/
|
|
407
648
|
declare function setChainId(chainId: number | string): string | number;
|
|
408
649
|
|
|
409
|
-
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type
|
|
650
|
+
export { type BaseAdapter, type ChainIdentifierArray, type ConnectorType, OrbitAdapter, type OrbitGenericAdapter, type RecentlyConnectedConnectorData, type RecentlyConnectedConnectorsList, delay, filterUniqueByKey, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getConnectorTypeFromName, getNetworkData, getParsedStorageItem, impersonatedHelpers, isAddress, isSafeApp, isSolanaChain, lastConnectedConnectorHelpers, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, waitFor };
|