@tuwaio/orbit-core 1.0.0-fix-test-alpha.35.fe44df5 → 1.0.0-fix-test-alpha.37.702ae35
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/dist/index.d.mts +163 -90
- package/dist/index.d.ts +163 -90
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/zustand/index.d.mts +47 -0
- package/dist/zustand/index.d.ts +47 -0
- package/dist/zustand/index.js +37 -0
- package/dist/zustand/index.js.map +1 -0
- package/dist/zustand/index.mjs +37 -0
- package/dist/zustand/index.mjs.map +1 -0
- package/package.json +13 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import { StoreApi } from 'zustand';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @file
|
|
5
3
|
* Core type definitions for the Orbit blockchain adapter system.
|
|
6
4
|
* This file contains fundamental enums and types that define the supported blockchain architectures
|
|
7
5
|
* and their adapter interfaces.
|
|
8
6
|
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A utility type for creating modular Zustand store slices, enabling composable state management.
|
|
12
|
-
* @template T The state slice being defined.
|
|
13
|
-
* @template S The full store state that includes the slice `T`.
|
|
14
|
-
*/
|
|
15
|
-
type StoreSlice<T extends object, S extends object = T> = (set: StoreApi<S extends T ? S : S & T>['setState'], get: StoreApi<S extends T ? S : S & T>['getState']) => T;
|
|
16
7
|
/**
|
|
17
8
|
* Defines the supported blockchain adapters in the Orbit system.
|
|
18
9
|
* Each adapter corresponds to a specific blockchain architecture and implements
|
|
@@ -110,88 +101,11 @@ type BaseAdapter = {
|
|
|
110
101
|
/** Optional method to get avatar for resolved names */
|
|
111
102
|
getAvatar?: (name: string) => Promise<string | null>;
|
|
112
103
|
};
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Helper utilities for managing impersonated wallet addresses
|
|
116
|
-
*
|
|
117
|
-
* @remarks
|
|
118
|
-
* These utilities are primarily used for development and testing purposes.
|
|
119
|
-
* They provide a way to simulate different wallet addresses without actually connecting a wallet.
|
|
120
|
-
* All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.
|
|
121
|
-
* Functions are safe to use in both browser and SSR environments.
|
|
122
|
-
*/
|
|
123
|
-
declare const connectedWalletChainHelpers: {
|
|
124
|
-
/**
|
|
125
|
-
* Currently impersonated address from localStorage
|
|
126
|
-
* Returns empty string if not set or in SSR context
|
|
127
|
-
*/
|
|
128
|
-
connectedWalletChain: string;
|
|
129
|
-
/**
|
|
130
|
-
* Stores an impersonated address in localStorage
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```typescript
|
|
134
|
-
* // Set impersonated address
|
|
135
|
-
* impersonatedHelpers.setImpersonated('0x1234...5678');
|
|
136
|
-
* ```
|
|
137
|
-
*
|
|
138
|
-
* @param address - Ethereum or Solana address to impersonate
|
|
139
|
-
* @returns undefined in SSR context, void in browser
|
|
140
|
-
*/
|
|
141
|
-
setConnectedWalletChain: (chain: string | number) => void;
|
|
142
|
-
/**
|
|
143
|
-
* Retrieves the current impersonated address from localStorage
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* ```typescript
|
|
147
|
-
* // Get current impersonated address
|
|
148
|
-
* const address = impersonatedHelpers.getImpersonated();
|
|
149
|
-
* if (address) {
|
|
150
|
-
* console.log('Currently impersonating:', address);
|
|
151
|
-
* }
|
|
152
|
-
* ```
|
|
153
|
-
* @returns The impersonated address or undefined if not set or in SSR context
|
|
154
|
-
*/
|
|
155
|
-
getConnectedWalletChain: () => string | null | undefined;
|
|
156
|
-
removeConnectedWalletChain: () => void;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.
|
|
161
|
-
* This pattern is recommended by the official Zustand documentation to ensure full type
|
|
162
|
-
* safety when integrating vanilla stores with React.
|
|
163
|
-
*
|
|
164
|
-
* @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
104
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* @template S - The type of the Zustand store (`StoreApi`).
|
|
105
|
+
* Type representing a wallet identifier in format "OrbitAdapter:wallet"
|
|
106
|
+
* @example "evm:metamask" | "solana:phantom"
|
|
171
107
|
*/
|
|
172
|
-
type
|
|
173
|
-
getState: () => infer T;
|
|
174
|
-
} ? T : never;
|
|
175
|
-
/**
|
|
176
|
-
* Creates a bounded `useStore` hook from a vanilla Zustand store.
|
|
177
|
-
*
|
|
178
|
-
* This function takes a vanilla Zustand store instance and returns a React hook
|
|
179
|
-
* that is pre-bound to that store. This approach provides a cleaner API and
|
|
180
|
-
* enhances type inference, eliminating the need to pass the store instance
|
|
181
|
-
* on every use.
|
|
182
|
-
*
|
|
183
|
-
* The returned hook supports two signatures:
|
|
184
|
-
* 1. `useBoundedStore()`: Selects the entire state.
|
|
185
|
-
* 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.
|
|
186
|
-
*
|
|
187
|
-
* @template S - The type of the Zustand store (`StoreApi`).
|
|
188
|
-
* @param {S} store - The vanilla Zustand store instance to bind the hook to.
|
|
189
|
-
* @returns {function} A fully typed React hook for accessing the store's state.
|
|
190
|
-
*/
|
|
191
|
-
declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) => {
|
|
192
|
-
(): ExtractState<S>;
|
|
193
|
-
<T>(selector: (state: ExtractState<S>) => T): T;
|
|
194
|
-
};
|
|
108
|
+
type WalletType = `${OrbitAdapter}:${string}`;
|
|
195
109
|
|
|
196
110
|
/**
|
|
197
111
|
* @name delay
|
|
@@ -240,6 +154,40 @@ declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
|
240
154
|
|
|
241
155
|
declare function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
242
156
|
|
|
157
|
+
declare const formatWalletName: (walletName: string) => string;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Extracts the adapter type from a wallet type string
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // Returns OrbitAdapter.EVM
|
|
165
|
+
* getAdapterFromWalletType('evm:metamask');
|
|
166
|
+
*
|
|
167
|
+
* // Returns OrbitAdapter.SOLANA
|
|
168
|
+
* getAdapterFromWalletType('solana:phantom');
|
|
169
|
+
*
|
|
170
|
+
* // Returns OrbitAdapter.EVM (default)
|
|
171
|
+
* getAdapterFromWalletType('unknown');
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @param walletType - Wallet type in format "chain:wallet" (e.g. "evm:metamask", "solana:phantom")
|
|
175
|
+
* @returns The corresponding {@link OrbitAdapter} type or EVM as default
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* The function splits the wallet type string by ":" and takes the first part as the adapter type.
|
|
179
|
+
* If the split fails or the first part is empty, it defaults to EVM adapter.
|
|
180
|
+
*/
|
|
181
|
+
declare function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Internal function for safely retrieving and parsing data from localStorage.
|
|
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
|
+
|
|
243
191
|
/**
|
|
244
192
|
* Generates a standardized wallet type identifier from adapter type and connector name
|
|
245
193
|
*
|
|
@@ -268,6 +216,129 @@ declare function formatWalletChainId(chainId: string | number, connectedAdapter:
|
|
|
268
216
|
*/
|
|
269
217
|
declare function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string;
|
|
270
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Helper utilities for managing impersonated wallet addresses
|
|
221
|
+
*
|
|
222
|
+
* @remarks
|
|
223
|
+
* These utilities are primarily used for development and testing purposes.
|
|
224
|
+
* They provide a way to simulate different wallet addresses without actually connecting a wallet.
|
|
225
|
+
* All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.
|
|
226
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
227
|
+
*/
|
|
228
|
+
declare const impersonatedHelpers: {
|
|
229
|
+
/**
|
|
230
|
+
* Currently impersonated address from localStorage
|
|
231
|
+
* Returns empty string if not set or in SSR context
|
|
232
|
+
*/
|
|
233
|
+
impersonatedAddress: string;
|
|
234
|
+
/**
|
|
235
|
+
* Stores an impersonated address in localStorage
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* // Set impersonated address
|
|
240
|
+
* impersonatedHelpers.setImpersonated('0x1234...5678');
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @param address - Ethereum or Solana address to impersonate
|
|
244
|
+
* @returns undefined in SSR context, void in browser
|
|
245
|
+
*/
|
|
246
|
+
setImpersonated: (address: string) => void;
|
|
247
|
+
/**
|
|
248
|
+
* Retrieves the current impersonated address from localStorage
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* // Get current impersonated address
|
|
253
|
+
* const address = impersonatedHelpers.getImpersonated();
|
|
254
|
+
* if (address) {
|
|
255
|
+
* console.log('Currently impersonating:', address);
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
* @returns The impersonated address or undefined if not set or in SSR context
|
|
259
|
+
*/
|
|
260
|
+
getImpersonated: () => string | null | undefined;
|
|
261
|
+
removeImpersonated: () => void;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
declare const isSafeApp: boolean;
|
|
265
|
+
|
|
266
|
+
type LastConnectedWallet = {
|
|
267
|
+
walletType: WalletType;
|
|
268
|
+
chainId: number | string;
|
|
269
|
+
address?: string;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Helper utilities for managing the last connected wallet state
|
|
273
|
+
*
|
|
274
|
+
* @remarks
|
|
275
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.
|
|
276
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
277
|
+
*/
|
|
278
|
+
declare const lastConnectedWalletHelpers: {
|
|
279
|
+
STORAGE_KEY: string;
|
|
280
|
+
/**
|
|
281
|
+
* The value of the last connected wallet, initialized when the module loads.
|
|
282
|
+
* Returns undefined if not set, invalid, or in an SSR context.
|
|
283
|
+
*/
|
|
284
|
+
lastConnectedWallet: LastConnectedWallet | undefined;
|
|
285
|
+
/**
|
|
286
|
+
* Stores the last connected wallet data in localStorage.
|
|
287
|
+
*
|
|
288
|
+
* @param data - Object containing the wallet type and chain ID.
|
|
289
|
+
* @returns undefined in SSR context, void in browser
|
|
290
|
+
*/
|
|
291
|
+
setLastConnectedWallet: ({ walletType, chainId }: LastConnectedWallet) => void;
|
|
292
|
+
/**
|
|
293
|
+
* Retrieves the current last connected wallet data from localStorage.
|
|
294
|
+
*
|
|
295
|
+
* @returns The LastConnectedWallet object or undefined if not set or in SSR context
|
|
296
|
+
*/
|
|
297
|
+
getLastConnectedWallet: () => LastConnectedWallet | undefined;
|
|
298
|
+
/**
|
|
299
|
+
* Removes the last connected wallet data from localStorage.
|
|
300
|
+
*
|
|
301
|
+
* @returns undefined in SSR context, void in browser
|
|
302
|
+
*/
|
|
303
|
+
removeLastConnectedWallet: () => void;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
type RecentConnectedWallet = Record<OrbitAdapter, Record<string, boolean>>;
|
|
307
|
+
/**
|
|
308
|
+
* Helper utilities for managing the last connected wallet state
|
|
309
|
+
*
|
|
310
|
+
* @remarks
|
|
311
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.
|
|
312
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
313
|
+
*/
|
|
314
|
+
declare const recentConnectedWalletHelpers: {
|
|
315
|
+
STORAGE_KEY: string;
|
|
316
|
+
/**
|
|
317
|
+
* The value of the last connected wallet, initialized when the module loads.
|
|
318
|
+
* Returns undefined if not set, invalid, or in an SSR context.
|
|
319
|
+
*/
|
|
320
|
+
recentConnectedWallet: RecentConnectedWallet | undefined;
|
|
321
|
+
/**
|
|
322
|
+
* Stores the last connected wallet data in localStorage.
|
|
323
|
+
*
|
|
324
|
+
* @param wallets - RecentConnectedWallet
|
|
325
|
+
* @returns undefined in SSR context, void in browser
|
|
326
|
+
*/
|
|
327
|
+
setRecentConnectedWallet: (wallets: RecentConnectedWallet) => void;
|
|
328
|
+
/**
|
|
329
|
+
* Retrieves the current last connected wallet data from localStorage.
|
|
330
|
+
*
|
|
331
|
+
* @returns The LastConnectedWallet object or undefined if not set or in SSR context
|
|
332
|
+
*/
|
|
333
|
+
getRecentConnectedWallet: () => RecentConnectedWallet | undefined;
|
|
334
|
+
/**
|
|
335
|
+
* Removes the last connected wallet data from localStorage.
|
|
336
|
+
*
|
|
337
|
+
* @returns undefined in SSR context, void in browser
|
|
338
|
+
*/
|
|
339
|
+
removeRecentConnectedWallet: () => void;
|
|
340
|
+
};
|
|
341
|
+
|
|
271
342
|
/**
|
|
272
343
|
* @file
|
|
273
344
|
* This module provides adapter selection functionality for the Orbit system.
|
|
@@ -317,6 +388,8 @@ declare const selectAdapterByKey: <A extends {
|
|
|
317
388
|
adapterKey: OrbitAdapter;
|
|
318
389
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
319
390
|
|
|
391
|
+
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
392
|
+
|
|
320
393
|
/**
|
|
321
394
|
* Checks whether the given chain ID belongs to a Solana network.
|
|
322
395
|
* Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.
|
|
@@ -333,4 +406,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
333
406
|
*/
|
|
334
407
|
declare function setChainId(chainId: number | string): string | number;
|
|
335
408
|
|
|
336
|
-
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type
|
|
409
|
+
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type RecentConnectedWallet, type WalletType, delay, filterUniqueByKey, formatWalletChainId, formatWalletName, getAdapterFromWalletType, getParsedStorageItem, getWalletTypeFromConnectorName, impersonatedHelpers, isSafeApp, isSolanaChain, lastConnectedWalletHelpers, recentConnectedWalletHelpers, selectAdapterByKey, setChainId, waitFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import { StoreApi } from 'zustand';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @file
|
|
5
3
|
* Core type definitions for the Orbit blockchain adapter system.
|
|
6
4
|
* This file contains fundamental enums and types that define the supported blockchain architectures
|
|
7
5
|
* and their adapter interfaces.
|
|
8
6
|
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A utility type for creating modular Zustand store slices, enabling composable state management.
|
|
12
|
-
* @template T The state slice being defined.
|
|
13
|
-
* @template S The full store state that includes the slice `T`.
|
|
14
|
-
*/
|
|
15
|
-
type StoreSlice<T extends object, S extends object = T> = (set: StoreApi<S extends T ? S : S & T>['setState'], get: StoreApi<S extends T ? S : S & T>['getState']) => T;
|
|
16
7
|
/**
|
|
17
8
|
* Defines the supported blockchain adapters in the Orbit system.
|
|
18
9
|
* Each adapter corresponds to a specific blockchain architecture and implements
|
|
@@ -110,88 +101,11 @@ type BaseAdapter = {
|
|
|
110
101
|
/** Optional method to get avatar for resolved names */
|
|
111
102
|
getAvatar?: (name: string) => Promise<string | null>;
|
|
112
103
|
};
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Helper utilities for managing impersonated wallet addresses
|
|
116
|
-
*
|
|
117
|
-
* @remarks
|
|
118
|
-
* These utilities are primarily used for development and testing purposes.
|
|
119
|
-
* They provide a way to simulate different wallet addresses without actually connecting a wallet.
|
|
120
|
-
* All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.
|
|
121
|
-
* Functions are safe to use in both browser and SSR environments.
|
|
122
|
-
*/
|
|
123
|
-
declare const connectedWalletChainHelpers: {
|
|
124
|
-
/**
|
|
125
|
-
* Currently impersonated address from localStorage
|
|
126
|
-
* Returns empty string if not set or in SSR context
|
|
127
|
-
*/
|
|
128
|
-
connectedWalletChain: string;
|
|
129
|
-
/**
|
|
130
|
-
* Stores an impersonated address in localStorage
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```typescript
|
|
134
|
-
* // Set impersonated address
|
|
135
|
-
* impersonatedHelpers.setImpersonated('0x1234...5678');
|
|
136
|
-
* ```
|
|
137
|
-
*
|
|
138
|
-
* @param address - Ethereum or Solana address to impersonate
|
|
139
|
-
* @returns undefined in SSR context, void in browser
|
|
140
|
-
*/
|
|
141
|
-
setConnectedWalletChain: (chain: string | number) => void;
|
|
142
|
-
/**
|
|
143
|
-
* Retrieves the current impersonated address from localStorage
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* ```typescript
|
|
147
|
-
* // Get current impersonated address
|
|
148
|
-
* const address = impersonatedHelpers.getImpersonated();
|
|
149
|
-
* if (address) {
|
|
150
|
-
* console.log('Currently impersonating:', address);
|
|
151
|
-
* }
|
|
152
|
-
* ```
|
|
153
|
-
* @returns The impersonated address or undefined if not set or in SSR context
|
|
154
|
-
*/
|
|
155
|
-
getConnectedWalletChain: () => string | null | undefined;
|
|
156
|
-
removeConnectedWalletChain: () => void;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.
|
|
161
|
-
* This pattern is recommended by the official Zustand documentation to ensure full type
|
|
162
|
-
* safety when integrating vanilla stores with React.
|
|
163
|
-
*
|
|
164
|
-
* @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
104
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* @template S - The type of the Zustand store (`StoreApi`).
|
|
105
|
+
* Type representing a wallet identifier in format "OrbitAdapter:wallet"
|
|
106
|
+
* @example "evm:metamask" | "solana:phantom"
|
|
171
107
|
*/
|
|
172
|
-
type
|
|
173
|
-
getState: () => infer T;
|
|
174
|
-
} ? T : never;
|
|
175
|
-
/**
|
|
176
|
-
* Creates a bounded `useStore` hook from a vanilla Zustand store.
|
|
177
|
-
*
|
|
178
|
-
* This function takes a vanilla Zustand store instance and returns a React hook
|
|
179
|
-
* that is pre-bound to that store. This approach provides a cleaner API and
|
|
180
|
-
* enhances type inference, eliminating the need to pass the store instance
|
|
181
|
-
* on every use.
|
|
182
|
-
*
|
|
183
|
-
* The returned hook supports two signatures:
|
|
184
|
-
* 1. `useBoundedStore()`: Selects the entire state.
|
|
185
|
-
* 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.
|
|
186
|
-
*
|
|
187
|
-
* @template S - The type of the Zustand store (`StoreApi`).
|
|
188
|
-
* @param {S} store - The vanilla Zustand store instance to bind the hook to.
|
|
189
|
-
* @returns {function} A fully typed React hook for accessing the store's state.
|
|
190
|
-
*/
|
|
191
|
-
declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) => {
|
|
192
|
-
(): ExtractState<S>;
|
|
193
|
-
<T>(selector: (state: ExtractState<S>) => T): T;
|
|
194
|
-
};
|
|
108
|
+
type WalletType = `${OrbitAdapter}:${string}`;
|
|
195
109
|
|
|
196
110
|
/**
|
|
197
111
|
* @name delay
|
|
@@ -240,6 +154,40 @@ declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
|
240
154
|
|
|
241
155
|
declare function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
242
156
|
|
|
157
|
+
declare const formatWalletName: (walletName: string) => string;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Extracts the adapter type from a wallet type string
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // Returns OrbitAdapter.EVM
|
|
165
|
+
* getAdapterFromWalletType('evm:metamask');
|
|
166
|
+
*
|
|
167
|
+
* // Returns OrbitAdapter.SOLANA
|
|
168
|
+
* getAdapterFromWalletType('solana:phantom');
|
|
169
|
+
*
|
|
170
|
+
* // Returns OrbitAdapter.EVM (default)
|
|
171
|
+
* getAdapterFromWalletType('unknown');
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @param walletType - Wallet type in format "chain:wallet" (e.g. "evm:metamask", "solana:phantom")
|
|
175
|
+
* @returns The corresponding {@link OrbitAdapter} type or EVM as default
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* The function splits the wallet type string by ":" and takes the first part as the adapter type.
|
|
179
|
+
* If the split fails or the first part is empty, it defaults to EVM adapter.
|
|
180
|
+
*/
|
|
181
|
+
declare function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Internal function for safely retrieving and parsing data from localStorage.
|
|
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
|
+
|
|
243
191
|
/**
|
|
244
192
|
* Generates a standardized wallet type identifier from adapter type and connector name
|
|
245
193
|
*
|
|
@@ -268,6 +216,129 @@ declare function formatWalletChainId(chainId: string | number, connectedAdapter:
|
|
|
268
216
|
*/
|
|
269
217
|
declare function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string;
|
|
270
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Helper utilities for managing impersonated wallet addresses
|
|
221
|
+
*
|
|
222
|
+
* @remarks
|
|
223
|
+
* These utilities are primarily used for development and testing purposes.
|
|
224
|
+
* They provide a way to simulate different wallet addresses without actually connecting a wallet.
|
|
225
|
+
* All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.
|
|
226
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
227
|
+
*/
|
|
228
|
+
declare const impersonatedHelpers: {
|
|
229
|
+
/**
|
|
230
|
+
* Currently impersonated address from localStorage
|
|
231
|
+
* Returns empty string if not set or in SSR context
|
|
232
|
+
*/
|
|
233
|
+
impersonatedAddress: string;
|
|
234
|
+
/**
|
|
235
|
+
* Stores an impersonated address in localStorage
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* // Set impersonated address
|
|
240
|
+
* impersonatedHelpers.setImpersonated('0x1234...5678');
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @param address - Ethereum or Solana address to impersonate
|
|
244
|
+
* @returns undefined in SSR context, void in browser
|
|
245
|
+
*/
|
|
246
|
+
setImpersonated: (address: string) => void;
|
|
247
|
+
/**
|
|
248
|
+
* Retrieves the current impersonated address from localStorage
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* // Get current impersonated address
|
|
253
|
+
* const address = impersonatedHelpers.getImpersonated();
|
|
254
|
+
* if (address) {
|
|
255
|
+
* console.log('Currently impersonating:', address);
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
* @returns The impersonated address or undefined if not set or in SSR context
|
|
259
|
+
*/
|
|
260
|
+
getImpersonated: () => string | null | undefined;
|
|
261
|
+
removeImpersonated: () => void;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
declare const isSafeApp: boolean;
|
|
265
|
+
|
|
266
|
+
type LastConnectedWallet = {
|
|
267
|
+
walletType: WalletType;
|
|
268
|
+
chainId: number | string;
|
|
269
|
+
address?: string;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Helper utilities for managing the last connected wallet state
|
|
273
|
+
*
|
|
274
|
+
* @remarks
|
|
275
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.
|
|
276
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
277
|
+
*/
|
|
278
|
+
declare const lastConnectedWalletHelpers: {
|
|
279
|
+
STORAGE_KEY: string;
|
|
280
|
+
/**
|
|
281
|
+
* The value of the last connected wallet, initialized when the module loads.
|
|
282
|
+
* Returns undefined if not set, invalid, or in an SSR context.
|
|
283
|
+
*/
|
|
284
|
+
lastConnectedWallet: LastConnectedWallet | undefined;
|
|
285
|
+
/**
|
|
286
|
+
* Stores the last connected wallet data in localStorage.
|
|
287
|
+
*
|
|
288
|
+
* @param data - Object containing the wallet type and chain ID.
|
|
289
|
+
* @returns undefined in SSR context, void in browser
|
|
290
|
+
*/
|
|
291
|
+
setLastConnectedWallet: ({ walletType, chainId }: LastConnectedWallet) => void;
|
|
292
|
+
/**
|
|
293
|
+
* Retrieves the current last connected wallet data from localStorage.
|
|
294
|
+
*
|
|
295
|
+
* @returns The LastConnectedWallet object or undefined if not set or in SSR context
|
|
296
|
+
*/
|
|
297
|
+
getLastConnectedWallet: () => LastConnectedWallet | undefined;
|
|
298
|
+
/**
|
|
299
|
+
* Removes the last connected wallet data from localStorage.
|
|
300
|
+
*
|
|
301
|
+
* @returns undefined in SSR context, void in browser
|
|
302
|
+
*/
|
|
303
|
+
removeLastConnectedWallet: () => void;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
type RecentConnectedWallet = Record<OrbitAdapter, Record<string, boolean>>;
|
|
307
|
+
/**
|
|
308
|
+
* Helper utilities for managing the last connected wallet state
|
|
309
|
+
*
|
|
310
|
+
* @remarks
|
|
311
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.
|
|
312
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
313
|
+
*/
|
|
314
|
+
declare const recentConnectedWalletHelpers: {
|
|
315
|
+
STORAGE_KEY: string;
|
|
316
|
+
/**
|
|
317
|
+
* The value of the last connected wallet, initialized when the module loads.
|
|
318
|
+
* Returns undefined if not set, invalid, or in an SSR context.
|
|
319
|
+
*/
|
|
320
|
+
recentConnectedWallet: RecentConnectedWallet | undefined;
|
|
321
|
+
/**
|
|
322
|
+
* Stores the last connected wallet data in localStorage.
|
|
323
|
+
*
|
|
324
|
+
* @param wallets - RecentConnectedWallet
|
|
325
|
+
* @returns undefined in SSR context, void in browser
|
|
326
|
+
*/
|
|
327
|
+
setRecentConnectedWallet: (wallets: RecentConnectedWallet) => void;
|
|
328
|
+
/**
|
|
329
|
+
* Retrieves the current last connected wallet data from localStorage.
|
|
330
|
+
*
|
|
331
|
+
* @returns The LastConnectedWallet object or undefined if not set or in SSR context
|
|
332
|
+
*/
|
|
333
|
+
getRecentConnectedWallet: () => RecentConnectedWallet | undefined;
|
|
334
|
+
/**
|
|
335
|
+
* Removes the last connected wallet data from localStorage.
|
|
336
|
+
*
|
|
337
|
+
* @returns undefined in SSR context, void in browser
|
|
338
|
+
*/
|
|
339
|
+
removeRecentConnectedWallet: () => void;
|
|
340
|
+
};
|
|
341
|
+
|
|
271
342
|
/**
|
|
272
343
|
* @file
|
|
273
344
|
* This module provides adapter selection functionality for the Orbit system.
|
|
@@ -317,6 +388,8 @@ declare const selectAdapterByKey: <A extends {
|
|
|
317
388
|
adapterKey: OrbitAdapter;
|
|
318
389
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
319
390
|
|
|
391
|
+
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
392
|
+
|
|
320
393
|
/**
|
|
321
394
|
* Checks whether the given chain ID belongs to a Solana network.
|
|
322
395
|
* Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.
|
|
@@ -333,4 +406,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
333
406
|
*/
|
|
334
407
|
declare function setChainId(chainId: number | string): string | number;
|
|
335
408
|
|
|
336
|
-
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type
|
|
409
|
+
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type RecentConnectedWallet, type WalletType, delay, filterUniqueByKey, formatWalletChainId, formatWalletName, getAdapterFromWalletType, getParsedStorageItem, getWalletTypeFromConnectorName, impersonatedHelpers, isSafeApp, isSolanaChain, lastConnectedWalletHelpers, recentConnectedWalletHelpers, selectAdapterByKey, setChainId, waitFor };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var l=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(l||{});var f=(e,t)=>new Promise(n=>{let r=()=>{setTimeout(()=>n(e),t);};typeof window<"u"?r():setTimeout(r,0);});function m(e,t){let n=new Set;return e.filter(r=>{let i=r[t];return n.has(i)?false:(n.add(i),true)})}function w(e,t){return typeof e=="string"?`${t}:${e}`:e}var y=e=>{switch(e){case "Impersonated Connector":return "impersonatedwallet";case "Safe":return "safewallet";default:return e.replace(/\s+/g,"").toLowerCase()}};function T(e){return e.split(":")[0]??"evm"}function o(e){if(typeof window>"u")return;let t=window.localStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(n){console.error(`Error parsing ${e} from localStorage:`,n);return}}function C(e,t){return `${e}:${t.replace(/\s+/g,"").toLowerCase()}`}var E={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:e=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",e):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0,removeImpersonated:()=>typeof window<"u"?window.localStorage.removeItem("satellite-connect:impersonatedAddress"):void 0};var I=typeof window<"u"&&window!==window.parent;var a={STORAGE_KEY:"orbit-core:lastConnectedWallet",lastConnectedWallet:o("orbit-core:lastConnectedWallet"),setLastConnectedWallet:({walletType:e,chainId:t})=>typeof window<"u"?window.localStorage.setItem(a.STORAGE_KEY,JSON.stringify({walletType:e,chainId:t})):void 0,getLastConnectedWallet:()=>o(a.STORAGE_KEY),removeLastConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(a.STORAGE_KEY):void 0};var d={STORAGE_KEY:"orbit-core:recentConnectedWallet",recentConnectedWallet:o("orbit-core:recentConnectedWallets"),setRecentConnectedWallet:e=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentConnectedWallet:()=>o(d.STORAGE_KEY),removeRecentConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var $=({adapterKey:e,adapter:t})=>{if(Array.isArray(t)){if(t.length===0){console.error("Adapter selection failed: The provided adapters array is empty.");return}let n=t.find(r=>r.key===e);return n||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${t[0].key}".`),t[0])}return t};async function Y(e,t=50,n=200){for(let r=0;r<t;r++){if(e())return;await new Promise(i=>setTimeout(i,n));}throw new Error("Predicate not fulfilled in time")}function s(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function h(e){return s(e)?`solana:${e}`:e}exports.OrbitAdapter=l;exports.delay=f;exports.filterUniqueByKey=m;exports.formatWalletChainId=w;exports.formatWalletName=y;exports.getAdapterFromWalletType=T;exports.getParsedStorageItem=o;exports.getWalletTypeFromConnectorName=C;exports.impersonatedHelpers=E;exports.isSafeApp=I;exports.isSolanaChain=s;exports.lastConnectedWalletHelpers=a;exports.recentConnectedWalletHelpers=d;exports.selectAdapterByKey=$;exports.setChainId=h;exports.waitFor=Y;//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|