@formo/analytics 1.28.4 → 1.28.6
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 +1 -2
- package/dist/cjs/src/FormoAnalytics.d.ts +7 -3
- package/dist/cjs/src/FormoAnalytics.js +24 -12
- package/dist/cjs/src/index.d.ts +3 -1
- package/dist/cjs/src/index.js +5 -1
- package/dist/cjs/src/solana/SolanaManager.d.ts +36 -11
- package/dist/cjs/src/solana/SolanaManager.js +47 -49
- package/dist/cjs/src/solana/SolanaStoreHandler.d.ts +88 -0
- package/dist/cjs/src/solana/SolanaStoreHandler.js +471 -0
- package/dist/cjs/src/solana/index.d.ts +8 -4
- package/dist/cjs/src/solana/index.js +10 -6
- package/dist/cjs/src/solana/storeTypes.d.ts +107 -0
- package/dist/cjs/src/solana/storeTypes.js +12 -0
- package/dist/cjs/src/solana/types.d.ts +23 -154
- package/dist/cjs/src/solana/types.js +4 -37
- package/dist/cjs/src/storage/StorageManager.d.ts +1 -0
- package/dist/cjs/src/storage/StorageManager.js +10 -2
- package/dist/cjs/src/types/base.d.ts +16 -5
- package/dist/cjs/src/version.d.ts +1 -1
- package/dist/cjs/src/version.js +1 -1
- package/dist/esm/src/FormoAnalytics.d.ts +7 -3
- package/dist/esm/src/FormoAnalytics.js +24 -12
- package/dist/esm/src/index.d.ts +3 -1
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/solana/SolanaManager.d.ts +36 -11
- package/dist/esm/src/solana/SolanaManager.js +47 -49
- package/dist/esm/src/solana/SolanaStoreHandler.d.ts +88 -0
- package/dist/esm/src/solana/SolanaStoreHandler.js +468 -0
- package/dist/esm/src/solana/index.d.ts +8 -4
- package/dist/esm/src/solana/index.js +8 -4
- package/dist/esm/src/solana/storeTypes.d.ts +107 -0
- package/dist/esm/src/solana/storeTypes.js +11 -0
- package/dist/esm/src/solana/types.d.ts +23 -154
- package/dist/esm/src/solana/types.js +3 -34
- package/dist/esm/src/storage/StorageManager.d.ts +1 -0
- package/dist/esm/src/storage/StorageManager.js +10 -2
- package/dist/esm/src/types/base.d.ts +16 -5
- package/dist/esm/src/version.d.ts +1 -1
- package/dist/esm/src/version.js +1 -1
- package/dist/index.umd.min.js +1 -1
- package/package.json +5 -16
- package/dist/cjs/src/solana/SolanaAdapter.d.ts +0 -210
- package/dist/cjs/src/solana/SolanaAdapter.js +0 -988
- package/dist/esm/src/solana/SolanaAdapter.d.ts +0 -210
- package/dist/esm/src/solana/SolanaAdapter.js +0 -985
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SolanaStoreHandler
|
|
3
|
+
*
|
|
4
|
+
* Handles wallet event tracking by subscribing to framework-kit's zustand store.
|
|
5
|
+
* This provides automatic event capture (autocapture) for Solana wallets without
|
|
6
|
+
* wrapping any wallet methods — similar to how WagmiEventHandler subscribes to
|
|
7
|
+
* TanStack Query's mutation/query caches.
|
|
8
|
+
*
|
|
9
|
+
* Subscribes to:
|
|
10
|
+
* - `state.wallet` — connect/disconnect events
|
|
11
|
+
* - `state.transactions` — transaction lifecycle events (sending → confirmed/failed)
|
|
12
|
+
*
|
|
13
|
+
* @see https://github.com/solana-foundation/framework-kit
|
|
14
|
+
*/
|
|
15
|
+
import { FormoAnalytics } from "../FormoAnalytics";
|
|
16
|
+
import { SolanaClientStore } from "./storeTypes";
|
|
17
|
+
import { SolanaCluster } from "./types";
|
|
18
|
+
export declare class SolanaStoreHandler {
|
|
19
|
+
private formo;
|
|
20
|
+
private store;
|
|
21
|
+
private unsubscribers;
|
|
22
|
+
private cluster;
|
|
23
|
+
private chainId;
|
|
24
|
+
/**
|
|
25
|
+
* Track last known wallet status to detect transitions.
|
|
26
|
+
*/
|
|
27
|
+
private lastWalletStatus;
|
|
28
|
+
private lastAddress?;
|
|
29
|
+
private lastChainId?;
|
|
30
|
+
/**
|
|
31
|
+
* Track processed transaction state changes to prevent duplicate events.
|
|
32
|
+
* Key format: `${signature}:${status}`
|
|
33
|
+
*/
|
|
34
|
+
private processedTransactions;
|
|
35
|
+
/**
|
|
36
|
+
* Track transactions we've emitted STARTED for (status was "sending").
|
|
37
|
+
* Ensures we only emit STARTED once per transaction key.
|
|
38
|
+
*/
|
|
39
|
+
private startedTransactions;
|
|
40
|
+
/**
|
|
41
|
+
* Per-transaction sender address captured at STARTED time.
|
|
42
|
+
* Ensures terminal events (confirmed/failed) are attributed correctly
|
|
43
|
+
* even if the wallet disconnects before the transaction settles.
|
|
44
|
+
*/
|
|
45
|
+
private transactionSenders;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the cluster was explicitly set (via options or setCluster).
|
|
48
|
+
* When true, auto-detection from the store endpoint is disabled.
|
|
49
|
+
*/
|
|
50
|
+
private explicitCluster;
|
|
51
|
+
constructor(formoAnalytics: FormoAnalytics, store: SolanaClientStore, options?: {
|
|
52
|
+
cluster?: SolanaCluster;
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Update the cluster/network.
|
|
56
|
+
*/
|
|
57
|
+
setCluster(cluster: SolanaCluster): void;
|
|
58
|
+
/**
|
|
59
|
+
* Get the current chain ID.
|
|
60
|
+
*/
|
|
61
|
+
getChainId(): number;
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the current chainId from the live store state.
|
|
64
|
+
* This ensures correctness when wallet and cluster change in the same tick
|
|
65
|
+
* (the cluster subscription may not have fired yet).
|
|
66
|
+
*/
|
|
67
|
+
private resolveCurrentChainId;
|
|
68
|
+
private setupWalletSubscription;
|
|
69
|
+
private checkInitialWalletState;
|
|
70
|
+
private handleWalletChange;
|
|
71
|
+
private handleConnect;
|
|
72
|
+
private handleDisconnect;
|
|
73
|
+
private setupClusterSubscription;
|
|
74
|
+
private handleClusterChange;
|
|
75
|
+
private setupTransactionSubscription;
|
|
76
|
+
private handleTransactionChanges;
|
|
77
|
+
private handleTransactionStatusChange;
|
|
78
|
+
/**
|
|
79
|
+
* Attempt to detect the Solana cluster from the store's endpoint URL.
|
|
80
|
+
*/
|
|
81
|
+
private detectClusterFromStore;
|
|
82
|
+
/**
|
|
83
|
+
* Detect cluster from an RPC endpoint URL.
|
|
84
|
+
*/
|
|
85
|
+
private detectClusterFromEndpoint;
|
|
86
|
+
cleanup(): void;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=SolanaStoreHandler.d.ts.map
|
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SolanaStoreHandler
|
|
3
|
+
*
|
|
4
|
+
* Handles wallet event tracking by subscribing to framework-kit's zustand store.
|
|
5
|
+
* This provides automatic event capture (autocapture) for Solana wallets without
|
|
6
|
+
* wrapping any wallet methods — similar to how WagmiEventHandler subscribes to
|
|
7
|
+
* TanStack Query's mutation/query caches.
|
|
8
|
+
*
|
|
9
|
+
* Subscribes to:
|
|
10
|
+
* - `state.wallet` — connect/disconnect events
|
|
11
|
+
* - `state.transactions` — transaction lifecycle events (sending → confirmed/failed)
|
|
12
|
+
*
|
|
13
|
+
* @see https://github.com/solana-foundation/framework-kit
|
|
14
|
+
*/
|
|
15
|
+
var __assign = (this && this.__assign) || function () {
|
|
16
|
+
__assign = Object.assign || function(t) {
|
|
17
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
18
|
+
s = arguments[i];
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
return __assign.apply(this, arguments);
|
|
25
|
+
};
|
|
26
|
+
import { TransactionStatus } from "../types/events";
|
|
27
|
+
import { logger } from "../logger";
|
|
28
|
+
import { SOLANA_CHAIN_IDS } from "./types";
|
|
29
|
+
import { isBlockedSolanaAddress } from "./address";
|
|
30
|
+
/**
|
|
31
|
+
* Clean up old entries from a Set to prevent memory leaks.
|
|
32
|
+
*/
|
|
33
|
+
function cleanupOldEntries(set, maxSize, removeCount) {
|
|
34
|
+
if (maxSize === void 0) { maxSize = 1000; }
|
|
35
|
+
if (removeCount === void 0) { removeCount = 500; }
|
|
36
|
+
if (set.size > maxSize) {
|
|
37
|
+
var entries = Array.from(set);
|
|
38
|
+
for (var i = 0; i < removeCount && i < entries.length; i++) {
|
|
39
|
+
set.delete(entries[i]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var SolanaStoreHandler = /** @class */ (function () {
|
|
44
|
+
function SolanaStoreHandler(formoAnalytics, store, options) {
|
|
45
|
+
this.unsubscribers = [];
|
|
46
|
+
/**
|
|
47
|
+
* Track last known wallet status to detect transitions.
|
|
48
|
+
*/
|
|
49
|
+
this.lastWalletStatus = "disconnected";
|
|
50
|
+
/**
|
|
51
|
+
* Track processed transaction state changes to prevent duplicate events.
|
|
52
|
+
* Key format: `${signature}:${status}`
|
|
53
|
+
*/
|
|
54
|
+
this.processedTransactions = new Set();
|
|
55
|
+
/**
|
|
56
|
+
* Track transactions we've emitted STARTED for (status was "sending").
|
|
57
|
+
* Ensures we only emit STARTED once per transaction key.
|
|
58
|
+
*/
|
|
59
|
+
this.startedTransactions = new Set();
|
|
60
|
+
/**
|
|
61
|
+
* Per-transaction sender address captured at STARTED time.
|
|
62
|
+
* Ensures terminal events (confirmed/failed) are attributed correctly
|
|
63
|
+
* even if the wallet disconnects before the transaction settles.
|
|
64
|
+
*/
|
|
65
|
+
this.transactionSenders = new Map();
|
|
66
|
+
this.formo = formoAnalytics;
|
|
67
|
+
this.store = store;
|
|
68
|
+
this.explicitCluster = !!(options === null || options === void 0 ? void 0 : options.cluster);
|
|
69
|
+
this.cluster = (options === null || options === void 0 ? void 0 : options.cluster) || this.detectClusterFromStore(store) || "mainnet-beta";
|
|
70
|
+
this.chainId = SOLANA_CHAIN_IDS[this.cluster];
|
|
71
|
+
logger.info("SolanaStoreHandler: Initializing framework-kit store integration", {
|
|
72
|
+
cluster: this.cluster,
|
|
73
|
+
chainId: this.chainId,
|
|
74
|
+
});
|
|
75
|
+
this.setupWalletSubscription();
|
|
76
|
+
this.setupTransactionSubscription();
|
|
77
|
+
this.setupClusterSubscription();
|
|
78
|
+
// Check initial wallet state
|
|
79
|
+
this.checkInitialWalletState();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Update the cluster/network.
|
|
83
|
+
*/
|
|
84
|
+
SolanaStoreHandler.prototype.setCluster = function (cluster) {
|
|
85
|
+
this.explicitCluster = true;
|
|
86
|
+
var previousCluster = this.cluster;
|
|
87
|
+
this.cluster = cluster;
|
|
88
|
+
this.chainId = SOLANA_CHAIN_IDS[cluster];
|
|
89
|
+
if (previousCluster !== cluster && this.lastAddress) {
|
|
90
|
+
this.lastChainId = this.chainId;
|
|
91
|
+
if (this.formo.isAutocaptureEnabled("chain")) {
|
|
92
|
+
this.formo.chain({
|
|
93
|
+
chainId: this.chainId,
|
|
94
|
+
address: this.lastAddress,
|
|
95
|
+
}).catch(function (error) {
|
|
96
|
+
logger.error("SolanaStoreHandler: Error emitting chain event", error);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Get the current chain ID.
|
|
103
|
+
*/
|
|
104
|
+
SolanaStoreHandler.prototype.getChainId = function () {
|
|
105
|
+
return this.chainId;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Resolve the current chainId from the live store state.
|
|
109
|
+
* This ensures correctness when wallet and cluster change in the same tick
|
|
110
|
+
* (the cluster subscription may not have fired yet).
|
|
111
|
+
*/
|
|
112
|
+
SolanaStoreHandler.prototype.resolveCurrentChainId = function () {
|
|
113
|
+
// Don't auto-detect if the cluster was explicitly set
|
|
114
|
+
if (!this.explicitCluster) {
|
|
115
|
+
var detected = this.detectClusterFromStore(this.store);
|
|
116
|
+
if (detected) {
|
|
117
|
+
this.cluster = detected;
|
|
118
|
+
this.chainId = SOLANA_CHAIN_IDS[detected];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return this.chainId;
|
|
122
|
+
};
|
|
123
|
+
// ============================================================
|
|
124
|
+
// Wallet Subscription
|
|
125
|
+
// ============================================================
|
|
126
|
+
SolanaStoreHandler.prototype.setupWalletSubscription = function () {
|
|
127
|
+
var _this = this;
|
|
128
|
+
var prevWallet = this.store.getState().wallet;
|
|
129
|
+
var unsubscribe = this.store.subscribe(function (state) {
|
|
130
|
+
var wallet = state.wallet;
|
|
131
|
+
if (wallet !== prevWallet) {
|
|
132
|
+
var prev = prevWallet;
|
|
133
|
+
prevWallet = wallet;
|
|
134
|
+
_this.handleWalletChange(wallet, prev);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
this.unsubscribers.push(unsubscribe);
|
|
138
|
+
logger.info("SolanaStoreHandler: Wallet subscription set up");
|
|
139
|
+
};
|
|
140
|
+
SolanaStoreHandler.prototype.checkInitialWalletState = function () {
|
|
141
|
+
var _a;
|
|
142
|
+
var state = this.store.getState();
|
|
143
|
+
var wallet = state.wallet;
|
|
144
|
+
if (wallet.status === "connected") {
|
|
145
|
+
var address = wallet.session.account.address;
|
|
146
|
+
if (address && !isBlockedSolanaAddress(address)) {
|
|
147
|
+
this.lastWalletStatus = "connected";
|
|
148
|
+
this.lastAddress = address;
|
|
149
|
+
this.lastChainId = this.chainId;
|
|
150
|
+
logger.info("SolanaStoreHandler: Already connected on initialization", {
|
|
151
|
+
address: address,
|
|
152
|
+
chainId: this.chainId,
|
|
153
|
+
});
|
|
154
|
+
if (this.formo.isAutocaptureEnabled("connect")) {
|
|
155
|
+
var connectorName = ((_a = wallet.session.connector) === null || _a === void 0 ? void 0 : _a.name) || wallet.connectorId;
|
|
156
|
+
this.formo.connect({ chainId: this.chainId, address: address }, {
|
|
157
|
+
providerName: connectorName,
|
|
158
|
+
rdns: "sol.wallet.".concat(connectorName.toLowerCase().replace(/\s+/g, "")),
|
|
159
|
+
}).catch(function (error) {
|
|
160
|
+
logger.error("SolanaStoreHandler: Error emitting initial connect", error);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
this.lastWalletStatus = wallet.status;
|
|
166
|
+
};
|
|
167
|
+
SolanaStoreHandler.prototype.handleWalletChange = function (wallet, prevWallet) {
|
|
168
|
+
// connected → any other state (disconnected, error, connecting)
|
|
169
|
+
if (prevWallet.status === "connected" &&
|
|
170
|
+
wallet.status !== "connected") {
|
|
171
|
+
this.handleDisconnect();
|
|
172
|
+
}
|
|
173
|
+
// * → connected (new connection)
|
|
174
|
+
if (wallet.status === "connected" && prevWallet.status !== "connected") {
|
|
175
|
+
this.handleConnect(wallet);
|
|
176
|
+
}
|
|
177
|
+
else if (wallet.status === "connected" &&
|
|
178
|
+
prevWallet.status === "connected") {
|
|
179
|
+
// connected → connected: check for account switch OR connector change
|
|
180
|
+
var addressChanged = wallet.session.account.address !== prevWallet.session.account.address;
|
|
181
|
+
var connectorChanged = wallet.connectorId !== prevWallet.connectorId;
|
|
182
|
+
if (addressChanged || connectorChanged) {
|
|
183
|
+
this.handleDisconnect();
|
|
184
|
+
this.handleConnect(wallet);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this.lastWalletStatus = wallet.status;
|
|
188
|
+
};
|
|
189
|
+
SolanaStoreHandler.prototype.handleConnect = function (wallet) {
|
|
190
|
+
var _a;
|
|
191
|
+
var address = wallet.session.account.address;
|
|
192
|
+
if (!address || isBlockedSolanaAddress(address)) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// Resolve chainId from live store state so batched wallet+cluster
|
|
196
|
+
// updates use the correct network even if the cluster subscription
|
|
197
|
+
// hasn't fired yet.
|
|
198
|
+
var chainId = this.resolveCurrentChainId();
|
|
199
|
+
this.lastAddress = address;
|
|
200
|
+
this.lastChainId = chainId;
|
|
201
|
+
logger.info("SolanaStoreHandler: Wallet connected", {
|
|
202
|
+
address: address,
|
|
203
|
+
chainId: chainId,
|
|
204
|
+
connector: wallet.connectorId,
|
|
205
|
+
});
|
|
206
|
+
if (this.formo.isAutocaptureEnabled("connect")) {
|
|
207
|
+
var connectorName = ((_a = wallet.session.connector) === null || _a === void 0 ? void 0 : _a.name) || wallet.connectorId;
|
|
208
|
+
this.formo.connect({ chainId: chainId, address: address }, {
|
|
209
|
+
providerName: connectorName,
|
|
210
|
+
rdns: "sol.wallet.".concat(connectorName.toLowerCase().replace(/\s+/g, "")),
|
|
211
|
+
}).catch(function (error) {
|
|
212
|
+
logger.error("SolanaStoreHandler: Error emitting connect", error);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
SolanaStoreHandler.prototype.handleDisconnect = function () {
|
|
217
|
+
if (!this.lastAddress) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
logger.info("SolanaStoreHandler: Wallet disconnected", {
|
|
221
|
+
address: this.lastAddress,
|
|
222
|
+
chainId: this.lastChainId,
|
|
223
|
+
});
|
|
224
|
+
if (this.formo.isAutocaptureEnabled("disconnect")) {
|
|
225
|
+
this.formo.disconnect({
|
|
226
|
+
chainId: this.lastChainId,
|
|
227
|
+
address: this.lastAddress,
|
|
228
|
+
}).catch(function (error) {
|
|
229
|
+
logger.error("SolanaStoreHandler: Error emitting disconnect", error);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
this.lastAddress = undefined;
|
|
233
|
+
this.lastChainId = undefined;
|
|
234
|
+
};
|
|
235
|
+
// ============================================================
|
|
236
|
+
// Cluster Subscription
|
|
237
|
+
// ============================================================
|
|
238
|
+
SolanaStoreHandler.prototype.setupClusterSubscription = function () {
|
|
239
|
+
var _this = this;
|
|
240
|
+
var prevEndpoint = this.store.getState().cluster.endpoint;
|
|
241
|
+
var unsubscribe = this.store.subscribe(function (state) {
|
|
242
|
+
var endpoint = state.cluster.endpoint;
|
|
243
|
+
if (endpoint !== prevEndpoint) {
|
|
244
|
+
prevEndpoint = endpoint;
|
|
245
|
+
_this.handleClusterChange(endpoint);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
this.unsubscribers.push(unsubscribe);
|
|
249
|
+
logger.info("SolanaStoreHandler: Cluster subscription set up");
|
|
250
|
+
};
|
|
251
|
+
SolanaStoreHandler.prototype.handleClusterChange = function (endpoint) {
|
|
252
|
+
// Don't auto-detect if the cluster was explicitly set
|
|
253
|
+
if (this.explicitCluster) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
var detected = this.detectClusterFromEndpoint(endpoint);
|
|
257
|
+
if (!detected) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
var previousCluster = this.cluster;
|
|
261
|
+
if (detected === previousCluster) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
this.cluster = detected;
|
|
265
|
+
this.chainId = SOLANA_CHAIN_IDS[detected];
|
|
266
|
+
logger.info("SolanaStoreHandler: Cluster changed", {
|
|
267
|
+
from: previousCluster,
|
|
268
|
+
to: detected,
|
|
269
|
+
chainId: this.chainId,
|
|
270
|
+
});
|
|
271
|
+
if (this.lastAddress) {
|
|
272
|
+
this.lastChainId = this.chainId;
|
|
273
|
+
if (this.formo.isAutocaptureEnabled("chain")) {
|
|
274
|
+
this.formo.chain({
|
|
275
|
+
chainId: this.chainId,
|
|
276
|
+
address: this.lastAddress,
|
|
277
|
+
}).catch(function (error) {
|
|
278
|
+
logger.error("SolanaStoreHandler: Error emitting chain event", error);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
// ============================================================
|
|
284
|
+
// Transaction Subscription
|
|
285
|
+
// ============================================================
|
|
286
|
+
SolanaStoreHandler.prototype.setupTransactionSubscription = function () {
|
|
287
|
+
var _this = this;
|
|
288
|
+
var prevTransactions = this.store.getState().transactions;
|
|
289
|
+
var unsubscribe = this.store.subscribe(function (state) {
|
|
290
|
+
var transactions = state.transactions;
|
|
291
|
+
if (transactions !== prevTransactions) {
|
|
292
|
+
var prev = prevTransactions;
|
|
293
|
+
prevTransactions = transactions;
|
|
294
|
+
_this.handleTransactionChanges(transactions, prev);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
this.unsubscribers.push(unsubscribe);
|
|
298
|
+
logger.info("SolanaStoreHandler: Transaction subscription set up");
|
|
299
|
+
};
|
|
300
|
+
SolanaStoreHandler.prototype.handleTransactionChanges = function (transactions, prevTransactions) {
|
|
301
|
+
var _a;
|
|
302
|
+
// Check each transaction for status changes
|
|
303
|
+
for (var _i = 0, _b = Object.entries(transactions); _i < _b.length; _i++) {
|
|
304
|
+
var _c = _b[_i], key = _c[0], tx = _c[1];
|
|
305
|
+
var prevTx = prevTransactions[key];
|
|
306
|
+
// Skip if status hasn't changed
|
|
307
|
+
if (prevTx && prevTx.status === tx.status) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
// For new transactions (sending), use current address.
|
|
311
|
+
// For terminal states, fall back to the address captured at STARTED time.
|
|
312
|
+
var address = this.lastAddress || ((_a = this.transactionSenders.get(key)) === null || _a === void 0 ? void 0 : _a.address);
|
|
313
|
+
if (!address) {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
this.handleTransactionStatusChange(key, tx, prevTx, address);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
SolanaStoreHandler.prototype.handleTransactionStatusChange = function (key, tx, prevTx, address) {
|
|
320
|
+
var chainId = this.chainId;
|
|
321
|
+
var dedupeKey = "".concat(key, ":").concat(tx.status);
|
|
322
|
+
// Deduplicate
|
|
323
|
+
if (this.processedTransactions.has(dedupeKey)) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
this.processedTransactions.add(dedupeKey);
|
|
327
|
+
cleanupOldEntries(this.processedTransactions);
|
|
328
|
+
if (!this.formo.isAutocaptureEnabled("transaction")) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
switch (tx.status) {
|
|
332
|
+
case "sending": {
|
|
333
|
+
// Emit STARTED when transaction enters "sending" state
|
|
334
|
+
if (!this.startedTransactions.has(key)) {
|
|
335
|
+
this.startedTransactions.add(key);
|
|
336
|
+
cleanupOldEntries(this.startedTransactions);
|
|
337
|
+
// Capture sender for this transaction so terminal events are attributed
|
|
338
|
+
// correctly even if the wallet disconnects before the tx settles.
|
|
339
|
+
this.transactionSenders.set(key, { address: address, chainId: chainId });
|
|
340
|
+
this.formo.transaction({
|
|
341
|
+
status: TransactionStatus.STARTED,
|
|
342
|
+
chainId: chainId,
|
|
343
|
+
address: address,
|
|
344
|
+
}).catch(function (error) {
|
|
345
|
+
logger.error("SolanaStoreHandler: Error emitting transaction STARTED", error);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
case "waiting": {
|
|
351
|
+
// "waiting" means the tx was sent and we have a signature — emit BROADCASTED
|
|
352
|
+
var signature = tx.signature;
|
|
353
|
+
if (signature) {
|
|
354
|
+
// Ensure sender is captured (in case we missed "sending")
|
|
355
|
+
if (!this.transactionSenders.has(key)) {
|
|
356
|
+
this.transactionSenders.set(key, { address: address, chainId: chainId });
|
|
357
|
+
}
|
|
358
|
+
var sender = this.transactionSenders.get(key);
|
|
359
|
+
this.formo.transaction({
|
|
360
|
+
status: TransactionStatus.BROADCASTED,
|
|
361
|
+
chainId: sender.chainId,
|
|
362
|
+
address: sender.address,
|
|
363
|
+
transactionHash: signature,
|
|
364
|
+
}).catch(function (error) {
|
|
365
|
+
logger.error("SolanaStoreHandler: Error emitting transaction BROADCASTED", error);
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
case "confirmed": {
|
|
371
|
+
var sender = this.transactionSenders.get(key);
|
|
372
|
+
var txAddress = (sender === null || sender === void 0 ? void 0 : sender.address) || address;
|
|
373
|
+
var txChainId = (sender === null || sender === void 0 ? void 0 : sender.chainId) || chainId;
|
|
374
|
+
var signature = tx.signature;
|
|
375
|
+
logger.info("SolanaStoreHandler: Transaction confirmed", {
|
|
376
|
+
key: key,
|
|
377
|
+
signature: signature,
|
|
378
|
+
});
|
|
379
|
+
this.formo.transaction(__assign({ status: TransactionStatus.CONFIRMED, chainId: txChainId, address: txAddress }, (signature && { transactionHash: signature }))).catch(function (error) {
|
|
380
|
+
logger.error("SolanaStoreHandler: Error emitting transaction CONFIRMED", error);
|
|
381
|
+
});
|
|
382
|
+
this.transactionSenders.delete(key);
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
case "failed": {
|
|
386
|
+
var sender = this.transactionSenders.get(key);
|
|
387
|
+
var txAddress = (sender === null || sender === void 0 ? void 0 : sender.address) || address;
|
|
388
|
+
var txChainId = (sender === null || sender === void 0 ? void 0 : sender.chainId) || chainId;
|
|
389
|
+
var signature = tx.signature;
|
|
390
|
+
var prevStatus = prevTx === null || prevTx === void 0 ? void 0 : prevTx.status;
|
|
391
|
+
// If it failed after being sent and confirmed as failed on-chain, emit REVERTED.
|
|
392
|
+
// Otherwise (rejected by user, build error, RPC rejection), emit REJECTED.
|
|
393
|
+
var status_1 = prevStatus === "waiting"
|
|
394
|
+
? TransactionStatus.REVERTED
|
|
395
|
+
: TransactionStatus.REJECTED;
|
|
396
|
+
logger.info("SolanaStoreHandler: Transaction failed", {
|
|
397
|
+
key: key,
|
|
398
|
+
signature: signature,
|
|
399
|
+
status: status_1,
|
|
400
|
+
prevStatus: prevStatus,
|
|
401
|
+
});
|
|
402
|
+
this.formo.transaction(__assign({ status: status_1, chainId: txChainId, address: txAddress }, (signature && { transactionHash: signature }))).catch(function (error) {
|
|
403
|
+
logger.error("SolanaStoreHandler: Error emitting transaction event", error);
|
|
404
|
+
});
|
|
405
|
+
this.transactionSenders.delete(key);
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
// "idle" — no event needed
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
// ============================================================
|
|
412
|
+
// Cluster Detection
|
|
413
|
+
// ============================================================
|
|
414
|
+
/**
|
|
415
|
+
* Attempt to detect the Solana cluster from the store's endpoint URL.
|
|
416
|
+
*/
|
|
417
|
+
SolanaStoreHandler.prototype.detectClusterFromStore = function (store) {
|
|
418
|
+
try {
|
|
419
|
+
var endpoint = store.getState().cluster.endpoint;
|
|
420
|
+
return this.detectClusterFromEndpoint(endpoint);
|
|
421
|
+
}
|
|
422
|
+
catch (_a) {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* Detect cluster from an RPC endpoint URL.
|
|
428
|
+
*/
|
|
429
|
+
SolanaStoreHandler.prototype.detectClusterFromEndpoint = function (endpoint) {
|
|
430
|
+
if (!endpoint)
|
|
431
|
+
return null;
|
|
432
|
+
var lower = endpoint.toLowerCase();
|
|
433
|
+
if (lower.includes("devnet"))
|
|
434
|
+
return "devnet";
|
|
435
|
+
if (lower.includes("testnet"))
|
|
436
|
+
return "testnet";
|
|
437
|
+
if (lower.includes("localhost") || lower.includes("127.0.0.1"))
|
|
438
|
+
return "localnet";
|
|
439
|
+
if (lower.includes("mainnet"))
|
|
440
|
+
return "mainnet-beta";
|
|
441
|
+
return null;
|
|
442
|
+
};
|
|
443
|
+
// ============================================================
|
|
444
|
+
// Cleanup
|
|
445
|
+
// ============================================================
|
|
446
|
+
SolanaStoreHandler.prototype.cleanup = function () {
|
|
447
|
+
logger.debug("SolanaStoreHandler: Cleaning up");
|
|
448
|
+
for (var _i = 0, _a = this.unsubscribers; _i < _a.length; _i++) {
|
|
449
|
+
var unsubscribe = _a[_i];
|
|
450
|
+
try {
|
|
451
|
+
unsubscribe();
|
|
452
|
+
}
|
|
453
|
+
catch (error) {
|
|
454
|
+
logger.error("SolanaStoreHandler: Error during cleanup", error);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
this.unsubscribers = [];
|
|
458
|
+
this.processedTransactions.clear();
|
|
459
|
+
this.startedTransactions.clear();
|
|
460
|
+
this.transactionSenders.clear();
|
|
461
|
+
this.lastAddress = undefined;
|
|
462
|
+
this.lastChainId = undefined;
|
|
463
|
+
logger.debug("SolanaStoreHandler: Cleanup complete");
|
|
464
|
+
};
|
|
465
|
+
return SolanaStoreHandler;
|
|
466
|
+
}());
|
|
467
|
+
export { SolanaStoreHandler };
|
|
468
|
+
//# sourceMappingURL=SolanaStoreHandler.js.map
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Solana integration module
|
|
3
3
|
*
|
|
4
|
-
* Provides
|
|
5
|
-
*
|
|
4
|
+
* Provides automatic event capture for Solana wallets via framework-kit's
|
|
5
|
+
* zustand store. Connect/disconnect and transaction events are tracked
|
|
6
|
+
* automatically. Signature events (signMessage/signTransaction) require
|
|
7
|
+
* explicit tracking via formo.signature() since framework-kit
|
|
8
|
+
* doesn't track these in store state.
|
|
6
9
|
*
|
|
7
|
-
* @see https://github.com/
|
|
10
|
+
* @see https://github.com/solana-foundation/framework-kit
|
|
8
11
|
*/
|
|
9
|
-
export {
|
|
12
|
+
export { SolanaStoreHandler } from "./SolanaStoreHandler";
|
|
10
13
|
export { SolanaManager } from "./SolanaManager";
|
|
11
14
|
export * from "./types";
|
|
15
|
+
export * from "./storeTypes";
|
|
12
16
|
export * from "./address";
|
|
13
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Solana integration module
|
|
3
3
|
*
|
|
4
|
-
* Provides
|
|
5
|
-
*
|
|
4
|
+
* Provides automatic event capture for Solana wallets via framework-kit's
|
|
5
|
+
* zustand store. Connect/disconnect and transaction events are tracked
|
|
6
|
+
* automatically. Signature events (signMessage/signTransaction) require
|
|
7
|
+
* explicit tracking via formo.signature() since framework-kit
|
|
8
|
+
* doesn't track these in store state.
|
|
6
9
|
*
|
|
7
|
-
* @see https://github.com/
|
|
10
|
+
* @see https://github.com/solana-foundation/framework-kit
|
|
8
11
|
*/
|
|
9
|
-
export {
|
|
12
|
+
export { SolanaStoreHandler } from "./SolanaStoreHandler";
|
|
10
13
|
export { SolanaManager } from "./SolanaManager";
|
|
11
14
|
export * from "./types";
|
|
15
|
+
export * from "./storeTypes";
|
|
12
16
|
export * from "./address";
|
|
13
17
|
//# sourceMappingURL=index.js.map
|