@solana/connector 0.1.6 → 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 +122 -44
- package/dist/{chunk-VMSZJPR5.mjs → chunk-6F6M6L7R.mjs} +152 -173
- package/dist/chunk-6F6M6L7R.mjs.map +1 -0
- package/dist/{chunk-NQXK7PGX.js → chunk-AOIXHVRH.js} +82 -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-JUZVCBAI.js → chunk-FTXIXM43.js} +240 -271
- package/dist/chunk-FTXIXM43.js.map +1 -0
- package/dist/{chunk-QKVL45F6.mjs → chunk-G575OAT4.mjs} +73 -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-ULUYX23Q.js → chunk-K3BNIGPX.js} +1023 -404
- package/dist/chunk-K3BNIGPX.js.map +1 -0
- package/dist/{chunk-3STZXVXD.mjs → chunk-TTOKQAPX.mjs} +998 -388
- 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 +540 -152
- package/dist/headless.d.ts +540 -152
- package/dist/headless.js +226 -190
- package/dist/headless.mjs +3 -3
- package/dist/index.d.mts +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.js +286 -218
- package/dist/index.mjs +4 -4
- package/dist/react.d.mts +283 -16
- package/dist/react.d.ts +283 -16
- package/dist/react.js +60 -28
- package/dist/react.mjs +2 -2
- package/dist/{wallet-standard-shim--YcrQNRt.d.ts → standard-shim-CT49DM5l.d.mts} +72 -252
- package/dist/{wallet-standard-shim-Dx7H8Ctf.d.mts → standard-shim-D9guL5fz.d.ts} +72 -252
- package/dist/{transaction-signer-D9d8nxwb.d.mts → transaction-signer-T-KVQFi8.d.mts} +2 -2
- package/dist/{transaction-signer-D9d8nxwb.d.ts → transaction-signer-T-KVQFi8.d.ts} +2 -2
- package/package.json +3 -3
- package/dist/chunk-3STZXVXD.mjs.map +0 -1
- package/dist/chunk-I64FD2EH.js +0 -312
- package/dist/chunk-I64FD2EH.js.map +0 -1
- package/dist/chunk-JUZVCBAI.js.map +0 -1
- package/dist/chunk-NQXK7PGX.js.map +0 -1
- package/dist/chunk-QKVL45F6.mjs.map +0 -1
- package/dist/chunk-QL3IT3TS.mjs +0 -299
- package/dist/chunk-QL3IT3TS.mjs.map +0 -1
- package/dist/chunk-ULUYX23Q.js.map +0 -1
- package/dist/chunk-VMSZJPR5.mjs.map +0 -1
|
@@ -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",
|
|
@@ -228,6 +117,11 @@ function getNetworkDisplayName(network) {
|
|
|
228
117
|
}
|
|
229
118
|
|
|
230
119
|
// src/utils/cluster.ts
|
|
120
|
+
function getMaybeStringProp(value, prop) {
|
|
121
|
+
if (typeof value != "object" || value === null) return;
|
|
122
|
+
let v = value[prop];
|
|
123
|
+
return typeof v == "string" ? v : void 0;
|
|
124
|
+
}
|
|
231
125
|
function getClusterRpcUrl(cluster) {
|
|
232
126
|
if (typeof cluster == "string") {
|
|
233
127
|
let presets2 = {
|
|
@@ -238,7 +132,7 @@ function getClusterRpcUrl(cluster) {
|
|
|
238
132
|
return presets2[cluster];
|
|
239
133
|
throw new Error(`Unknown cluster: ${cluster}`);
|
|
240
134
|
}
|
|
241
|
-
let url = cluster.url
|
|
135
|
+
let url = cluster.url ?? getMaybeStringProp(cluster, "rpcUrl");
|
|
242
136
|
if (!url)
|
|
243
137
|
throw new Error("Cluster URL is required");
|
|
244
138
|
if (url.startsWith("http://") || url.startsWith("https://"))
|
|
@@ -283,16 +177,17 @@ function isTestnetCluster(cluster) {
|
|
|
283
177
|
return cluster.id === "solana:testnet";
|
|
284
178
|
}
|
|
285
179
|
function isLocalCluster(cluster) {
|
|
286
|
-
let url = cluster.url
|
|
180
|
+
let url = cluster.url ?? getMaybeStringProp(cluster, "rpcUrl");
|
|
287
181
|
return url ? cluster.id === "solana:localnet" || url.includes("localhost") || url.includes("127.0.0.1") : cluster.id === "solana:localnet";
|
|
288
182
|
}
|
|
289
183
|
function getClusterName(cluster) {
|
|
290
184
|
if (cluster.label) return cluster.label;
|
|
291
|
-
|
|
185
|
+
let name = getMaybeStringProp(cluster, "name");
|
|
186
|
+
if (name) return name;
|
|
292
187
|
let parts = cluster.id.split(":");
|
|
293
188
|
if (parts.length >= 2 && parts[1]) {
|
|
294
|
-
let
|
|
295
|
-
return
|
|
189
|
+
let name2 = parts.slice(1).join(":");
|
|
190
|
+
return name2.charAt(0).toUpperCase() + name2.slice(1).replace(/-/g, " ");
|
|
296
191
|
}
|
|
297
192
|
return "Unknown";
|
|
298
193
|
}
|
|
@@ -515,7 +410,7 @@ var BaseCollaborator = class {
|
|
|
515
410
|
}
|
|
516
411
|
};
|
|
517
412
|
|
|
518
|
-
// src/lib/
|
|
413
|
+
// src/lib/wallet/authenticity-verifier.ts
|
|
519
414
|
var logger2 = createLogger("WalletAuthenticity"), WalletAuthenticityVerifier = class {
|
|
520
415
|
/**
|
|
521
416
|
* Verify a wallet's authenticity using dynamic heuristics
|
|
@@ -725,7 +620,7 @@ var logger2 = createLogger("WalletAuthenticity"), WalletAuthenticityVerifier = c
|
|
|
725
620
|
}
|
|
726
621
|
};
|
|
727
622
|
|
|
728
|
-
// src/lib/
|
|
623
|
+
// src/lib/wallet/detector.ts
|
|
729
624
|
var logger3 = createLogger("WalletDetector");
|
|
730
625
|
function hasFeature(wallet, featureName) {
|
|
731
626
|
return wallet.features != null && wallet.features[featureName] !== void 0;
|
|
@@ -751,7 +646,14 @@ var WalletDetector = class extends BaseCollaborator {
|
|
|
751
646
|
__publicField(this, "unsubscribers", []);
|
|
752
647
|
}
|
|
753
648
|
/**
|
|
754
|
-
* 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.
|
|
755
657
|
*/
|
|
756
658
|
initialize() {
|
|
757
659
|
if (!(typeof window > "u"))
|
|
@@ -774,6 +676,24 @@ var WalletDetector = class extends BaseCollaborator {
|
|
|
774
676
|
} catch {
|
|
775
677
|
}
|
|
776
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
|
+
}
|
|
777
697
|
/**
|
|
778
698
|
* Check if a specific wallet is available immediately via direct window object detection
|
|
779
699
|
*/
|
|
@@ -860,7 +780,7 @@ var WalletDetector = class extends BaseCollaborator {
|
|
|
860
780
|
}
|
|
861
781
|
};
|
|
862
782
|
|
|
863
|
-
// src/lib/
|
|
783
|
+
// src/lib/wallet/connection-manager.ts
|
|
864
784
|
function getConnectFeature(wallet) {
|
|
865
785
|
return wallet.features["standard:connect"]?.connect ?? null;
|
|
866
786
|
}
|
|
@@ -1070,7 +990,7 @@ var ConnectionManager = class extends BaseCollaborator {
|
|
|
1070
990
|
}
|
|
1071
991
|
};
|
|
1072
992
|
|
|
1073
|
-
// src/lib/
|
|
993
|
+
// src/lib/wallet/auto-connector.ts
|
|
1074
994
|
var logger4 = createLogger("AutoConnector"), MIN_ADDRESS_LENGTH = 30, AutoConnector = class {
|
|
1075
995
|
constructor(walletDetector, connectionManager, stateManager, walletStorage, debug = false) {
|
|
1076
996
|
__publicField(this, "walletDetector");
|
|
@@ -1184,7 +1104,7 @@ var logger4 = createLogger("AutoConnector"), MIN_ADDRESS_LENGTH = 30, AutoConnec
|
|
|
1184
1104
|
]
|
|
1185
1105
|
},
|
|
1186
1106
|
true
|
|
1187
|
-
);
|
|
1107
|
+
), await ready;
|
|
1188
1108
|
let walletsApi = getWalletsRegistry(), registryWallet = walletsApi.get().find((w) => w.name === storedWalletName), walletToUse = registryWallet || wallet;
|
|
1189
1109
|
return this.debug && logger4.info("Attempting to connect via instant auto-connect", {
|
|
1190
1110
|
walletName: storedWalletName,
|
|
@@ -1284,7 +1204,7 @@ var TransactionTracker = class extends BaseCollaborator {
|
|
|
1284
1204
|
* Track a transaction for debugging and monitoring
|
|
1285
1205
|
*/
|
|
1286
1206
|
trackTransaction(activity) {
|
|
1287
|
-
let clusterId = this.getState().cluster?.id
|
|
1207
|
+
let clusterId = this.getState().cluster?.id ?? "solana:devnet", fullActivity = {
|
|
1288
1208
|
...activity,
|
|
1289
1209
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1290
1210
|
cluster: clusterId
|
|
@@ -1300,10 +1220,10 @@ var TransactionTracker = class extends BaseCollaborator {
|
|
|
1300
1220
|
* Update transaction status (e.g., from pending to confirmed/failed)
|
|
1301
1221
|
*/
|
|
1302
1222
|
updateStatus(signature, status, error) {
|
|
1303
|
-
let tx = this.transactions.find((t) => t.signature === signature);
|
|
1223
|
+
let tx = this.transactions.find((t) => String(t.signature) === signature);
|
|
1304
1224
|
tx && (tx.status = status, error && (tx.error = error), this.eventEmitter.emit({
|
|
1305
1225
|
type: "transaction:updated",
|
|
1306
|
-
signature,
|
|
1226
|
+
signature: tx.signature,
|
|
1307
1227
|
status,
|
|
1308
1228
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1309
1229
|
}), this.log("[Connector] Transaction updated:", { signature, status, error }));
|
|
@@ -1440,16 +1360,15 @@ var logger5 = createLogger("ConnectorClient"), ConnectorClient = class {
|
|
|
1440
1360
|
), this.initialize();
|
|
1441
1361
|
}
|
|
1442
1362
|
initialize() {
|
|
1443
|
-
if (
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
}
|
|
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 });
|
|
1453
1372
|
}
|
|
1454
1373
|
async select(walletName) {
|
|
1455
1374
|
let wallet = this.stateManager.getSnapshot().wallets.find((w) => w.wallet.name === walletName)?.wallet;
|
|
@@ -1474,11 +1393,8 @@ var logger5 = createLogger("ConnectorClient"), ConnectorClient = class {
|
|
|
1474
1393
|
getRpcUrl() {
|
|
1475
1394
|
let cluster = this.clusterManager.getCluster();
|
|
1476
1395
|
if (!cluster) return null;
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
} catch (error) {
|
|
1480
|
-
return this.config.debug && logger5.error("Failed to get RPC URL", { error }), null;
|
|
1481
|
-
}
|
|
1396
|
+
let { data, error } = tryCatchSync(() => getClusterRpcUrl(cluster));
|
|
1397
|
+
return error ? (this.config.debug && logger5.error("Failed to get RPC URL", { error }), null) : data;
|
|
1482
1398
|
}
|
|
1483
1399
|
subscribe(listener) {
|
|
1484
1400
|
return this.stateManager.subscribe(listener);
|
|
@@ -1491,12 +1407,10 @@ var logger5 = createLogger("ConnectorClient"), ConnectorClient = class {
|
|
|
1491
1407
|
let storageKeys = ["account", "wallet", "cluster"];
|
|
1492
1408
|
for (let key of storageKeys) {
|
|
1493
1409
|
let storage = this.config.storage?.[key];
|
|
1494
|
-
if (storage && "reset" in storage && typeof storage.reset == "function")
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
this.config.debug && logger5.error("Failed to reset storage", { key, error });
|
|
1499
|
-
}
|
|
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
|
+
}
|
|
1500
1414
|
}
|
|
1501
1415
|
this.eventEmitter.emit({
|
|
1502
1416
|
type: "storage:reset",
|
|
@@ -1886,6 +1800,71 @@ function formatTokenAmount(amount, decimals, options = {}) {
|
|
|
1886
1800
|
maximumFractionDigits: maxDecimals
|
|
1887
1801
|
});
|
|
1888
1802
|
}
|
|
1803
|
+
var MAX_SAFE_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
|
|
1804
|
+
function isSafeInteger(value) {
|
|
1805
|
+
return value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
|
|
1806
|
+
}
|
|
1807
|
+
function splitBigIntDecimals(amount, decimals) {
|
|
1808
|
+
if (decimals <= 0)
|
|
1809
|
+
return { whole: amount.toString(), fraction: "" };
|
|
1810
|
+
let str = amount.toString(), isNegative = str.startsWith("-"), absStr = isNegative ? str.slice(1) : str;
|
|
1811
|
+
if (absStr.length <= decimals) {
|
|
1812
|
+
let padded = absStr.padStart(decimals, "0");
|
|
1813
|
+
return {
|
|
1814
|
+
whole: isNegative ? "-0" : "0",
|
|
1815
|
+
fraction: padded
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
let splitPoint = absStr.length - decimals;
|
|
1819
|
+
return {
|
|
1820
|
+
whole: (isNegative ? "-" : "") + absStr.slice(0, splitPoint),
|
|
1821
|
+
fraction: absStr.slice(splitPoint)
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
function formatBigIntBalance(amount, decimals, options = {}) {
|
|
1825
|
+
let { maxDecimals = Math.min(decimals, 6), minDecimals = 0, locale, useGrouping = true } = options;
|
|
1826
|
+
if (isSafeInteger(amount))
|
|
1827
|
+
return (Number(amount) / Math.pow(10, decimals)).toLocaleString(locale, {
|
|
1828
|
+
minimumFractionDigits: minDecimals,
|
|
1829
|
+
maximumFractionDigits: maxDecimals,
|
|
1830
|
+
useGrouping
|
|
1831
|
+
});
|
|
1832
|
+
let { whole, fraction } = splitBigIntDecimals(amount, decimals), truncatedFraction = fraction.slice(0, maxDecimals);
|
|
1833
|
+
for (; truncatedFraction.length > minDecimals && truncatedFraction.endsWith("0"); )
|
|
1834
|
+
truncatedFraction = truncatedFraction.slice(0, -1);
|
|
1835
|
+
truncatedFraction = truncatedFraction.padEnd(minDecimals, "0");
|
|
1836
|
+
let formattedWhole = whole;
|
|
1837
|
+
if (useGrouping) {
|
|
1838
|
+
let isNegative = whole.startsWith("-"), absWhole = isNegative ? whole.slice(1) : whole, parts = [];
|
|
1839
|
+
for (let i = absWhole.length; i > 0; i -= 3)
|
|
1840
|
+
parts.unshift(absWhole.slice(Math.max(0, i - 3), i));
|
|
1841
|
+
formattedWhole = (isNegative ? "-" : "") + parts.join(",");
|
|
1842
|
+
}
|
|
1843
|
+
return truncatedFraction.length === 0 ? formattedWhole : `${formattedWhole}.${truncatedFraction}`;
|
|
1844
|
+
}
|
|
1845
|
+
function formatLamportsToSolSafe(lamports, options = {}) {
|
|
1846
|
+
let { maxDecimals = 4, minDecimals = 0, suffix = false, locale } = options, formatted = formatBigIntBalance(lamports, 9, {
|
|
1847
|
+
maxDecimals,
|
|
1848
|
+
minDecimals,
|
|
1849
|
+
locale
|
|
1850
|
+
});
|
|
1851
|
+
return suffix ? `${formatted} SOL` : formatted;
|
|
1852
|
+
}
|
|
1853
|
+
function formatBigIntUsd(amount, decimals, usdPrice, options = {}) {
|
|
1854
|
+
let { locale, currency = "USD" } = options, { whole, fraction } = splitBigIntDecimals(amount, decimals), wholeNum = parseFloat(whole), fractionNum = fraction ? parseFloat("0." + fraction) : 0;
|
|
1855
|
+
return ((wholeNum + fractionNum) * usdPrice).toLocaleString(locale, {
|
|
1856
|
+
style: "currency",
|
|
1857
|
+
currency,
|
|
1858
|
+
minimumFractionDigits: 2,
|
|
1859
|
+
maximumFractionDigits: 2
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
function formatTokenBalanceSafe(amount, decimals, options = {}) {
|
|
1863
|
+
return formatBigIntBalance(amount, decimals, {
|
|
1864
|
+
maxDecimals: options.maxDecimals ?? Math.min(decimals, 6),
|
|
1865
|
+
locale: options.locale
|
|
1866
|
+
});
|
|
1867
|
+
}
|
|
1889
1868
|
var ClipboardErrorType = /* @__PURE__ */ ((ClipboardErrorType2) => (ClipboardErrorType2.NOT_SUPPORTED = "not_supported", ClipboardErrorType2.PERMISSION_DENIED = "permission_denied", ClipboardErrorType2.SSR = "ssr", ClipboardErrorType2.EMPTY_VALUE = "empty_value", ClipboardErrorType2.INVALID_VALUE = "invalid_value", ClipboardErrorType2.UNKNOWN = "unknown", ClipboardErrorType2))(ClipboardErrorType || {});
|
|
1890
1869
|
function isClipboardAvailable() {
|
|
1891
1870
|
if (typeof window > "u" || typeof document > "u")
|
|
@@ -2447,6 +2426,6 @@ function createKitTransactionSigner(connectorSigner) {
|
|
|
2447
2426
|
}
|
|
2448
2427
|
var createGillTransactionSigner = createKitTransactionSigner;
|
|
2449
2428
|
|
|
2450
|
-
export { ClipboardErrorType,
|
|
2451
|
-
//# sourceMappingURL=chunk-
|
|
2452
|
-
//# 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
|