@liberfi.io/react-predict 0.3.47 → 0.3.49
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.mts +21 -10
- package/dist/index.d.ts +21 -10
- package/dist/index.js +78 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -14
- package/dist/index.mjs.map +1 -1
- package/dist/{server-Byq4PK9C.d.mts → server-D5LNY5tz.d.mts} +28 -8
- package/dist/{server-Byq4PK9C.d.ts → server-D5LNY5tz.d.ts} +28 -8
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +44 -10
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +44 -10
- package/dist/server.mjs.map +1 -1
- package/package.json +3 -3
package/dist/server.mjs
CHANGED
|
@@ -596,8 +596,9 @@ var PredictClient = class {
|
|
|
596
596
|
// Redeem (resolved market token redemption)
|
|
597
597
|
// -------------------------------------------------------------------------
|
|
598
598
|
/**
|
|
599
|
-
* Prepare
|
|
600
|
-
* The frontend must sign
|
|
599
|
+
* Prepare the signing payload for a Polymarket redeem transaction.
|
|
600
|
+
* The frontend must sign the returned Safe hash or deposit-wallet typed data
|
|
601
|
+
* and pass the signature to `redeemPolymarket`.
|
|
601
602
|
*
|
|
602
603
|
* Maps to `POST /api/v1/redeem/polymarket/prepare`.
|
|
603
604
|
*/
|
|
@@ -607,7 +608,7 @@ var PredictClient = class {
|
|
|
607
608
|
}
|
|
608
609
|
/**
|
|
609
610
|
* Redeem tokens from a resolved Polymarket market via gasless Relayer.
|
|
610
|
-
* Requires a valid
|
|
611
|
+
* Requires a valid signature for the payload returned by the prepare step.
|
|
611
612
|
*
|
|
612
613
|
* Maps to `POST /api/v1/redeem/polymarket`.
|
|
613
614
|
*/
|
|
@@ -625,6 +626,13 @@ var DEFAULT_RECONNECT_BASE = 1e3;
|
|
|
625
626
|
var DEFAULT_RECONNECT_MAX = 3e4;
|
|
626
627
|
var DEFAULT_PING_INTERVAL = 2e4;
|
|
627
628
|
var DEFAULT_PONG_TIMEOUT = 1e4;
|
|
629
|
+
var MAX_SUBSCRIPTION_FRAME_BYTES = 3500;
|
|
630
|
+
function byteLength(str) {
|
|
631
|
+
if (typeof TextEncoder !== "undefined") {
|
|
632
|
+
return new TextEncoder().encode(str).length;
|
|
633
|
+
}
|
|
634
|
+
return str.length;
|
|
635
|
+
}
|
|
628
636
|
var PredictWsClient = class {
|
|
629
637
|
ws = null;
|
|
630
638
|
wsUrl;
|
|
@@ -742,7 +750,7 @@ var PredictWsClient = class {
|
|
|
742
750
|
const set = this.subs.channels.get(ch);
|
|
743
751
|
for (const slug of marketSlugs) set.add(slug);
|
|
744
752
|
}
|
|
745
|
-
this.
|
|
753
|
+
this.sendChunkedSubscription("subscribe", channels, marketSlugs);
|
|
746
754
|
}
|
|
747
755
|
/**
|
|
748
756
|
* Unsubscribe from one or more channels for the given market slugs.
|
|
@@ -752,7 +760,7 @@ var PredictWsClient = class {
|
|
|
752
760
|
const set = this.subs.channels.get(ch);
|
|
753
761
|
for (const slug of marketSlugs) set.delete(slug);
|
|
754
762
|
}
|
|
755
|
-
this.
|
|
763
|
+
this.sendChunkedSubscription("unsubscribe", channels, marketSlugs);
|
|
756
764
|
}
|
|
757
765
|
// -------------------------------------------------------------------------
|
|
758
766
|
// Subscription — convenience (single channel)
|
|
@@ -908,14 +916,40 @@ var PredictWsClient = class {
|
|
|
908
916
|
restoreSubscriptions() {
|
|
909
917
|
for (const [channel, slugs] of this.subs.channels.entries()) {
|
|
910
918
|
if (slugs.size > 0) {
|
|
911
|
-
this.
|
|
912
|
-
type: "subscribe",
|
|
913
|
-
channels: [channel],
|
|
914
|
-
market_slugs: Array.from(slugs)
|
|
915
|
-
});
|
|
919
|
+
this.sendChunkedSubscription("subscribe", [channel], Array.from(slugs));
|
|
916
920
|
}
|
|
917
921
|
}
|
|
918
922
|
}
|
|
923
|
+
/**
|
|
924
|
+
* Send a subscribe/unsubscribe message, splitting `marketSlugs` across
|
|
925
|
+
* multiple frames so no single frame exceeds the server read limit.
|
|
926
|
+
*/
|
|
927
|
+
sendChunkedSubscription(type, channels, marketSlugs) {
|
|
928
|
+
if (marketSlugs.length === 0) {
|
|
929
|
+
this.send({ type, channels, market_slugs: [] });
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
const envelopeBytes = byteLength(
|
|
933
|
+
JSON.stringify({ type, channels, market_slugs: [] })
|
|
934
|
+
);
|
|
935
|
+
const budget = MAX_SUBSCRIPTION_FRAME_BYTES - envelopeBytes;
|
|
936
|
+
let chunk = [];
|
|
937
|
+
let chunkBytes = 0;
|
|
938
|
+
const flush = () => {
|
|
939
|
+
if (chunk.length > 0) {
|
|
940
|
+
this.send({ type, channels, market_slugs: chunk });
|
|
941
|
+
chunk = [];
|
|
942
|
+
chunkBytes = 0;
|
|
943
|
+
}
|
|
944
|
+
};
|
|
945
|
+
for (const slug of marketSlugs) {
|
|
946
|
+
const slugBytes = byteLength(JSON.stringify(slug)) + 1;
|
|
947
|
+
if (chunk.length > 0 && chunkBytes + slugBytes > budget) flush();
|
|
948
|
+
chunk.push(slug);
|
|
949
|
+
chunkBytes += slugBytes;
|
|
950
|
+
}
|
|
951
|
+
flush();
|
|
952
|
+
}
|
|
919
953
|
startPing() {
|
|
920
954
|
this.stopPing();
|
|
921
955
|
this.pingTimer = setInterval(() => {
|