@solana/connector 0.1.7 → 0.1.8
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 +83 -5
- package/dist/{chunk-APQGEW7S.mjs → chunk-6F6M6L7R.mjs} +73 -165
- package/dist/chunk-6F6M6L7R.mjs.map +1 -0
- package/dist/{chunk-VZ5Y6DIM.js → chunk-AOIXHVRH.js} +80 -235
- package/dist/chunk-AOIXHVRH.js.map +1 -0
- package/dist/chunk-DSUCH44G.js +678 -0
- package/dist/chunk-DSUCH44G.js.map +1 -0
- package/dist/{chunk-VA6LKXCQ.js → chunk-FTXIXM43.js} +157 -263
- package/dist/chunk-FTXIXM43.js.map +1 -0
- package/dist/{chunk-TQRJYZNK.mjs → chunk-G575OAT4.mjs} +71 -218
- package/dist/chunk-G575OAT4.mjs.map +1 -0
- package/dist/chunk-J7DHGLW6.mjs +638 -0
- package/dist/chunk-J7DHGLW6.mjs.map +1 -0
- package/dist/{chunk-Z22V3D4E.js → chunk-K3BNIGPX.js} +95 -37
- package/dist/chunk-K3BNIGPX.js.map +1 -0
- package/dist/{chunk-JK47EFJT.mjs → chunk-TTOKQAPX.mjs} +65 -14
- package/dist/chunk-TTOKQAPX.mjs.map +1 -0
- package/dist/compat.d.mts +1 -1
- package/dist/compat.d.ts +1 -1
- package/dist/compat.js +40 -39
- package/dist/compat.js.map +1 -1
- package/dist/compat.mjs +39 -38
- package/dist/compat.mjs.map +1 -1
- package/dist/headless.d.mts +447 -151
- package/dist/headless.d.ts +447 -151
- package/dist/headless.js +214 -194
- package/dist/headless.mjs +3 -3
- package/dist/index.d.mts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +268 -224
- package/dist/index.mjs +4 -4
- package/dist/react.d.mts +108 -7
- package/dist/react.d.ts +108 -7
- package/dist/react.js +54 -30
- package/dist/react.mjs +2 -2
- package/dist/{wallet-standard-shim-DiMvGjOk.d.ts → standard-shim-CT49DM5l.d.mts} +38 -247
- package/dist/{wallet-standard-shim-D4CYG5sU.d.mts → standard-shim-D9guL5fz.d.ts} +38 -247
- package/dist/{transaction-signer-CpGEvp7S.d.mts → transaction-signer-T-KVQFi8.d.mts} +1 -1
- package/dist/{transaction-signer-CpGEvp7S.d.ts → transaction-signer-T-KVQFi8.d.ts} +1 -1
- package/package.json +3 -3
- package/dist/chunk-APQGEW7S.mjs.map +0 -1
- package/dist/chunk-I64FD2EH.js +0 -312
- package/dist/chunk-I64FD2EH.js.map +0 -1
- package/dist/chunk-JK47EFJT.mjs.map +0 -1
- package/dist/chunk-QL3IT3TS.mjs +0 -299
- package/dist/chunk-QL3IT3TS.mjs.map +0 -1
- package/dist/chunk-TQRJYZNK.mjs.map +0 -1
- package/dist/chunk-VA6LKXCQ.js.map +0 -1
- package/dist/chunk-VZ5Y6DIM.js.map +0 -1
- package/dist/chunk-Z22V3D4E.js.map +0 -1
package/README.md
CHANGED
|
@@ -911,6 +911,85 @@ Token prices are cached for 60 seconds to minimize API calls. The retry logic on
|
|
|
911
911
|
|
|
912
912
|
## Advanced Usage
|
|
913
913
|
|
|
914
|
+
### Error Handling with `tryCatch`
|
|
915
|
+
|
|
916
|
+
ConnectorKit exports a `tryCatch` utility for consistent async error handling:
|
|
917
|
+
|
|
918
|
+
```typescript
|
|
919
|
+
import { tryCatch } from '@solana/connector/headless';
|
|
920
|
+
|
|
921
|
+
// Instead of try/catch blocks
|
|
922
|
+
async function sendTransaction() {
|
|
923
|
+
const { data: signature, error } = await tryCatch(signer.signAndSendTransaction(transaction));
|
|
924
|
+
|
|
925
|
+
if (error) {
|
|
926
|
+
console.error('Transaction failed:', error.message);
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
console.log('Transaction sent:', signature);
|
|
931
|
+
}
|
|
932
|
+
```
|
|
933
|
+
|
|
934
|
+
The `tryCatch` utility returns a `Result<T, E>` type that's either a success with `data` or a failure with `error`:
|
|
935
|
+
|
|
936
|
+
```typescript
|
|
937
|
+
interface Success<T> {
|
|
938
|
+
data: T;
|
|
939
|
+
error: null;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
interface Failure<E> {
|
|
943
|
+
data: null;
|
|
944
|
+
error: E;
|
|
945
|
+
}
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
Also available: `tryCatchSync` for synchronous operations, and `isSuccess`/`isFailure` type guards.
|
|
949
|
+
|
|
950
|
+
### Cache Invalidation with Query Keys
|
|
951
|
+
|
|
952
|
+
For advanced cache management, ConnectorKit exports query key generators:
|
|
953
|
+
|
|
954
|
+
```typescript
|
|
955
|
+
import {
|
|
956
|
+
getBalanceQueryKey,
|
|
957
|
+
getTokensQueryKey,
|
|
958
|
+
getTransactionsQueryKey,
|
|
959
|
+
invalidateSharedQuery,
|
|
960
|
+
} from '@solana/connector/react';
|
|
961
|
+
|
|
962
|
+
// After sending a transaction, invalidate relevant caches
|
|
963
|
+
async function sendAndRefresh() {
|
|
964
|
+
await sendTransaction();
|
|
965
|
+
|
|
966
|
+
// Invalidate balance and tokens (they share the same cache)
|
|
967
|
+
const balanceKey = getBalanceQueryKey(rpcUrl, address);
|
|
968
|
+
if (balanceKey) invalidateSharedQuery(balanceKey);
|
|
969
|
+
|
|
970
|
+
// Invalidate transactions
|
|
971
|
+
const txKey = getTransactionsQueryKey({ rpcUrl, address, clusterId });
|
|
972
|
+
if (txKey) invalidateSharedQuery(txKey);
|
|
973
|
+
}
|
|
974
|
+
```
|
|
975
|
+
|
|
976
|
+
### Configuration Validation
|
|
977
|
+
|
|
978
|
+
Configuration is validated at runtime using Zod schemas. For manual validation:
|
|
979
|
+
|
|
980
|
+
```typescript
|
|
981
|
+
import { validateConfigOptions } from '@solana/connector/headless';
|
|
982
|
+
|
|
983
|
+
const result = validateConfigOptions({
|
|
984
|
+
appName: 'My App',
|
|
985
|
+
network: 'mainnet',
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
if (!result.success) {
|
|
989
|
+
console.error('Validation errors:', result.error.issues);
|
|
990
|
+
}
|
|
991
|
+
```
|
|
992
|
+
|
|
914
993
|
### Headless Client (Vue, Svelte, Vanilla JS)
|
|
915
994
|
|
|
916
995
|
Use `ConnectorClient` for non-React frameworks:
|
|
@@ -1021,11 +1100,10 @@ import { useConnector, useAccount } from '@solana/connector/react';
|
|
|
1021
1100
|
|
|
1022
1101
|
### Configuration Functions
|
|
1023
1102
|
|
|
1024
|
-
| Function | Description
|
|
1025
|
-
| --------------------------------- |
|
|
1026
|
-
| `getDefaultConfig(options)` | Create default connector configuration
|
|
1027
|
-
| `getDefaultMobileConfig(options)` | Create mobile wallet adapter configuration
|
|
1028
|
-
| `createConfig(options)` | Create unified config for ConnectorKit + Armadura |
|
|
1103
|
+
| Function | Description |
|
|
1104
|
+
| --------------------------------- | ------------------------------------------ |
|
|
1105
|
+
| `getDefaultConfig(options)` | Create default connector configuration |
|
|
1106
|
+
| `getDefaultMobileConfig(options)` | Create mobile wallet adapter configuration |
|
|
1029
1107
|
|
|
1030
1108
|
### Utility Functions
|
|
1031
1109
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createLogger, __publicField,
|
|
1
|
+
import { createLogger, getPublicSolanaRpcUrl, getExplorerLink, __publicField, tryCatchSync, TransactionError, isWeb3jsTransaction, Errors, prepareTransactionForWallet, convertSignedTransaction, ValidationError, isConnectorError } from './chunk-J7DHGLW6.mjs';
|
|
2
2
|
import { Component, useTransition, useState, useCallback, useMemo } from 'react';
|
|
3
3
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
4
4
|
import { install } from '@solana/webcrypto-ed25519-polyfill';
|
|
@@ -6,8 +6,25 @@ import { address, isAddress } from '@solana/addresses';
|
|
|
6
6
|
import { getTransactionDecoder, assertIsTransactionWithinSizeLimit } from '@solana/transactions';
|
|
7
7
|
import { getBase58Decoder } from '@solana/codecs';
|
|
8
8
|
|
|
9
|
-
// src/lib/
|
|
10
|
-
var registry = null
|
|
9
|
+
// src/lib/wallet/standard-shim.ts
|
|
10
|
+
var registry = null, registryInitPromise = null, registryInitResolve = null, ready = new Promise((resolve, reject) => {
|
|
11
|
+
if (typeof window > "u") {
|
|
12
|
+
resolve();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
registryInitResolve = resolve;
|
|
16
|
+
let nav = window.navigator;
|
|
17
|
+
if (nav.wallets && typeof nav.wallets.get == "function") {
|
|
18
|
+
registry = nav.wallets, resolve();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
registryInitPromise = import('@wallet-standard/app').then((mod) => {
|
|
22
|
+
let walletStandardRegistry = mod.getWallets?.();
|
|
23
|
+
walletStandardRegistry && (registry = walletStandardRegistry), resolve();
|
|
24
|
+
}).catch((err) => {
|
|
25
|
+
console.warn("[standard-shim] Failed to load @wallet-standard/app:", err), resolve();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
11
28
|
function getWalletsRegistry() {
|
|
12
29
|
if (typeof window > "u")
|
|
13
30
|
return {
|
|
@@ -15,12 +32,13 @@ function getWalletsRegistry() {
|
|
|
15
32
|
on: () => () => {
|
|
16
33
|
}
|
|
17
34
|
};
|
|
18
|
-
if (!registry) {
|
|
35
|
+
if (!registry && !registryInitPromise) {
|
|
19
36
|
let nav = window.navigator;
|
|
20
|
-
nav.wallets && typeof nav.wallets.get == "function" ? registry = nav.wallets : import('@wallet-standard/app').then((mod) => {
|
|
37
|
+
nav.wallets && typeof nav.wallets.get == "function" ? (registry = nav.wallets, registryInitResolve?.()) : registryInitPromise = import('@wallet-standard/app').then((mod) => {
|
|
21
38
|
let walletStandardRegistry = mod.getWallets?.();
|
|
22
|
-
walletStandardRegistry && (registry = walletStandardRegistry);
|
|
39
|
+
walletStandardRegistry && (registry = walletStandardRegistry), registryInitResolve?.();
|
|
23
40
|
}).catch(() => {
|
|
41
|
+
registryInitResolve?.();
|
|
24
42
|
});
|
|
25
43
|
}
|
|
26
44
|
return {
|
|
@@ -49,135 +67,6 @@ function getWalletsRegistry() {
|
|
|
49
67
|
};
|
|
50
68
|
}
|
|
51
69
|
|
|
52
|
-
// src/lib/errors/index.ts
|
|
53
|
-
var ConnectorError = class extends Error {
|
|
54
|
-
constructor(message, context, originalError) {
|
|
55
|
-
super(message);
|
|
56
|
-
__publicField(this, "context");
|
|
57
|
-
__publicField(this, "originalError");
|
|
58
|
-
__publicField(this, "timestamp");
|
|
59
|
-
this.name = this.constructor.name, this.context = context, this.originalError = originalError, this.timestamp = (/* @__PURE__ */ new Date()).toISOString(), Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
|
|
60
|
-
}
|
|
61
|
-
toJSON() {
|
|
62
|
-
return {
|
|
63
|
-
name: this.name,
|
|
64
|
-
code: this.code,
|
|
65
|
-
message: this.message,
|
|
66
|
-
recoverable: this.recoverable,
|
|
67
|
-
context: this.context,
|
|
68
|
-
timestamp: this.timestamp,
|
|
69
|
-
originalError: this.originalError?.message
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
}, ConnectionError = class extends ConnectorError {
|
|
73
|
-
constructor(code, message, context, originalError) {
|
|
74
|
-
super(message, context, originalError);
|
|
75
|
-
__publicField(this, "code");
|
|
76
|
-
__publicField(this, "recoverable", true);
|
|
77
|
-
this.code = code;
|
|
78
|
-
}
|
|
79
|
-
}, ValidationError = class extends ConnectorError {
|
|
80
|
-
constructor(code, message, context, originalError) {
|
|
81
|
-
super(message, context, originalError);
|
|
82
|
-
__publicField(this, "code");
|
|
83
|
-
__publicField(this, "recoverable", false);
|
|
84
|
-
this.code = code;
|
|
85
|
-
}
|
|
86
|
-
}, ConfigurationError = class extends ConnectorError {
|
|
87
|
-
constructor(code, message, context, originalError) {
|
|
88
|
-
super(message, context, originalError);
|
|
89
|
-
__publicField(this, "code");
|
|
90
|
-
__publicField(this, "recoverable", false);
|
|
91
|
-
this.code = code;
|
|
92
|
-
}
|
|
93
|
-
}, NetworkError = class extends ConnectorError {
|
|
94
|
-
constructor(code, message, context, originalError) {
|
|
95
|
-
super(message, context, originalError);
|
|
96
|
-
__publicField(this, "code");
|
|
97
|
-
__publicField(this, "recoverable", true);
|
|
98
|
-
this.code = code;
|
|
99
|
-
}
|
|
100
|
-
}, TransactionError = class extends ConnectorError {
|
|
101
|
-
constructor(code, message, context, originalError) {
|
|
102
|
-
super(message, context, originalError);
|
|
103
|
-
__publicField(this, "code");
|
|
104
|
-
__publicField(this, "recoverable");
|
|
105
|
-
this.code = code, this.recoverable = ["USER_REJECTED", "SEND_FAILED", "SIMULATION_FAILED"].includes(code);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
function isConnectorError(error) {
|
|
109
|
-
return error instanceof ConnectorError;
|
|
110
|
-
}
|
|
111
|
-
function isConnectionError(error) {
|
|
112
|
-
return error instanceof ConnectionError;
|
|
113
|
-
}
|
|
114
|
-
function isValidationError(error) {
|
|
115
|
-
return error instanceof ValidationError;
|
|
116
|
-
}
|
|
117
|
-
function isConfigurationError(error) {
|
|
118
|
-
return error instanceof ConfigurationError;
|
|
119
|
-
}
|
|
120
|
-
function isNetworkError(error) {
|
|
121
|
-
return error instanceof NetworkError;
|
|
122
|
-
}
|
|
123
|
-
function isTransactionError(error) {
|
|
124
|
-
return error instanceof TransactionError;
|
|
125
|
-
}
|
|
126
|
-
var Errors = {
|
|
127
|
-
walletNotConnected: (context) => new ConnectionError("WALLET_NOT_CONNECTED", "No wallet connected", context),
|
|
128
|
-
walletNotFound: (walletName) => new ConnectionError("WALLET_NOT_FOUND", `Wallet not found${walletName ? `: ${walletName}` : ""}`, {
|
|
129
|
-
walletName
|
|
130
|
-
}),
|
|
131
|
-
connectionFailed: (originalError) => new ConnectionError("CONNECTION_FAILED", "Failed to connect to wallet", void 0, originalError),
|
|
132
|
-
accountNotAvailable: (address) => new ConnectionError("ACCOUNT_NOT_AVAILABLE", "Requested account not available", { address }),
|
|
133
|
-
invalidTransaction: (reason, context) => new ValidationError("INVALID_TRANSACTION", `Invalid transaction: ${reason}`, context),
|
|
134
|
-
invalidFormat: (expectedFormat, actualFormat) => new ValidationError("INVALID_FORMAT", `Invalid format: expected ${expectedFormat}`, {
|
|
135
|
-
expectedFormat,
|
|
136
|
-
actualFormat
|
|
137
|
-
}),
|
|
138
|
-
unsupportedFormat: (format) => new ValidationError("UNSUPPORTED_FORMAT", `Unsupported format: ${format}`, { format }),
|
|
139
|
-
missingProvider: (hookName) => new ConfigurationError(
|
|
140
|
-
"MISSING_PROVIDER",
|
|
141
|
-
`${hookName} must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider>.`,
|
|
142
|
-
{ hookName }
|
|
143
|
-
),
|
|
144
|
-
clusterNotFound: (clusterId, availableClusters) => new ConfigurationError(
|
|
145
|
-
"CLUSTER_NOT_FOUND",
|
|
146
|
-
`Cluster ${clusterId} not found. Available clusters: ${availableClusters.join(", ")}`,
|
|
147
|
-
{ clusterId, availableClusters }
|
|
148
|
-
),
|
|
149
|
-
rpcError: (message, originalError) => new NetworkError("RPC_ERROR", message, void 0, originalError),
|
|
150
|
-
networkTimeout: () => new NetworkError("NETWORK_TIMEOUT", "Network request timed out"),
|
|
151
|
-
signingFailed: (originalError) => new TransactionError("SIGNING_FAILED", "Failed to sign transaction", void 0, originalError),
|
|
152
|
-
featureNotSupported: (feature) => new TransactionError("FEATURE_NOT_SUPPORTED", `Wallet does not support ${feature}`, { feature }),
|
|
153
|
-
userRejected: (operation) => new TransactionError("USER_REJECTED", `User rejected ${operation}`, { operation })
|
|
154
|
-
};
|
|
155
|
-
function toConnectorError(error, defaultMessage = "An unexpected error occurred") {
|
|
156
|
-
if (isConnectorError(error))
|
|
157
|
-
return error;
|
|
158
|
-
if (error instanceof Error) {
|
|
159
|
-
let message = error.message.toLowerCase();
|
|
160
|
-
return message.includes("user rejected") || message.includes("user denied") ? Errors.userRejected("transaction") : message.includes("wallet not found") || message.includes("not installed") ? Errors.walletNotFound() : message.includes("not connected") ? Errors.walletNotConnected() : message.includes("network") || message.includes("fetch") ? Errors.rpcError(error.message, error) : message.includes("invalid") ? new ValidationError("VALIDATION_FAILED", error.message, void 0, error) : new TransactionError("SIGNING_FAILED", error.message, void 0, error);
|
|
161
|
-
}
|
|
162
|
-
return new TransactionError("SIGNING_FAILED", defaultMessage, { originalError: String(error) });
|
|
163
|
-
}
|
|
164
|
-
function getUserFriendlyMessage(error) {
|
|
165
|
-
return isConnectorError(error) ? {
|
|
166
|
-
WALLET_NOT_CONNECTED: "Please connect your wallet to continue.",
|
|
167
|
-
WALLET_NOT_FOUND: "Wallet not found. Please install a supported wallet.",
|
|
168
|
-
CONNECTION_FAILED: "Failed to connect to wallet. Please try again.",
|
|
169
|
-
USER_REJECTED: "Transaction was cancelled.",
|
|
170
|
-
FEATURE_NOT_SUPPORTED: "This wallet does not support this feature.",
|
|
171
|
-
SIGNING_FAILED: "Failed to sign transaction. Please try again.",
|
|
172
|
-
SEND_FAILED: "Failed to send transaction. Please try again.",
|
|
173
|
-
INVALID_CLUSTER: "Invalid network configuration.",
|
|
174
|
-
CLUSTER_NOT_FOUND: "Network not found.",
|
|
175
|
-
MISSING_PROVIDER: "Application not properly configured.",
|
|
176
|
-
RPC_ERROR: "Network error. Please check your connection.",
|
|
177
|
-
NETWORK_TIMEOUT: "Request timed out. Please try again."
|
|
178
|
-
}[error.code] || error.message || "An error occurred." : "An unexpected error occurred. Please try again.";
|
|
179
|
-
}
|
|
180
|
-
|
|
181
70
|
// src/utils/network.ts
|
|
182
71
|
var PUBLIC_RPC_ENDPOINTS = {
|
|
183
72
|
mainnet: "https://api.mainnet-beta.solana.com",
|
|
@@ -521,7 +410,7 @@ var BaseCollaborator = class {
|
|
|
521
410
|
}
|
|
522
411
|
};
|
|
523
412
|
|
|
524
|
-
// src/lib/
|
|
413
|
+
// src/lib/wallet/authenticity-verifier.ts
|
|
525
414
|
var logger2 = createLogger("WalletAuthenticity"), WalletAuthenticityVerifier = class {
|
|
526
415
|
/**
|
|
527
416
|
* Verify a wallet's authenticity using dynamic heuristics
|
|
@@ -731,7 +620,7 @@ var logger2 = createLogger("WalletAuthenticity"), WalletAuthenticityVerifier = c
|
|
|
731
620
|
}
|
|
732
621
|
};
|
|
733
622
|
|
|
734
|
-
// src/lib/
|
|
623
|
+
// src/lib/wallet/detector.ts
|
|
735
624
|
var logger3 = createLogger("WalletDetector");
|
|
736
625
|
function hasFeature(wallet, featureName) {
|
|
737
626
|
return wallet.features != null && wallet.features[featureName] !== void 0;
|
|
@@ -757,7 +646,14 @@ var WalletDetector = class extends BaseCollaborator {
|
|
|
757
646
|
__publicField(this, "unsubscribers", []);
|
|
758
647
|
}
|
|
759
648
|
/**
|
|
760
|
-
* Initialize wallet detection
|
|
649
|
+
* Initialize wallet detection (synchronous)
|
|
650
|
+
*
|
|
651
|
+
* Sets up registry listeners immediately. Due to the async nature of registry initialization,
|
|
652
|
+
* the initial call to `get()` may return an empty array if called before the registry is ready.
|
|
653
|
+
* Event listeners will fire as wallets register, providing eventual consistency.
|
|
654
|
+
*
|
|
655
|
+
* For deterministic detection where you need all wallets available immediately,
|
|
656
|
+
* use `initializeAsync()` instead.
|
|
761
657
|
*/
|
|
762
658
|
initialize() {
|
|
763
659
|
if (!(typeof window > "u"))
|
|
@@ -780,6 +676,24 @@ var WalletDetector = class extends BaseCollaborator {
|
|
|
780
676
|
} catch {
|
|
781
677
|
}
|
|
782
678
|
}
|
|
679
|
+
/**
|
|
680
|
+
* Initialize wallet detection with deterministic registry availability (async)
|
|
681
|
+
*
|
|
682
|
+
* Awaits the registry `ready` Promise before performing initial detection,
|
|
683
|
+
* ensuring all registered wallets are available on the first `get()` call.
|
|
684
|
+
*
|
|
685
|
+
* Use this when you need guaranteed wallet availability before proceeding
|
|
686
|
+
* (e.g., auto-reconnect logic, checking if a specific wallet is installed).
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* ```ts
|
|
690
|
+
* await walletDetector.initializeAsync();
|
|
691
|
+
* const wallets = walletDetector.getDetectedWallets(); // Guaranteed populated
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
async initializeAsync() {
|
|
695
|
+
typeof window > "u" || (await ready, this.initialize());
|
|
696
|
+
}
|
|
783
697
|
/**
|
|
784
698
|
* Check if a specific wallet is available immediately via direct window object detection
|
|
785
699
|
*/
|
|
@@ -866,7 +780,7 @@ var WalletDetector = class extends BaseCollaborator {
|
|
|
866
780
|
}
|
|
867
781
|
};
|
|
868
782
|
|
|
869
|
-
// src/lib/
|
|
783
|
+
// src/lib/wallet/connection-manager.ts
|
|
870
784
|
function getConnectFeature(wallet) {
|
|
871
785
|
return wallet.features["standard:connect"]?.connect ?? null;
|
|
872
786
|
}
|
|
@@ -1076,7 +990,7 @@ var ConnectionManager = class extends BaseCollaborator {
|
|
|
1076
990
|
}
|
|
1077
991
|
};
|
|
1078
992
|
|
|
1079
|
-
// src/lib/
|
|
993
|
+
// src/lib/wallet/auto-connector.ts
|
|
1080
994
|
var logger4 = createLogger("AutoConnector"), MIN_ADDRESS_LENGTH = 30, AutoConnector = class {
|
|
1081
995
|
constructor(walletDetector, connectionManager, stateManager, walletStorage, debug = false) {
|
|
1082
996
|
__publicField(this, "walletDetector");
|
|
@@ -1190,7 +1104,7 @@ var logger4 = createLogger("AutoConnector"), MIN_ADDRESS_LENGTH = 30, AutoConnec
|
|
|
1190
1104
|
]
|
|
1191
1105
|
},
|
|
1192
1106
|
true
|
|
1193
|
-
);
|
|
1107
|
+
), await ready;
|
|
1194
1108
|
let walletsApi = getWalletsRegistry(), registryWallet = walletsApi.get().find((w) => w.name === storedWalletName), walletToUse = registryWallet || wallet;
|
|
1195
1109
|
return this.debug && logger4.info("Attempting to connect via instant auto-connect", {
|
|
1196
1110
|
walletName: storedWalletName,
|
|
@@ -1446,16 +1360,15 @@ var logger5 = createLogger("ConnectorClient"), ConnectorClient = class {
|
|
|
1446
1360
|
), this.initialize();
|
|
1447
1361
|
}
|
|
1448
1362
|
initialize() {
|
|
1449
|
-
if (
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
}
|
|
1363
|
+
if (typeof window > "u" || this.initialized) return;
|
|
1364
|
+
let { error } = tryCatchSync(() => {
|
|
1365
|
+
this.walletDetector.initialize(), this.config.autoConnect && setTimeout(() => {
|
|
1366
|
+
this.autoConnector.attemptAutoConnect().catch((err) => {
|
|
1367
|
+
this.config.debug && logger5.error("Auto-connect error", { error: err });
|
|
1368
|
+
});
|
|
1369
|
+
}, 100), this.initialized = true;
|
|
1370
|
+
});
|
|
1371
|
+
error && this.config.debug && logger5.error("Connector initialization failed", { error });
|
|
1459
1372
|
}
|
|
1460
1373
|
async select(walletName) {
|
|
1461
1374
|
let wallet = this.stateManager.getSnapshot().wallets.find((w) => w.wallet.name === walletName)?.wallet;
|
|
@@ -1480,11 +1393,8 @@ var logger5 = createLogger("ConnectorClient"), ConnectorClient = class {
|
|
|
1480
1393
|
getRpcUrl() {
|
|
1481
1394
|
let cluster = this.clusterManager.getCluster();
|
|
1482
1395
|
if (!cluster) return null;
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
} catch (error) {
|
|
1486
|
-
return this.config.debug && logger5.error("Failed to get RPC URL", { error }), null;
|
|
1487
|
-
}
|
|
1396
|
+
let { data, error } = tryCatchSync(() => getClusterRpcUrl(cluster));
|
|
1397
|
+
return error ? (this.config.debug && logger5.error("Failed to get RPC URL", { error }), null) : data;
|
|
1488
1398
|
}
|
|
1489
1399
|
subscribe(listener) {
|
|
1490
1400
|
return this.stateManager.subscribe(listener);
|
|
@@ -1497,12 +1407,10 @@ var logger5 = createLogger("ConnectorClient"), ConnectorClient = class {
|
|
|
1497
1407
|
let storageKeys = ["account", "wallet", "cluster"];
|
|
1498
1408
|
for (let key of storageKeys) {
|
|
1499
1409
|
let storage = this.config.storage?.[key];
|
|
1500
|
-
if (storage && "reset" in storage && typeof storage.reset == "function")
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
this.config.debug && logger5.error("Failed to reset storage", { key, error });
|
|
1505
|
-
}
|
|
1410
|
+
if (storage && "reset" in storage && typeof storage.reset == "function") {
|
|
1411
|
+
let resetFn = storage.reset, { error } = tryCatchSync(() => resetFn());
|
|
1412
|
+
error ? this.config.debug && logger5.error("Failed to reset storage", { key, error }) : this.config.debug && logger5.debug("Reset storage", { key });
|
|
1413
|
+
}
|
|
1506
1414
|
}
|
|
1507
1415
|
this.eventEmitter.emit({
|
|
1508
1416
|
type: "storage:reset",
|
|
@@ -2518,6 +2426,6 @@ function createKitTransactionSigner(connectorSigner) {
|
|
|
2518
2426
|
}
|
|
2519
2427
|
var createGillTransactionSigner = createKitTransactionSigner;
|
|
2520
2428
|
|
|
2521
|
-
export { ClipboardErrorType,
|
|
2522
|
-
//# sourceMappingURL=chunk-
|
|
2523
|
-
//# sourceMappingURL=chunk-
|
|
2429
|
+
export { ClipboardErrorType, ConnectorClient, ConnectorErrorBoundary, DEFAULT_MAX_RETRIES, PUBLIC_RPC_ENDPOINTS, TransactionSignerError, WalletErrorType, copyAddressToClipboard, copySignatureToClipboard, copyToClipboard, createGillTransactionSigner, createKitTransactionSigner, createTransactionSigner, formatAddress, formatBigIntBalance, formatBigIntUsd, formatLamportsToSolSafe, formatNumber, formatSOL, formatTokenAmount, formatTokenBalanceSafe, getAddressUrl, getBlockUrl, getChainIdForWalletStandard, getClusterChainId, getClusterExplorerUrl, getClusterName, getClusterRpcUrl, getClusterType, getDefaultRpcUrl, getNetworkDisplayName, getPolyfillStatus, getTokenUrl, getTransactionUrl, getWalletsRegistry, installPolyfills, isClipboardAvailable, isCryptoAvailable, isDevnet, isDevnetCluster, isLocalCluster, isLocalnet, isMainnet, isMainnetCluster, isPolyfillInstalled, isTestnet, isTestnetCluster, isTransactionSignerError, normalizeNetwork, ready, toClusterId, truncate, withErrorBoundary };
|
|
2430
|
+
//# sourceMappingURL=chunk-6F6M6L7R.mjs.map
|
|
2431
|
+
//# sourceMappingURL=chunk-6F6M6L7R.mjs.map
|