@gala-chain/gswap-sdk 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -195,7 +195,11 @@ declare class PendingTransaction {
195
195
  readonly message: string;
196
196
  readonly error: boolean;
197
197
  private readonly waitDelegate;
198
- constructor(transactionId: string, message: string, error: boolean, waitDelegate: () => Promise<void>);
198
+ constructor(transactionId: string, message: string, error: boolean, waitDelegate: () => Promise<{
199
+ txId: string;
200
+ transactionHash: string;
201
+ Data: Record<string, unknown>;
202
+ }>);
199
203
  /**
200
204
  * Waits for the transaction to be confirmed.
201
205
  * This should be called immediately after receiving the PendingTransaction
@@ -204,7 +208,11 @@ declare class PendingTransaction {
204
208
  *
205
209
  * @returns A promise that resolves when the transaction is confirmed.
206
210
  */
207
- wait(): Promise<void>;
211
+ wait(): Promise<{
212
+ txId: string;
213
+ transactionHash: string;
214
+ Data: Record<string, unknown>;
215
+ }>;
208
216
  }
209
217
 
210
218
  /**
@@ -251,11 +259,24 @@ declare class Bundler {
251
259
  hasSigner(): boolean;
252
260
  }
253
261
 
254
- interface BundlerResponse {
255
- status: 'PROCESSED' | 'FAILED' | 'PENDING';
256
- data?: string;
257
- error?: string;
258
- }
262
+ type BundlerResponse = {
263
+ status: 'FAILED';
264
+ transactionHash: string;
265
+ data: {
266
+ ErrorCode: number;
267
+ ErrorKey: string;
268
+ ErrorPayload: Record<string, unknown>;
269
+ Message: string;
270
+ transactionId: string;
271
+ };
272
+ } | {
273
+ status: 'PROCESSED';
274
+ transactionHash: string;
275
+ data: {
276
+ Data: Record<string, unknown>;
277
+ transactionId: string;
278
+ };
279
+ };
259
280
  interface BundlerRequest {
260
281
  data: string;
261
282
  message: string;
@@ -318,7 +339,11 @@ declare class Events {
318
339
  * @param txId - The transaction ID to wait for.
319
340
  * @returns Promise that resolves when the transaction completes.
320
341
  */
321
- wait(txId: string): Promise<void>;
342
+ wait(txId: string): Promise<{
343
+ txId: string;
344
+ transactionHash: string;
345
+ Data: Record<string, unknown>;
346
+ }>;
322
347
  /**
323
348
  * Internal handler for socket messages.
324
349
  * @param response - The bundler response.
package/dist/index.d.ts CHANGED
@@ -195,7 +195,11 @@ declare class PendingTransaction {
195
195
  readonly message: string;
196
196
  readonly error: boolean;
197
197
  private readonly waitDelegate;
198
- constructor(transactionId: string, message: string, error: boolean, waitDelegate: () => Promise<void>);
198
+ constructor(transactionId: string, message: string, error: boolean, waitDelegate: () => Promise<{
199
+ txId: string;
200
+ transactionHash: string;
201
+ Data: Record<string, unknown>;
202
+ }>);
199
203
  /**
200
204
  * Waits for the transaction to be confirmed.
201
205
  * This should be called immediately after receiving the PendingTransaction
@@ -204,7 +208,11 @@ declare class PendingTransaction {
204
208
  *
205
209
  * @returns A promise that resolves when the transaction is confirmed.
206
210
  */
207
- wait(): Promise<void>;
211
+ wait(): Promise<{
212
+ txId: string;
213
+ transactionHash: string;
214
+ Data: Record<string, unknown>;
215
+ }>;
208
216
  }
209
217
 
210
218
  /**
@@ -251,11 +259,24 @@ declare class Bundler {
251
259
  hasSigner(): boolean;
252
260
  }
253
261
 
254
- interface BundlerResponse {
255
- status: 'PROCESSED' | 'FAILED' | 'PENDING';
256
- data?: string;
257
- error?: string;
258
- }
262
+ type BundlerResponse = {
263
+ status: 'FAILED';
264
+ transactionHash: string;
265
+ data: {
266
+ ErrorCode: number;
267
+ ErrorKey: string;
268
+ ErrorPayload: Record<string, unknown>;
269
+ Message: string;
270
+ transactionId: string;
271
+ };
272
+ } | {
273
+ status: 'PROCESSED';
274
+ transactionHash: string;
275
+ data: {
276
+ Data: Record<string, unknown>;
277
+ transactionId: string;
278
+ };
279
+ };
259
280
  interface BundlerRequest {
260
281
  data: string;
261
282
  message: string;
@@ -318,7 +339,11 @@ declare class Events {
318
339
  * @param txId - The transaction ID to wait for.
319
340
  * @returns Promise that resolves when the transaction completes.
320
341
  */
