@silentswap/react 0.0.78 → 0.0.80

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.
@@ -0,0 +1,327 @@
1
+ /**
2
+ * Order tracking WebSocket and cache logic.
3
+ * Lives in context via createOrderTrackingManager(); state updates go through setStateForKey.
4
+ */
5
+ import { OutputStage, DEFAULT_ORDER_TRACKING_STATE, getStatusTextFromStage, getProgressFromStage, hasFinalizedOutput, isFullOrderStatus, getOrderTrackingCacheKey, buildOrderTrackingWsUrl, } from './orderTrackingTypes.js';
6
+ const wsCache = new Map();
7
+ const pendingCleanups = new Map();
8
+ const statusCache = new Map();
9
+ function buildFullState(key, status, isConnected, isLoading, error) {
10
+ const outputsList = status.outputs ?? [];
11
+ const numOutputs = outputsList.length || 1;
12
+ const newOutputs = [];
13
+ const newProgresses = [];
14
+ const newStatusTexts = [];
15
+ for (let index = 0; index < outputsList.length; index++) {
16
+ const output = outputsList[index];
17
+ const outputAsset = output.output ??
18
+ (output.asset
19
+ ? { caip19: output.asset, amount: output.value || '0', decimals: 0 }
20
+ : undefined);
21
+ newOutputs.push({
22
+ index,
23
+ stage: output.stage,
24
+ timestamp: output.timestamp,
25
+ recipient: output.recipient,
26
+ asset: outputAsset,
27
+ txs: output.txs,
28
+ });
29
+ newProgresses.push(getProgressFromStage(output.stage));
30
+ newStatusTexts.push(getStatusTextFromStage(output.stage));
31
+ }
32
+ const allFinalized = newOutputs.length > 0 && newOutputs.every((o) => o.stage === OutputStage.FINALIZED);
33
+ const completedTimestamp = outputsList.length > 0
34
+ ? outputsList.reduce((min, o) => (min == null || o.timestamp < min ? o.timestamp : min), null)
35
+ : null;
36
+ return {
37
+ isConnected,
38
+ isLoading,
39
+ error,
40
+ orderStatus: status,
41
+ deposit: status.deposit
42
+ ? {
43
+ amount: status.deposit.amount,
44
+ timestamp: status.deposit.timestamp,
45
+ duration: status.deposit.duration,
46
+ orderId: status.deposit.orderId,
47
+ tx: status.deposit.tx,
48
+ }
49
+ : null,
50
+ outputs: newOutputs.length ? newOutputs : [],
51
+ progresses: newProgresses.length ? newProgresses : new Array(numOutputs).fill(undefined),
52
+ statusTexts: newStatusTexts.length ? newStatusTexts : new Array(numOutputs).fill('Connecting'),
53
+ completedTimestamp: allFinalized ? completedTimestamp : null,
54
+ isComplete: allFinalized,
55
+ };
56
+ }
57
+ function applyFullStatus(getApi, key, status, cacheConn, isConnected, isLoading, error) {
58
+ const api = getApi();
59
+ const current = api.getStateForKey(key)?.orderStatus;
60
+ const currentFinalized = current && hasFinalizedOutput(current);
61
+ const incomingFinalized = hasFinalizedOutput(status);
62
+ if (currentFinalized && !incomingFinalized)
63
+ return;
64
+ if (cacheConn) {
65
+ cacheConn.initialStatus = status;
66
+ statusCache.set(getOrderTrackingCacheKey(cacheConn.orderId, cacheConn.auth), status);
67
+ }
68
+ const state = buildFullState(key, status, isConnected, isLoading, error);
69
+ api.setStateForKey(key, state);
70
+ api.getOptionsForKey(key)?.onStatusUpdate?.(status);
71
+ }
72
+ function submitRequest(conn, method, params, handler) {
73
+ if (conn.ws.readyState !== WebSocket.OPEN)
74
+ return -1;
75
+ const requestId = conn.requestCounter++;
76
+ const request = { jsonrpc: '2.0', id: requestId, method, params };
77
+ if (handler)
78
+ conn.responseHandlers.set(requestId, handler);
79
+ conn.ws.send(JSON.stringify(request));
80
+ return requestId;
81
+ }
82
+ export function createOrderTrackingManager(apiRef) {
83
+ const getApi = () => apiRef.current;
84
+ const reconnectTimeoutRef = { current: null };
85
+ function handleStatusUpdate(key, update, conn, getCurrentState) {
86
+ conn.statusUpdates.push(update);
87
+ const prev = getCurrentState() ?? DEFAULT_ORDER_TRACKING_STATE;
88
+ let next = { ...prev };
89
+ switch (update.type) {
90
+ case 'deposit':
91
+ next = {
92
+ ...next,
93
+ deposit: {
94
+ amount: update.data.amount,
95
+ timestamp: update.data.timestamp,
96
+ duration: update.data.duration,
97
+ orderId: update.data.orderId,
98
+ tx: update.data.tx,
99
+ },
100
+ };
101
+ break;
102
+ case 'stage': {
103
+ const idx = update.data.index;
104
+ const progress = getProgressFromStage(update.data.stage);
105
+ const statusText = getStatusTextFromStage(update.data.stage);
106
+ const newOutputs = [...(next.outputs || [])];
107
+ newOutputs[idx] = {
108
+ ...newOutputs[idx],
109
+ index: idx,
110
+ stage: update.data.stage,
111
+ timestamp: update.data.timestamp,
112
+ ...(update.data.asset ? { asset: update.data.asset } : {}),
113
+ };
114
+ const newProgresses = [...(next.progresses || [])];
115
+ newProgresses[idx] = progress;
116
+ const newStatusTexts = [...(next.statusTexts || [])];
117
+ newStatusTexts[idx] = statusText;
118
+ next = {
119
+ ...next,
120
+ outputs: newOutputs,
121
+ progresses: newProgresses,
122
+ statusTexts: newStatusTexts,
123
+ };
124
+ const allOne = newProgresses.every((p) => (p ?? 0) >= 1);
125
+ if (allOne) {
126
+ next = {
127
+ ...next,
128
+ isComplete: true,
129
+ completedTimestamp: next.completedTimestamp ?? update.data.timestamp,
130
+ };
131
+ getApi().getOptionsForKey(key)?.onComplete?.();
132
+ }
133
+ break;
134
+ }
135
+ case 'transaction': {
136
+ const newOutputs = [...(next.outputs || [])];
137
+ if (newOutputs[update.data.index]) {
138
+ const existingTxs = newOutputs[update.data.index].txs || {};
139
+ newOutputs[update.data.index] = {
140
+ ...newOutputs[update.data.index],
141
+ txs: {
142
+ ...existingTxs,
143
+ [update.data.kind]: {
144
+ txId: update.data.txId,
145
+ chain: update.data.chain,
146
+ },
147
+ },
148
+ };
149
+ }
150
+ next = { ...next, outputs: newOutputs };
151
+ break;
152
+ }
153
+ case 'error': {
154
+ const err = new Error(update.data.message || 'Order tracking error');
155
+ next = { ...next, error: err };
156
+ getApi().getOptionsForKey(key)?.onError?.(err);
157
+ break;
158
+ }
159
+ }
160
+ getApi().setStateForKey(key, next);
161
+ }
162
+ function connect(orderId, auth, key, options) {
163
+ const client = options.client;
164
+ const pendingCleanup = pendingCleanups.get(key);
165
+ if (pendingCleanup) {
166
+ clearTimeout(pendingCleanup);
167
+ pendingCleanups.delete(key);
168
+ }
169
+ if (reconnectTimeoutRef.current) {
170
+ clearTimeout(reconnectTimeoutRef.current);
171
+ reconnectTimeoutRef.current = null;
172
+ }
173
+ const cached = wsCache.get(key);
174
+ if (cached &&
175
+ (cached.ws.readyState === WebSocket.OPEN || cached.ws.readyState === WebSocket.CONNECTING)) {
176
+ if (cached.initialStatus) {
177
+ const status = cached.initialStatus;
178
+ applyFullStatus(getApi, key, status, cached, true, false, null);
179
+ }
180
+ return;
181
+ }
182
+ wsCache.delete(key);
183
+ const cachedStatus = statusCache.get(key);
184
+ if (cachedStatus) {
185
+ applyFullStatus(getApi, key, cachedStatus, null, false, false, null);
186
+ }
187
+ else {
188
+ getApi().setStateForKey(key, {
189
+ ...DEFAULT_ORDER_TRACKING_STATE,
190
+ isLoading: true,
191
+ });
192
+ }
193
+ const wsUrl = buildOrderTrackingWsUrl(client);
194
+ let ws;
195
+ try {
196
+ ws = new WebSocket(wsUrl);
197
+ }
198
+ catch (err) {
199
+ const e = err instanceof Error ? err : new Error('Failed to connect to order tracking');
200
+ getApi().setStateForKey(key, {
201
+ ...DEFAULT_ORDER_TRACKING_STATE,
202
+ error: e,
203
+ isLoading: false,
204
+ });
205
+ options.onError?.(e);
206
+ return;
207
+ }
208
+ const conn = {
209
+ ws,
210
+ orderId,
211
+ auth,
212
+ requestCounter: 0,
213
+ responseHandlers: new Map(),
214
+ lastReceived: 0,
215
+ reconnectTimeout: null,
216
+ initialStatus: null,
217
+ statusUpdates: [],
218
+ };
219
+ wsCache.set(key, conn);
220
+ ws.onopen = () => {
221
+ conn.lastReceived = Date.now();
222
+ const connectRequestId = submitRequest(conn, 'connect', { auth: { orderId, viewingAuth: auth } }, (rpcError, result) => {
223
+ if (rpcError) {
224
+ const err = new Error(rpcError.message || 'Connection error');
225
+ if (!getApi().isKeyActive(key))
226
+ return;
227
+ getApi().setStateForKey(key, {
228
+ ...DEFAULT_ORDER_TRACKING_STATE,
229
+ error: err,
230
+ isLoading: false,
231
+ });
232
+ getApi().getOptionsForKey(key)?.onError?.(err);
233
+ return;
234
+ }
235
+ if (!getApi().isKeyActive(key))
236
+ return;
237
+ const status = result;
238
+ conn.statusUpdates = [];
239
+ applyFullStatus(getApi, key, status, conn, true, false, null);
240
+ if (connectRequestId >= 0) {
241
+ conn.responseHandlers.set(connectRequestId, (statusError, statusResult) => {
242
+ if (statusError) {
243
+ const err = new Error(statusError.message || 'Status error');
244
+ if (!getApi().isKeyActive(key))
245
+ return;
246
+ const prev = getApi().getStateForKey(key) ?? DEFAULT_ORDER_TRACKING_STATE;
247
+ getApi().setStateForKey(key, { ...prev, error: err });
248
+ getApi().getOptionsForKey(key)?.onError?.(err);
249
+ return;
250
+ }
251
+ if (!getApi().isKeyActive(key))
252
+ return;
253
+ if (isFullOrderStatus(statusResult)) {
254
+ applyFullStatus(getApi, key, statusResult, conn, true, false, null);
255
+ return;
256
+ }
257
+ handleStatusUpdate(key, statusResult, conn, () => getApi().getStateForKey(key));
258
+ });
259
+ }
260
+ getApi().getOptionsForKey(key)?.onStatusUpdate?.(status);
261
+ });
262
+ };
263
+ ws.onmessage = (event) => {
264
+ conn.lastReceived = Date.now();
265
+ try {
266
+ const response = JSON.parse(event.data);
267
+ if (response.jsonrpc !== '2.0' || typeof response.id !== 'number')
268
+ return;
269
+ const handler = conn.responseHandlers.get(response.id);
270
+ if (handler)
271
+ handler(response.error, response.result);
272
+ }
273
+ catch {
274
+ // ignore
275
+ }
276
+ };
277
+ ws.onerror = () => {
278
+ if (!getApi().isKeyActive(key))
279
+ return;
280
+ const prev = getApi().getStateForKey(key) ?? DEFAULT_ORDER_TRACKING_STATE;
281
+ getApi().setStateForKey(key, {
282
+ ...prev,
283
+ error: new Error('WebSocket connection error'),
284
+ isLoading: false,
285
+ });
286
+ };
287
+ ws.onclose = () => {
288
+ if (wsCache.get(key)?.ws === ws)
289
+ wsCache.delete(key);
290
+ conn.responseHandlers.clear();
291
+ conn.initialStatus = null;
292
+ conn.statusUpdates = [];
293
+ if (getApi().isKeyActive(key)) {
294
+ const prev = getApi().getStateForKey(key) ?? DEFAULT_ORDER_TRACKING_STATE;
295
+ getApi().setStateForKey(key, { ...prev, isConnected: false });
296
+ const idle = Date.now() - conn.lastReceived > 90_000;
297
+ if (idle) {
298
+ reconnectTimeoutRef.current = setTimeout(() => {
299
+ if (getApi().isKeyActive(key))
300
+ connect(orderId, auth, key, getApi().getOptionsForKey(key) ?? {});
301
+ }, 5000);
302
+ }
303
+ else {
304
+ connect(orderId, auth, key, getApi().getOptionsForKey(key) ?? {});
305
+ }
306
+ }
307
+ };
308
+ }
309
+ function disconnect(orderId, auth) {
310
+ if (reconnectTimeoutRef.current) {
311
+ clearTimeout(reconnectTimeoutRef.current);
312
+ reconnectTimeoutRef.current = null;
313
+ }
314
+ const key = getOrderTrackingCacheKey(orderId, auth);
315
+ const ws = wsCache.get(key)?.ws;
316
+ if (ws) {
317
+ pendingCleanups.set(key, setTimeout(() => {
318
+ pendingCleanups.delete(key);
319
+ if (wsCache.get(key)?.ws === ws) {
320
+ wsCache.delete(key);
321
+ ws.close();
322
+ }
323
+ }, 500));
324
+ }
325
+ }
326
+ return { connect, disconnect };
327
+ }
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Shared types and helpers for order tracking (WebSocket + context).
3
+ * Used by orderTrackingConnection.ts and useOrderTracking.ts.
4
+ */
5
+ import type { SilentSwapClient } from '@silentswap/sdk';
6
+ export declare enum OutputStage {
7
+ NONE = "NONE",
8
+ INIT = "INIT",
9
+ FUNDED = "FUNDED",
10
+ REDEEMED = "REDEEMED",
11
+ IBC_SENT = "IBC_SENT",
12
+ IBC_RCVD = "IBC_RCVD",
13
+ BRIDGE_SENT = "BRIDGE_SENT",
14
+ BRIDGE_CFRM = "BRIDGE_CFRM",
15
+ BRIDGE_RCVD = "BRIDGE_RCVD",
16
+ SWAP_USDC_GAS = "SWAP_USDC_GAS",
17
+ SWAP_USDC_TRG = "SWAP_USDC_TRG",
18
+ LTRL_TRG_SENT = "LTRL_TRG_SENT",
19
+ LTRL_TRG_RCVD = "LTRL_TRG_RCVD",
20
+ SWAP_TRG_DST = "SWAP_TRG_DST",
21
+ XFER_TRG_DST = "XFER_TRG_DST",
22
+ REFUND_NATIVE = "REFUND_NATIVE",
23
+ FINALIZED = "FINALIZED"
24
+ }
25
+ export type OrderDeposit = {
26
+ amount: string;
27
+ timestamp: number;
28
+ duration: number;
29
+ orderId?: string;
30
+ tx?: string;
31
+ };
32
+ export type OrderTransactions = {
33
+ RECEIPT?: {
34
+ chain: string;
35
+ txId: string;
36
+ };
37
+ REFUND?: {
38
+ chain: string;
39
+ txId: string;
40
+ };
41
+ };
42
+ export type OutputStatus = {
43
+ index: number;
44
+ stage: OutputStage;
45
+ timestamp: number;
46
+ recipient?: string;
47
+ asset?: {
48
+ caip19: string;
49
+ amount: string;
50
+ decimals: number;
51
+ priceUsd?: number;
52
+ };
53
+ txs?: OrderTransactions;
54
+ };
55
+ export type IOutput = {
56
+ caip19: string;
57
+ amount: string;
58
+ decimals: number;
59
+ priceUsd?: number;
60
+ };
61
+ export type Outputs = Array<{
62
+ stage: OutputStage;
63
+ timestamp: number;
64
+ asset: string;
65
+ value: string;
66
+ recipient: string;
67
+ txs?: OrderTransactions;
68
+ output?: IOutput;
69
+ }>;
70
+ export type OrderStatus = {
71
+ priority?: string;
72
+ signer: string;
73
+ deposit?: OrderDeposit;
74
+ outputs: Outputs;
75
+ metadata?: {
76
+ sourceAsset?: {
77
+ caip19: string;
78
+ amount: string;
79
+ };
80
+ sourceSender?: {
81
+ contactId: string;
82
+ };
83
+ };
84
+ };
85
+ export type StatusUpdate = {
86
+ type: 'deposit';
87
+ data: OrderDeposit;
88
+ } | {
89
+ type: 'stage';
90
+ data: {
91
+ orderId: string;
92
+ index: number;
93
+ stage: OutputStage;
94
+ timestamp: number;
95
+ asset?: {
96
+ caip19: string;
97
+ amount: string;
98
+ decimals: number;
99
+ priceUsd?: number;
100
+ };
101
+ };
102
+ } | {
103
+ type: 'transaction';
104
+ data: {
105
+ orderId: string;
106
+ index: number;
107
+ chain: string;
108
+ txId: string;
109
+ kind: keyof OrderTransactions;
110
+ };
111
+ } | {
112
+ type: 'error';
113
+ data: {
114
+ orderId: string;
115
+ message: string;
116
+ index?: number;
117
+ };
118
+ };
119
+ export type JsonRpcError = {
120
+ code: number;
121
+ message: string;
122
+ data?: unknown;
123
+ };
124
+ export type OrderTrackingState = {
125
+ isConnected: boolean;
126
+ isLoading: boolean;
127
+ error: Error | null;
128
+ orderStatus: OrderStatus | null;
129
+ deposit: OrderDeposit | null;
130
+ outputs: OutputStatus[];
131
+ progresses: (number | undefined)[];
132
+ statusTexts: string[];
133
+ completedTimestamp: number | null;
134
+ isComplete: boolean;
135
+ };
136
+ export type OrderTrackingOptions = {
137
+ client?: SilentSwapClient;
138
+ onStatusUpdate?: (status: OrderStatus) => void;
139
+ onError?: (error: Error) => void;
140
+ onComplete?: () => void;
141
+ fetchAssetPrice?: (caip19: string) => Promise<number>;
142
+ };
143
+ export declare const DEFAULT_ORDER_TRACKING_STATE: OrderTrackingState;
144
+ export declare function getStatusTextFromStage(stage: OutputStage): string;
145
+ export declare function getProgressFromStage(stage: OutputStage): number;
146
+ export declare function getOrderTrackingCacheKey(orderId: string, auth: string): string;
147
+ export declare function hasFinalizedOutput(status: OrderStatus): boolean;
148
+ export declare function isFullOrderStatus(result: unknown): result is OrderStatus;
149
+ export declare function buildOrderTrackingWsUrl(client?: SilentSwapClient): string;
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Shared types and helpers for order tracking (WebSocket + context).
3
+ * Used by orderTrackingConnection.ts and useOrderTracking.ts.
4
+ */
5
+ export var OutputStage;
6
+ (function (OutputStage) {
7
+ OutputStage["NONE"] = "NONE";
8
+ OutputStage["INIT"] = "INIT";
9
+ OutputStage["FUNDED"] = "FUNDED";
10
+ OutputStage["REDEEMED"] = "REDEEMED";
11
+ OutputStage["IBC_SENT"] = "IBC_SENT";
12
+ OutputStage["IBC_RCVD"] = "IBC_RCVD";
13
+ OutputStage["BRIDGE_SENT"] = "BRIDGE_SENT";
14
+ OutputStage["BRIDGE_CFRM"] = "BRIDGE_CFRM";
15
+ OutputStage["BRIDGE_RCVD"] = "BRIDGE_RCVD";
16
+ OutputStage["SWAP_USDC_GAS"] = "SWAP_USDC_GAS";
17
+ OutputStage["SWAP_USDC_TRG"] = "SWAP_USDC_TRG";
18
+ OutputStage["LTRL_TRG_SENT"] = "LTRL_TRG_SENT";
19
+ OutputStage["LTRL_TRG_RCVD"] = "LTRL_TRG_RCVD";
20
+ OutputStage["SWAP_TRG_DST"] = "SWAP_TRG_DST";
21
+ OutputStage["XFER_TRG_DST"] = "XFER_TRG_DST";
22
+ OutputStage["REFUND_NATIVE"] = "REFUND_NATIVE";
23
+ OutputStage["FINALIZED"] = "FINALIZED";
24
+ })(OutputStage || (OutputStage = {}));
25
+ export const DEFAULT_ORDER_TRACKING_STATE = {
26
+ isConnected: false,
27
+ isLoading: false,
28
+ error: null,
29
+ orderStatus: null,
30
+ deposit: null,
31
+ outputs: [],
32
+ progresses: [undefined],
33
+ statusTexts: ['Connecting'],
34
+ completedTimestamp: null,
35
+ isComplete: false,
36
+ };
37
+ export function getStatusTextFromStage(stage) {
38
+ switch (stage) {
39
+ case OutputStage.NONE:
40
+ return 'Uncertain state';
41
+ case OutputStage.INIT:
42
+ return 'Verifying deposit';
43
+ case OutputStage.FUNDED:
44
+ return 'Initializing';
45
+ case OutputStage.REDEEMED:
46
+ return 'Anonymizing';
47
+ case OutputStage.IBC_SENT:
48
+ return 'Moving';
49
+ case OutputStage.IBC_RCVD:
50
+ return 'Staging';
51
+ case OutputStage.BRIDGE_SENT:
52
+ case OutputStage.BRIDGE_CFRM:
53
+ case OutputStage.BRIDGE_RCVD:
54
+ return 'Bridging';
55
+ case OutputStage.SWAP_USDC_GAS:
56
+ return 'Fueling';
57
+ case OutputStage.SWAP_USDC_TRG:
58
+ return 'Swapping';
59
+ case OutputStage.LTRL_TRG_SENT:
60
+ case OutputStage.LTRL_TRG_RCVD:
61
+ case OutputStage.SWAP_TRG_DST:
62
+ return 'Finalizing';
63
+ case OutputStage.XFER_TRG_DST:
64
+ case OutputStage.REFUND_NATIVE:
65
+ case OutputStage.FINALIZED:
66
+ return 'Completed';
67
+ default:
68
+ return 'Processing';
69
+ }
70
+ }
71
+ export function getProgressFromStage(stage) {
72
+ switch (stage) {
73
+ case OutputStage.NONE:
74
+ case OutputStage.INIT:
75
+ return 0;
76
+ case OutputStage.FUNDED:
77
+ return 0.1;
78
+ case OutputStage.REDEEMED:
79
+ return 0.15;
80
+ case OutputStage.IBC_SENT:
81
+ return 0.25;
82
+ case OutputStage.IBC_RCVD:
83
+ return 0.35;
84
+ case OutputStage.BRIDGE_SENT:
85
+ return 0.5;
86
+ case OutputStage.BRIDGE_CFRM:
87
+ return 0.6;
88
+ case OutputStage.BRIDGE_RCVD:
89
+ return 0.7;
90
+ case OutputStage.SWAP_USDC_GAS:
91
+ return 0.8;
92
+ case OutputStage.SWAP_USDC_TRG:
93
+ return 0.9;
94
+ case OutputStage.LTRL_TRG_SENT:
95
+ case OutputStage.LTRL_TRG_RCVD:
96
+ case OutputStage.SWAP_TRG_DST:
97
+ return 0.95;
98
+ case OutputStage.XFER_TRG_DST:
99
+ case OutputStage.REFUND_NATIVE:
100
+ case OutputStage.FINALIZED:
101
+ return 1;
102
+ default:
103
+ return 0;
104
+ }
105
+ }
106
+ export function getOrderTrackingCacheKey(orderId, auth) {
107
+ return `${orderId}|${auth}`;
108
+ }
109
+ export function hasFinalizedOutput(status) {
110
+ return status.outputs?.some((o) => o.stage === OutputStage.FINALIZED) ?? false;
111
+ }
112
+ const STATUS_UPDATE_TYPES = ['deposit', 'stage', 'transaction', 'error'];
113
+ export function isFullOrderStatus(result) {
114
+ if (typeof result !== 'object' || result === null)
115
+ return false;
116
+ const r = result;
117
+ const hasOutputs = Array.isArray(r.outputs) && r.outputs.length > 0;
118
+ const hasType = typeof r.type === 'string' && STATUS_UPDATE_TYPES.includes(r.type);
119
+ return hasOutputs && !hasType;
120
+ }
121
+ export function buildOrderTrackingWsUrl(client) {
122
+ let wsUrl;
123
+ if (typeof window !== 'undefined' && window.__WEBSOCKET_URL__) {
124
+ wsUrl = window.__WEBSOCKET_URL__;
125
+ }
126
+ else if (client) {
127
+ const baseUrl = client.baseUrl;
128
+ try {
129
+ const url = new URL(baseUrl);
130
+ wsUrl = `${url.protocol === 'https:' ? 'wss:' : 'ws:'}//${url.host}/websocket`;
131
+ }
132
+ catch {
133
+ wsUrl = baseUrl.replace(/^https?:\/\//, 'wss://').replace(/^http:\/\//, 'ws://') + '/websocket';
134
+ }
135
+ }
136
+ else if (typeof window !== 'undefined') {
137
+ wsUrl = `${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${window.location.host}/websocket`;
138
+ }
139
+ else {
140
+ wsUrl = 'ws://localhost/websocket';
141
+ }
142
+ try {
143
+ const url = new URL(wsUrl);
144
+ const protocol = url.protocol === 'https:' || url.protocol === 'wss:' ? 'wss:' : 'ws:';
145
+ wsUrl = `${protocol}//${url.host}/websocket`;
146
+ }
147
+ catch {
148
+ wsUrl = wsUrl.split('?')[0].split('#')[0].replace(/\/+$/, '') + '/websocket';
149
+ }
150
+ return wsUrl;
151
+ }
@@ -39,5 +39,5 @@ export interface BridgeExecutionResult {
39
39
  export declare function useBridgeExecution(walletClient: WalletClient | undefined, connector: Connector | undefined, solanaConnector: SolanaWalletConnector | undefined, solanaConnection: SolanaConnection | undefined, solanaRpcUrl: string | undefined, setCurrentStep: (step: string) => void, depositorAddress: Hex, onStatus?: (status: string) => void, bitcoinConnector?: BitcoinWalletConnector, bitcoinConnection?: BitcoinConnection): {
40
40
  executeSolanaBridge: (sourceAsset: string, sourceAmount: string, usdcAmount: string | undefined, solanaSenderAddress: string, evmSignerAddress: `0x${string}`, depositParams?: DepositParams<`${bigint}`>) => Promise<BridgeExecutionResult>;
41
41
  executeBitcoinBridge: (sourceAsset: string, sourceAmount: string, usdcAmount: string | undefined, bitcoinSenderAddress: string, evmSignerAddress: `0x${string}`, depositParams?: DepositParams<`${bigint}`>) => Promise<BridgeExecutionResult>;
42
- executeEvmBridge: (sourceChainId: number, sourceTokenAddress: string, sourceAmount: string, usdcAmount: string | undefined, depositParams: DepositParams<`${bigint}`>, evmSignerAddress: `0x${string}`, evmSenderAddress?: `0x${string}`, provider?: "relay" | "debridge") => Promise<BridgeExecutionResult>;
42
+ executeEvmBridge: (sourceChainId: number, sourceTokenAddress: string, sourceAmount: string, usdcAmount: string | undefined, depositParams: DepositParams<`${bigint}`>, evmSignerAddress: `0x${string}`, evmSenderAddress?: `0x${string}`, provider?: "relay" | "debridge", allowanceTarget?: string) => Promise<BridgeExecutionResult>;
43
43
  };