@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/browser/index.js +6 -6
- package/dist/browser/index.js.map +1 -1
- package/dist/index.cjs +21 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -8
- package/dist/index.d.ts +33 -8
- package/dist/index.mjs +21 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -118,9 +118,12 @@ var GSwapSDKError = class _GSwapSDKError extends Error {
|
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
120
|
static transactionWaitFailedError(txId, detail) {
|
|
121
|
+
const transactionHash = "transactionId" in detail && typeof detail.transactionId === "string" ? detail.transactionId : void 0;
|
|
122
|
+
const { transactionId, ...rest } = detail;
|
|
121
123
|
return new _GSwapSDKError("Transaction wait failed.", "TRANSACTION_WAIT_FAILED", {
|
|
122
124
|
txId,
|
|
123
|
-
|
|
125
|
+
transactionHash,
|
|
126
|
+
...rest
|
|
124
127
|
});
|
|
125
128
|
}
|
|
126
129
|
static socketConnectionRequiredError() {
|
|
@@ -382,9 +385,13 @@ var EventSocketClient = class extends TradeEventEmitter {
|
|
|
382
385
|
this.emit("disconnect", reason);
|
|
383
386
|
});
|
|
384
387
|
this.socket.onAny((eventName, ...args) => {
|
|
388
|
+
var _a2;
|
|
385
389
|
if (typeof eventName === "string") {
|
|
386
390
|
const [responseData] = args;
|
|
387
|
-
this.emit("transaction", eventName,
|
|
391
|
+
this.emit("transaction", eventName, {
|
|
392
|
+
...responseData,
|
|
393
|
+
transactionHash: (_a2 = responseData.data) == null ? void 0 : _a2.transactionId
|
|
394
|
+
});
|
|
388
395
|
}
|
|
389
396
|
});
|
|
390
397
|
});
|
|
@@ -442,7 +449,7 @@ var TransactionWaiter = class {
|
|
|
442
449
|
if (promiseInfo.waited) {
|
|
443
450
|
promiseInfo.reject(GSwapSDKError.transactionWaitTimeoutError(txId));
|
|
444
451
|
} else {
|
|
445
|
-
promiseInfo.resolve();
|
|
452
|
+
promiseInfo.resolve({ txId, transactionHash: txId, Data: {} });
|
|
446
453
|
}
|
|
447
454
|
this.promiseInfoForTxId.delete(txId);
|
|
448
455
|
}
|
|
@@ -469,13 +476,17 @@ var TransactionWaiter = class {
|
|
|
469
476
|
promise.waited = true;
|
|
470
477
|
return promise.promise;
|
|
471
478
|
}
|
|
472
|
-
notifySuccess(txId) {
|
|
479
|
+
notifySuccess(txId, data) {
|
|
473
480
|
const promiseInfo = this.promiseInfoForTxId.get(txId);
|
|
474
481
|
if (!promiseInfo) {
|
|
475
482
|
return;
|
|
476
483
|
}
|
|
477
484
|
clearTimeout(promiseInfo.timeoutId);
|
|
478
|
-
promiseInfo.resolve(
|
|
485
|
+
promiseInfo.resolve({
|
|
486
|
+
txId,
|
|
487
|
+
transactionHash: data.transactionId,
|
|
488
|
+
Data: data.Data
|
|
489
|
+
});
|
|
479
490
|
this.promiseInfoForTxId.delete(txId);
|
|
480
491
|
}
|
|
481
492
|
notifyFailure(txId, detail) {
|
|
@@ -487,7 +498,7 @@ var TransactionWaiter = class {
|
|
|
487
498
|
if (promiseInfo.waited) {
|
|
488
499
|
promiseInfo.reject(GSwapSDKError.transactionWaitFailedError(txId, detail));
|
|
489
500
|
} else {
|
|
490
|
-
promiseInfo.resolve();
|
|
501
|
+
promiseInfo.resolve({ txId, transactionHash: txId, Data: {} });
|
|
491
502
|
}
|
|
492
503
|
this.promiseInfoForTxId.delete(txId);
|
|
493
504
|
}
|
|
@@ -520,7 +531,7 @@ var Events = class _Events {
|
|
|
520
531
|
if ((_a = this.globalSocketClient) == null ? void 0 : _a.isConnected()) {
|
|
521
532
|
return this.globalSocketClient;
|
|
522
533
|
}
|
|
523
|
-
const url = bundlerBaseUrl ?? "https://bundle-backend-
|
|
534
|
+
const url = bundlerBaseUrl ?? "https://bundle-backend-prod1.defi.gala.com";
|
|
524
535
|
this.connectionPromise = (async () => {
|
|
525
536
|
const client = new _Events.tradeEventEmitterConstructor(url);
|
|
526
537
|
await client.connect();
|
|
@@ -571,7 +582,7 @@ var Events = class _Events {
|
|
|
571
582
|
if (!this.eventSocketConnected()) {
|
|
572
583
|
throw GSwapSDKError.socketConnectionRequiredError();
|
|
573
584
|
}
|
|
574
|
-
|
|
585
|
+
return this.globalWaitHelper.wait(txId);
|
|
575
586
|
}
|
|
576
587
|
/**
|
|
577
588
|
* Internal handler for socket messages.
|
|
@@ -580,14 +591,9 @@ var Events = class _Events {
|
|
|
580
591
|
*/
|
|
581
592
|
internalHandleSocketMessage(txId, response) {
|
|
582
593
|
if (response.status === "PROCESSED") {
|
|
583
|
-
this.globalWaitHelper.notifySuccess(txId);
|
|
594
|
+
this.globalWaitHelper.notifySuccess(txId, response.data);
|
|
584
595
|
} else if (response.status === "FAILED") {
|
|
585
|
-
this.globalWaitHelper.notifyFailure(txId,
|
|
586
|
-
error: response.error,
|
|
587
|
-
status: response.status,
|
|
588
|
-
data: response.data
|
|
589
|
-
});
|
|
590
|
-
} else if (response.status === "PENDING") {
|
|
596
|
+
this.globalWaitHelper.notifyFailure(txId, response.data);
|
|
591
597
|
} else {
|
|
592
598
|
debugLog(`Unknown response status for transaction ${txId}:`, response.status);
|
|
593
599
|
}
|