321
- wait(txId: string): Promise<void>;
342
+ wait(txId: string): Promise<{
343
+ txId: string;
344
+ transactionHash: string;
345
+ Data: Record<string, unknown>;
346
+ }>;
322
347
  /**
323
348
  * Internal handler for socket messages.
324
349
  * @param response - The bundler response.
package/dist/index.mjs CHANGED
@@ -57,9 +57,12 @@ var GSwapSDKError = class _GSwapSDKError extends Error {
57
57
  });
58
58
  }
59
59
  static transactionWaitFailedError(txId, detail) {
60
+ const transactionHash = "transactionId" in detail && typeof detail.transactionId === "string" ? detail.transactionId : void 0;
61
+ const { transactionId, ...rest } = detail;
60
62
  return new _GSwapSDKError("Transaction wait failed.", "TRANSACTION_WAIT_FAILED", {
61
63
  txId,
62
- ...detail
64
+ transactionHash,
65
+ ...rest
63
66
  });
64
67
  }
65
68
  static socketConnectionRequiredError() {
@@ -321,9 +324,13 @@ var EventSocketClient = class extends TradeEventEmitter {
321
324
  this.emit("disconnect", reason);
322
325
  });
323
326
  this.socket.onAny((eventName, ...args) => {
327
+ var _a2;
324
328
  if (typeof eventName === "string") {
325
329
  const [responseData] = args;
326
- this.emit("transaction", eventName, responseData);
330
+ this.emit("transaction", eventName, {
331
+ ...responseData,
332
+ transactionHash: (_a2 = responseData.data) == null ? void 0 : _a2.transactionId
333
+ });
327
334
  }
328
335
  });
329
336
  });
@@ -381,7 +388,7 @@ var TransactionWaiter = class {
381
388
  if (promiseInfo.waited) {
382
389
  promiseInfo.reject(GSwapSDKError.transactionWaitTimeoutError(txId));
383
390
  } else {
384
- promiseInfo.resolve();
391
+ promiseInfo.resolve({ txId, transactionHash: txId, Data: {} });
385
392
  }
386
393
  this.promiseInfoForTxId.delete(txId);
387
394
  }
@@ -408,13 +415,17 @@ var TransactionWaiter = class {
408
415
  promise.waited = true;
409
416
  return promise.promise;
410
417
  }
411
- notifySuccess(txId) {
418
+ notifySuccess(txId, data) {
412
419
  const promiseInfo = this.promiseInfoForTxId.get(txId);
413
420
  if (!promiseInfo) {
414
421
  return;
415
422
  }
416
423
  clearTimeout(promiseInfo.timeoutId);
417
- promiseInfo.resolve();
424
+ promiseInfo.resolve({
425
+ txId,
426
+ transactionHash: data.transactionId,
427
+ Data: data.Data
428
+ });
418
429
  this.promiseInfoForTxId.delete(txId);
419
430
  }
420
431
  notifyFailure(txId, detail) {
@@ -426,7 +437,7 @@ var TransactionWaiter = class {
426
437
  if (promiseInfo.waited) {
427
438
  promiseInfo.reject(GSwapSDKError.transactionWaitFailedError(txId, detail));
428
439
  } else {
429
- promiseInfo.resolve();
440
+ promiseInfo.resolve({ txId, transactionHash: txId, Data: {} });
430
441
  }
431
442
  this.promiseInfoForTxId.delete(txId);
432
443
  }
@@ -459,7 +470,7 @@ var Events = class _Events {
459
470
  if ((_a = this.globalSocketClient) == null ? void 0 : _a.isConnected()) {
460
471
  return this.globalSocketClient;
461
472
  }
462
- const url = bundlerBaseUrl ?? "https://bundle-backend-test1.defi.gala.com";
473
+ const url = bundlerBaseUrl ?? "https://bundle-backend-prod1.defi.gala.com";
463
474
  this.connectionPromise = (async () => {
464
475
  const client = new _Events.tradeEventEmitterConstructor(url);
465
476
  await client.connect();
@@ -510,7 +521,7 @@ var Events = class _Events {
510
521
  if (!this.eventSocketConnected()) {
511
522
  throw GSwapSDKError.socketConnectionRequiredError();
512
523
  }
513
- await this.globalWaitHelper.wait(txId);
524
+ return this.globalWaitHelper.wait(txId);
514
525
  }
515
526
  /**
516
527
  * Internal handler for socket messages.
@@ -519,14 +530,9 @@ var Events = class _Events {
519
530
  */
520
531
  internalHandleSocketMessage(txId, response) {
521
532
  if (response.status === "PROCESSED") {
522
- this.globalWaitHelper.notifySuccess(txId);
533
+ this.globalWaitHelper.notifySuccess(txId, response.data);
523
534
  } else if (response.status === "FAILED") {
524
- this.globalWaitHelper.notifyFailure(txId, {
525
- error: response.error,
526
- status: response.status,
527
- data: response.data
528
- });
529
- } else if (response.status === "PENDING") {
535
+ this.globalWaitHelper.notifyFailure(txId, response.data);
530
536
  } else {
531
537
  debugLog(`Unknown response status for transaction ${txId}:`, response.status);
532
538
  }